Script: Check AG Replica Role and Synchronization State

This script returns the current role, synchronization state, health status, and failover configuration for replicas participating in an Always On Availability Group.

It is commonly used during failover validation, replica troubleshooting, and general high availability health checks.


The Script


Example Output

The result set shows one row per replica in each Availability Group.

Important columns include:

  • role_desc – Indicates whether the replica is PRIMARY or SECONDARY
  • synchronization_health_descHEALTHY, PARTIALLY_HEALTHY, or NOT_HEALTHY
  • connected_state_desc – Shows whether the replica is currently connected
  • availability_mode_descSYNCHRONOUS_COMMIT or ASYNCHRONOUS_COMMIT
  • failover_mode_descAUTOMATIC or MANUAL

Together, these columns provide a quick operational view of AG configuration and health status.

SQL Server query showing AG replica role and synchronization state

Notes

  • Only returns data if Availability Groups are enabled
  • Useful before and after planned failovers
  • Check synchronization_health_desc before initiating manual failover
  • Combine with latency script for deeper replication visibility

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *