Created
November 30, 2024 17:44
-
-
Save petesql/a4b1e1d39250c6d9b82d84f64ef04872 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Get AAG Latency | |
| SELECT | |
| CAST(DB_NAME(database_id)as VARCHAR(40)) database_name, | |
| Convert(VARCHAR(20),last_commit_time,22) last_commit_time | |
| ,CAST(CAST(((DATEDIFF(s,last_commit_time,GetDate()))/3600) as varchar) + ' hour(s), ' | |
| + CAST((DATEDIFF(s,last_commit_time,GetDate())%3600)/60 as varchar) + ' min, ' | |
| + CAST((DATEDIFF(s,last_commit_time,GetDate())%60) as varchar) + ' sec' as VARCHAR(30)) time_behind_primary | |
| ,redo_queue_size | |
| ,redo_rate | |
| ,CONVERT(VARCHAR(20),DATEADD(mi,(redo_queue_size/redo_rate/60.0),GETDATE()),22) estimated_completion_time | |
| ,CAST((redo_queue_size/redo_rate/60.0) as decimal(10,2)) [estimated_recovery_time_minutes] | |
| ,(redo_queue_size/redo_rate) [estimated_recovery_time_seconds] | |
| ,CONVERT(VARCHAR(20),GETDATE(),22) [current_time] | |
| FROM sys.dm_hadr_database_replica_states (NOLOCK) | |
| WHERE last_redone_time is not null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment