Get-DbaAgDatabaseReplicaState
View SourceSynopsis
Retrieves the runtime state of databases participating in availability groups across all replicas.
Description
Retrieves comprehensive health monitoring information about databases participating in SQL Server availability groups, similar to the SSMS AG Dashboard. This function returns detailed database replica state information for all replicas in the availability group.
The class Microsoft.SqlServer.Management.Smo.DatabaseReplicaState represents the runtime state of a database that’s participating in an availability group. This database may be located on any of the replicas that compose the availability group.
Use this command to monitor availability group health, troubleshoot synchronization issues, verify failover readiness, identify data loss risks, and generate detailed operational reports showing the state of each database on each replica in your availability groups.
Syntax
Get-DbaAgDatabaseReplicaState
[[-SqlInstance] <DbaInstanceParameter[]>]
[[-SqlCredential] <PSCredential>]
[[-AvailabilityGroup] <String[]>]
[[-Database] <String[]>]
[[-InputObject] <AvailabilityGroup[]>]
[-EnableException]
[<CommonParameters>]
Examples
Example: 1
PS C:\> Get-DbaAgDatabaseReplicaState -SqlInstance sql2017a
Returns database replica state information for all databases in all availability groups on sql2017a
Example: 2
PS C:\> Get-DbaAgDatabaseReplicaState -SqlInstance sql2017a -AvailabilityGroup AG101
Returns database replica state information for all databases in the availability group AG101 on sql2017a
Example: 3
PS C:\> Get-DbaAgDatabaseReplicaState -SqlInstance sql2017a -AvailabilityGroup AG101 -Database AppDB
Returns database replica state information for the AppDB database in the availability group AG101 on sql2017a
Example: 4
PS C:\> Get-DbaAvailabilityGroup -SqlInstance sqlcluster -AvailabilityGroup SharePoint | Get-DbaAgDatabaseReplicaState
Returns database replica state information for all databases in the availability group SharePoint on server sqlcluster
Example: 5
PS C:\> Get-DbaAvailabilityGroup -SqlInstance sqlcluster -AvailabilityGroup SharePoint | Get-DbaAgDatabaseReplicaState -Database Sharepoint_Config
Returns database replica state information for the Sharepoint_Config database in the availability group SharePoint on server sqlcluster
Optional Parameters
-SqlInstance
The target SQL Server instance or instances. Server version must be SQL Server version 2012 or higher.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | false |
| Default Value |
-SqlCredential
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | false |
| Default Value |
-AvailabilityGroup
Specifies which availability groups to query for database replica state information. Accepts multiple availability group names.
Use this to limit results to specific availability groups when you have multiple AGs on the same instance.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | false |
| Default Value |
-Database
Specifies which availability group databases to return replica state information for. Accepts multiple database names.
Use this to focus on specific databases when troubleshooting AG issues or monitoring particular applications.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | false |
| Default Value |
-InputObject
Accepts availability group objects from Get-DbaAvailabilityGroup via pipeline input.
Use this when you want to chain commands to get database replica state details from already retrieved availability groups.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | true (ByValue) |
| Default Value |
-EnableException
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with “sea of red” exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this “nice by default” feature off and enables you to catch exceptions with your own try/catch.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | false |
| Default Value | False |
dbatools