Thursday, 21 June 2018

How to check AG delay in SQL Server

SELECT  ar.replica_server_name, max(datediff(MINUTE, drs.last_commit_time, getdate())) as Delay_inMin

FROM sys.dm_hadr_database_replica_states AS drs INNER JOIN sys.availability_databases_cluster AS adc ON drs.group_id = adc.group_id

AND drs.group_database_id = adc.group_database_id INNER JOIN sys.availability_groups AS ag ON ag.group_id = drs.group_id INNER JOIN sys.availability_replicas AS ar ON drs.group_id = ar.group_id

AND drs.replica_id = ar.replica_id WHERE adc.database_name = 'DatabaseName'  --And replica_server_name <> 'UHSCMPRDROSQL01' And drs.is_local <> 1

group by  ar.replica_server_name 

No comments:

Post a Comment

Check if column exists or not in the SQL server

--method 1 IF EXISTS(SELECT 1 FROM sys.columns with (nolock)           WHERE Name = N'LoginName'           AND Object_ID = Objec...