| author | rwestMSFT | |
|---|---|---|
| ms.author | randolphwest | |
| ms.date | 11/18/2024 | |
| ms.service | sql | |
| ms.subservice | linux | |
| ms.topic | include | |
| ms.custom |
|
Ensure that the database you add to the availability group is in the full recovery model and has a valid log backup. If your database is a test database or a newly created database, take a database backup. On the primary [!INCLUDE ssnoversion-md], run the following [!INCLUDE tsql-md] (T-SQL) script to create and back up a database called db1:
CREATE DATABASE [db1];
GO
ALTER DATABASE [db1]
SET RECOVERY FULL;
GO
BACKUP DATABASE [db1]
TO DISK = N'/var/opt/mssql/data/db1.bak';On the primary [!INCLUDE ssnoversion-md] replica, run the following T-SQL script to add a database called db1 to an availability group called ag1:
ALTER AVAILABILITY GROUP [ag1] ADD DATABASE [db1];On each secondary [!INCLUDE ssnoversion-md] replica, run the following query to see if the db1 database was created and is synchronized:
SELECT *
FROM sys.databases
WHERE name = 'db1';
GO
SELECT DB_NAME(database_id) AS 'database',
synchronization_state_desc
FROM sys.dm_hadr_database_replica_states;
GO