Skip to content

Latest commit

 

History

History
47 lines (37 loc) · 1.42 KB

cluster-availability-group-create-post.md

File metadata and controls

47 lines (37 loc) · 1.42 KB
author ms.author ms.date ms.service ms.subservice ms.topic ms.custom
rwestMSFT
randolphwest
11/18/2024
sql
linux
include
linux-related-content

Add a database to the availability group

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];

Verify that the database is created on the secondary servers

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