• sql-server
  • always-on
  • availability-groups
  • high-availability
  • dba

Adding a Replica to a SQL Server Always On Availability Group: My Checklist

The checklist I follow when adding a replica to an Always On availability group: endpoints, logins, seeding, sync checks and the usual mistakes.

Bu yazının Türkçesi →

On paper, adding a replica is a single ALTER AVAILABILITY GROUP statement. In practice, most of the work happens before and after it. This is the cleaned-up version of the checklist I go through every time.

Short answer

To add a new replica to an Always On availability group:

  1. Join the new server to the Windows Server Failover Cluster (WSFC).
  2. Enable Always On in SQL Server Configuration Manager and restart the service.
  3. Create the database mirroring endpoint and grant CONNECT to the service account.
  4. Copy logins, Agent jobs and linked servers to the new server.
  5. Run ADD REPLICA on the primary and JOIN on the new server.
  6. Seed the databases with automatic seeding or backup/restore.
  7. Check synchronization health in the DMVs.

The rest of this post goes through each step and why it matters.

1. Before you start: versions and layout

  • Version: A secondary can’t run an older SQL Server version than the primary. Keeping every replica on the same version and CU is the least painful option.
  • Edition: Basic Availability Groups (Standard Edition) are limited to one database and two replicas. If you need a third replica, you need Enterprise.
  • Disk layout: Matching data and log paths on every replica saves you from MOVE clauses during restores. Automatic seeding also expects the same folder structure.
  • Service account: Using the same domain account on all replicas keeps endpoint permissions simple.

2. Enable Always On and create the endpoint

In Configuration Manager, open the service properties, tick Always On Availability Groups and restart the service. Then create the endpoint:

CREATE ENDPOINT [Hadr_endpoint]
    STATE = STARTED
    AS TCP (LISTENER_PORT = 5022)
    FOR DATABASE_MIRRORING (
        ROLE = ALL,
        ENCRYPTION = REQUIRED ALGORITHM AES
    );

GRANT CONNECT ON ENDPOINT::[Hadr_endpoint] TO [CORP\sqlsvc];

Make sure port 5022 is open between replicas. Most “the replica won’t connect” cases come down to this port or the missing CONNECT permission.

3. What the availability group doesn’t copy

An availability group only synchronizes user databases. None of these follow it to the new server:

  • Logins (if the SIDs don’t match, you get orphaned users after a failover)
  • SQL Agent jobs
  • Linked servers
  • Credentials and proxies
  • Server-level settings (max server memory, MAXDOP, trace flags)

dbatools is the quickest way to copy logins with their SIDs:

Copy-DbaLogin -Source SQL01 -Destination SQL03 -ExcludeSystemLogins
Copy-DbaAgentJob -Source SQL01 -Destination SQL03

4. Add the replica

On the primary:

ALTER AVAILABILITY GROUP [AG1]
ADD REPLICA ON N'SQL03' WITH (
    ENDPOINT_URL = N'TCP://sql03.corp.local:5022',
    AVAILABILITY_MODE = ASYNCHRONOUS_COMMIT,
    FAILOVER_MODE = MANUAL,
    SEEDING_MODE = AUTOMATIC,
    SECONDARY_ROLE (ALLOW_CONNECTIONS = READ_ONLY)
);

On the new server:

ALTER AVAILABILITY GROUP [AG1] JOIN;
ALTER AVAILABILITY GROUP [AG1] GRANT CREATE ANY DATABASE;

Automatic seeding needs the second line. Without it, seeding doesn’t fail with an error. It just sits there and waits.

I always add a new replica as asynchronous, so transactions on the primary don’t wait for a replica that is still catching up. If it needs to be synchronous, I switch it once the databases reach SYNCHRONIZED.

5. Seeding: automatic or backup/restore?

Automatic seeding (SQL Server 2016 and later) is the easy choice for small and medium databases. For large databases, or when the link between replicas is slow, manual seeding with backup/restore is more predictable:

-- On the secondary
RESTORE DATABASE [SalesDB] FROM DISK = N'\\backup\SalesDB_full.bak' WITH NORECOVERY;
RESTORE LOG [SalesDB] FROM DISK = N'\\backup\SalesDB_log.trn' WITH NORECOVERY;

ALTER DATABASE [SalesDB] SET HADR AVAILABILITY GROUP = [AG1];

If you go the manual route, watch the log backup job on the primary. If it takes another log backup before you join the database, you have to restore that one too, or the log chain won’t line up.

To follow automatic seeding progress:

SELECT local_database_name, transferred_size_bytes / 1048576 AS transferred_mb,
       database_size_bytes / 1048576 AS total_mb, estimate_time_complete_utc
FROM sys.dm_hadr_physical_seeding_stats;

6. Is it really in sync?

A green dashboard isn’t enough. Look at the queues:

SELECT ar.replica_server_name,
       DB_NAME(drs.database_id) AS database_name,
       drs.synchronization_state_desc,
       drs.log_send_queue_size,   -- KB
       drs.redo_queue_size        -- KB
FROM sys.dm_hadr_database_replica_states drs
JOIN sys.availability_replicas ar ON ar.replica_id = drs.replica_id
ORDER BY ar.replica_server_name;

If log_send_queue_size keeps growing, the bottleneck is the network or the secondary’s disk. If redo_queue_size grows, the secondary is receiving log but can’t apply it fast enough. That often happens when heavy queries run on a readable secondary.

7. Things people forget

  • Quorum: A new node changes the vote count in the cluster. A node in the DR site usually gets no vote (NodeWeight = 0).
  • Read-only routing: If the new replica is readable, update the routing list. Otherwise connections with ApplicationIntent=ReadOnly will never reach it.
  • Backup jobs: If jobs run on every replica, start each one with a sys.fn_hadr_backup_is_preferred_replica check.
  • Monitoring: Add the new server to your monitoring and alerts.

FAQ

Can a secondary replica run a different SQL Server version than the primary? It can run a newer version (that’s how rolling upgrades work), but never an older one. For a permanent setup, keep all replicas on the same version and CU.

Why doesn’t automatic seeding start? Usually because GRANT CREATE ANY DATABASE wasn’t run on the secondary. The second most common cause is data and log paths that differ from the primary. The details show up in sys.dm_hadr_automatic_seeding.

Should I add the new replica as synchronous? Add it as asynchronous first and switch to synchronous once the databases have caught up. That way the initial sync doesn’t slow down writes on the primary.

Why don’t logins work after a failover? Logins aren’t part of the availability group. Logins created without the original SIDs don’t map to the database users. Copy them with Copy-DbaLogin or sp_help_revlogin so the SIDs match.