Use it to operate or troubleshoot SQL Server high availability.
Always On Availability Groups
SQL Server Always On Availability Groups replicate databases to secondary replicas (sync or async) with automatic failover and a listener name for clients, on top of Windows Server Failover Clustering (or Pacemaker on Linux).
1. SELECT * FROM sys.dm_hadr_database_replica_states; — synchronization_state, queues.
2. AG dashboard health.
3. Cluster quorum healthy.
4. Listener resolves and connects.
5. Test failover.
primary log → sent to secondaries → hardened/redone → failover via cluster → listener
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 How to verify Verify boundary
Confirm every database is SYNCHRONIZED on synchronous replicas. Test failover in a maintenance window and confirm applications reconnect through the listener.
Step 2 Checks Verify boundary
SELECT ag.name, ar.replica_server_name, ars.role_desc, ars.synchronization_health_desc
FROM sys.availability_groups ag
JOIN sys.availability_replicas ar ON ar.group_id = ag.group_id
JOIN sys.dm_hadr_availability_replica_states ars ON ars.replica_id = ar.replica_id;
Synchronous commit gives zero data loss and automatic failover; asynchronous for distant DR. Use the listener name in connection strings with MultiSubnetFailover=True. Logins, jobs and linked servers are not replicated — sync them separately (dbatools Copy-DbaLogin).
Step 3 Common failures Narrow the fault
A large redo queue makes failover slow. Logins and Agent jobs are not part of the AG and must be copied to each replica. Applications using the server name instead of the listener do not follow failover.
Synchronous commit for automatic failover; async for distance. Check synchronization health, queue sizes and the listener. Log can't truncate while a replica lags.
SELECT * FROM sys.dm_hadr_database_replica_states;— first check for this topicpsql -c "SELECT now(), version();"— PostgreSQL reachable and versionmysql -e "SELECT NOW(), VERSION();"— MariaDB/MySQL reachable and versionsqlcmd -S <server> -Q "SELECT @@VERSION"— SQL Server reachable and version
ReferenceWhat it is1 section · depth on demand
How it works
The primary sends log blocks to each secondary. In synchronous mode a commit waits until secondaries harden the log. The Windows or Pacemaker cluster decides ownership and failover.
ReferenceImportant terms & boundaries2 sections · depth on demand
In depth
Health at a glance
SELECT ag.name AS ag, ar.replica_server_name, ars.role_desc,
drs.database_id, drs.synchronization_state_desc, drs.synchronization_health_desc,
drs.log_send_queue_size AS send_kb, drs.redo_queue_size AS redo_kb,
drs.last_commit_time
FROM sys.dm_hadr_database_replica_states drs
JOIN sys.availability_replicas ar ON ar.replica_id = drs.replica_id
JOIN sys.dm_hadr_availability_replica_states ars ON ars.replica_id = ar.replica_id
JOIN sys.availability_groups ag ON ag.group_id = ar.group_id;
| Column | Tells you |
|---|---|
synchronization_state_desc | SYNCHRONIZED (sync replica, safe to fail over), SYNCHRONIZING, NOT SYNCHRONIZING |
log_send_queue_size | Log not yet sent to the secondary — potential data loss for async |
redo_queue_size | Log received but not yet redone — failover will wait for it |
Failover types and when they are safe
| Type | Needs | Data loss |
|---|---|---|
| Automatic | Synchronous commit, automatic mode on both replicas, secondary SYNCHRONIZED, cluster quorum | None |
| Planned manual | Synchronous commit and SYNCHRONIZED | None |
Forced (… FORCE_FAILOVER_ALLOW_DATA_LOSS) | Disaster only | Possible |
Not in the availability group — copy them yourself
Logins (with the same SID for SQL logins), SQL Server Agent jobs, linked servers, server-level permissions and credentials, Database Mail, and instance settings. A failover without these leaves applications unable to log in or nightly jobs not running.
Client connection
Connect through the listener with MultiSubnetFailover=True so the driver tries all listener IPs in parallel; without it, multi-subnet failovers can take a TCP timeout per attempt. ApplicationIntent=ReadOnly plus read-only routing sends reporting connections to a readable secondary.
Common mistakes
- Synchronous replicas across slow links.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.