Thor Logo dbatools

Get-DbaDbMirrorMonitor

View Source
Chrissy LeMaire (@cl), netnerds.net
Windows, Linux, macOS

Synopsis

Retrieves database mirroring performance metrics and monitoring history from SQL Server instances

Description

Retrieves detailed database mirroring performance statistics from the msdb monitoring tables, helping you track mirroring health and identify performance bottlenecks. This function executes sp_dbmmonitorresults to pull metrics like log generation rates, send rates, transaction delays, and recovery progress from both principal and mirror databases.

Use this when troubleshooting mirroring performance issues, monitoring replication lag, or generating compliance reports for high availability configurations. You can optionally refresh the monitoring data before retrieval and filter results by time periods or row counts to focus on specific timeframes.

The function returns comprehensive metrics including unsent log size, recovery rates, average delays, and witness status - all the key indicators DBAs need to assess mirroring health without manually querying system tables.

Syntax

Get-DbaDbMirrorMonitor
    [[-SqlInstance] <DbaInstanceParameter[]>]
    [[-SqlCredential] <PSCredential>]
    [[-Database] <String[]>]
    [[-InputObject] <Database[]>]
    [-Update]
    [[-LimitResults] <String>]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Get-DbaDbMirrorMonitor -SqlInstance sql2008, sql2012

Returns last two hours’ worth of status rows for a monitored database from the status table on sql2008 and sql2012.

Example: 2
PS C:\> Get-DbaDbMirrorMonitor -SqlInstance sql2005 -LimitResults LastDay -Update

Updates monitor stats then returns the last 24 hours worth of status rows for a monitored database from the status table on sql2008 and sql2012.

Optional Parameters

-SqlInstance

The target SQL Server instance

PropertyValue
Alias
RequiredFalse
Pipelinefalse
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.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-Database

Specifies which mirrored databases to monitor. Only databases configured for mirroring will return results.
Use this to focus monitoring on specific databases instead of checking all mirrored databases on the instance.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-InputObject

Accepts database objects from Get-DbaDatabase pipeline input.
Use this when you want to filter databases first before checking their mirroring status.

PropertyValue
Alias
RequiredFalse
Pipelinetrue (ByValue)
Default Value
-Update

Forces a refresh of mirroring statistics before retrieving results by calling sp_dbmmonitorupdate.
Use this when you need the most current metrics, though SQL Server automatically limits updates to once every 15 seconds and requires sysadmin privileges.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default ValueFalse
-LimitResults

Controls how much historical monitoring data to retrieve from the msdb.dbo.dbm_monitor_data table.
Choose shorter time periods for recent performance analysis or longer periods for trend analysis. Row-based options return the most recent entries regardless of time.
Options include:
LastRow
LastTwoHours
LastFourHours
LastEightHours
LastDay
LastTwoDays
Last100Rows
Last500Rows
Last1000Rows
Last1000000Rows

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default ValueLastTwoHours
Accepted ValuesLastRow,LastTwoHours,LastFourHours,LastEightHours,LastDay,LastTwoDays,Last100Rows,Last500Rows,Last1000Rows,Last1000000Rows
-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.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default ValueFalse

Outputs

PSCustomObject

Returns one object per monitoring record retrieved from the database mirroring monitor table. Multiple records may be returned depending on the -LimitResults parameter value.

Properties:

  • ComputerName: The computer name of the SQL Server instance
  • InstanceName: The SQL Server instance name
  • SqlInstance: The full SQL Server instance name (computer\instance)
  • DatabaseName: Name of the mirrored database
  • Role: The role of the server instance - Principal or Mirror
  • MirroringState: Current mirroring state (Synchronizing, Synchronized, Suspended, Disconnected, etc.)
  • WitnessStatus: Status of the witness server (Connected, Disconnected, Quorum Lost, etc.)
  • LogGenerationRate: Rate at which transaction log is being generated on the principal (KB/sec)
  • UnsentLog: Amount of log not yet sent to the mirror (KB)
  • SendRate: Rate at which log is being sent to the mirror (KB/sec)
  • UnrestoredLog: Amount of log not yet restored on the mirror (KB)
  • RecoveryRate: Rate at which log is being restored on the mirror (KB/sec)
  • TransactionDelay: Delay caused by database mirroring for committed transactions (milliseconds)
  • TransactionsPerSecond: Number of transactions per second being processed
  • AverageDelay: Average transaction delay (milliseconds)
  • TimeRecorded: DateTime when this monitoring record was recorded
  • TimeBehind: Amount the mirror lags behind the principal (milliseconds)
  • LocalTime: Local time on the server when the record was generated