You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Test-DbaAvailabilityGroup - Add comprehensive AG health monitoring
Implements comprehensive health monitoring for Availability Groups similar to SSMS AG Dashboard.
Adds -HealthCheck switch parameter that returns detailed database replica state information including:
- Replica-level health: Role, AvailabilityMode, FailoverMode, ConnectionState, SynchronizationState
- Database-level status: SynchronizationState, IsFailoverReady, IsJoined, IsSuspended, SuspendReason
- Performance metrics: LogSendQueue, RedoQueue sizes and rates
- LSN tracking: LastCommit, LastHardened, LastSent, LastReceived, LastRedone with times and LSNs
- Recovery metrics: EstimatedRecoveryTime, EstimatedDataLoss, SynchronizationPerformance
Completes feature request from issue #2190 based on research and code proposals from
@andreasjordan and @ReeceGoding, referencing Microsoft AG monitoring documentation.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-authored-by: Chrissy LeMaire <potatoqualitee@users.noreply.github.com>
Copy file name to clipboardExpand all lines: public/Test-DbaAvailabilityGroup.ps1
+73-11Lines changed: 73 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -48,6 +48,10 @@ function Test-DbaAvailabilityGroup {
48
48
Validates that the most recent database backup chain can be used for AG database addition.
49
49
Enables validation using existing backups instead of creating new ones, but requires the last backup to be a transaction log backup. Use this to test AG readiness with your current backup strategy.
50
50
51
+
.PARAMETERHealthCheck
52
+
Performs comprehensive health monitoring of the Availability Group similar to SSMS AG Dashboard.
53
+
Returns detailed replica and database synchronization status including queue sizes, LSN information, and performance metrics. Use this to monitor AG health, identify synchronization issues, or troubleshoot failover readiness.
54
+
51
55
.PARAMETEREnableException
52
56
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
53
57
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
@@ -73,21 +77,27 @@ function Test-DbaAvailabilityGroup {
Performs comprehensive health monitoring of TestAG1, returning detailed synchronization status for all replicas and databases similar to SSMS AG Dashboard.
76
85
#>
77
86
[CmdletBinding()]
78
87
param (
79
-
[Parameter(Mandatory=$true,Position=0)]
88
+
[Parameter(Mandatory)]
80
89
[DbaInstanceParameter]$SqlInstance,
81
90
[PSCredential]$SqlCredential,
82
-
[Parameter(Mandatory=$true)]
91
+
[Parameter(Mandatory)]
83
92
[string]$AvailabilityGroup,
84
93
[DbaInstanceParameter[]]$Secondary,
85
94
[PSCredential]$SecondarySqlCredential,
86
95
[string[]]$AddDatabase,
87
-
[ValidateSet('Automatic','Manual')]
96
+
[ValidateSet("Automatic","Manual")]
88
97
[string]$SeedingMode,
89
98
[string]$SharedPath,
90
99
[switch]$UseLastBackup,
100
+
[switch]$HealthCheck,
91
101
[switch]$EnableException
92
102
)
93
103
process {
@@ -110,22 +120,75 @@ function Test-DbaAvailabilityGroup {
110
120
return
111
121
}
112
122
113
-
if ($ag.LocalReplicaRole-ne'Primary') {
123
+
if (-not$HealthCheck-and$ag.LocalReplicaRole-ne'Primary') {
114
124
Stop-Function-Message "LocalReplicaRole of replica $server is not Primary, but $($ag.LocalReplicaRole). Please connect to the current primary replica $($ag.PrimaryReplica)."
115
125
return
116
126
}
117
127
118
128
# Test for health of Availability Group
119
129
120
-
# Later: Get replica and database states like in SSMS dashboard
121
-
# Now: Just test for ConnectionState -eq 'Connected'
130
+
if ($HealthCheck) {
131
+
# Comprehensive health monitoring similar to SSMS AG Dashboard
132
+
# Returns detailed database replica state information for all replicas
0 commit comments