Pcornel
Browse topics
Options
Recent
Favorites
Databases · Technical reference

Always On Availability Groups

Direct answer

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).

When to use this

Use it to operate or troubleshoot SQL Server high availability.

First 30 seconds

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.

Operational verification

primary log → sent to secondaries → hardened/redone → failover via cluster → listener

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
MariaDB / MySQL / PostgreSQL / Microsoft SQL Server concepts
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformMariaDB / MySQL / PostgreSQL / Microsoft SQL Server concepts
Scope / prerequisiteUse it to operate or troubleshoot SQL Server high availability.
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

3 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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.

Key points

Synchronous commit for automatic failover; async for distance. Check synchronization health, queue sizes and the listener. Log can't truncate while a replica lags.

Key checks
  • SELECT * FROM sys.dm_hadr_database_replica_states; — first check for this topic
  • psql -c "SELECT now(), version();" — PostgreSQL reachable and version
  • mysql -e "SELECT NOW(), VERSION();" — MariaDB/MySQL reachable and version
  • sqlcmd -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;
ColumnTells you
synchronization_state_descSYNCHRONIZED (sync replica, safe to fail over), SYNCHRONIZING, NOT SYNCHRONIZING
log_send_queue_sizeLog not yet sent to the secondary — potential data loss for async
redo_queue_sizeLog received but not yet redone — failover will wait for it

Failover types and when they are safe

TypeNeedsData loss
AutomaticSynchronous commit, automatic mode on both replicas, secondary SYNCHRONIZED, cluster quorumNone
Planned manualSynchronous commit and SYNCHRONIZEDNone
Forced (… FORCE_FAILOVER_ALLOW_DATA_LOSS)Disaster onlyPossible

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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Common mistakes

  • Synchronous replicas across slow links.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terminology layer

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.

Aliases that resolve here
always on availability groupssql server availability groupag listener failover
Confirmation

Confirm action

Continue?