info@techdevops.com | 437-991-3573 | Data Engineering Services
TechDevOps.com
Resources Tools
Experts in Microsoft SQL Server on Windows, Linux, Containers | Clusters, Always On, FCI | Migrations, Cloud, Performance



Determine which Replica has the most up-to-date database in a Microsoft SQL Server Always On Availability Group
by BFarrell (Principal Consultant; Architecture; Engineering)
2025-11-26







Determine which Replica has the most up-to-date database in a Microsoft SQL Server Always On Availability Group:

Notes:

(1) Run on all Replicas.
(2) LSNs tell you which database is most current.
(3) last_hardened_lsn is the most important value. Highest # is the most up-to-date replica.


SELECT
@@SERVERNAME AS ServerName,
db_name(dr_state.database_id) AS DatabaseName,
dr_state.last_hardened_lsn,
dr_state.redo_queue_size,
dr_state.log_send_queue_size,
dr_state.last_redone_lsn,
dr_state.synchronization_state_desc,
dr_state.synchronization_health_desc
FROM sys.dm_hadr_database_replica_states dr_state
ORDER BY DatabaseName;


Microsoft Always On Availability Groups