· Uwe Janke
Commands / Get-sqmBlockingHistory

Get-sqmBlockingHistory

PerformancesqmSQLTool v1.9.101+ · Get🔓 VIEW SERVER STATE  + ALTER ANY EVENT SESSION
Reads blocked_process_report events already captured in Extended Events ring buffers - unlike Get-sqmBlockingReport, which only shows blocking happening at the exact moment it is called. The built-in system_health session does not reliably include this event on a default installation, so this function first ensures a dedicated sqm_BlockedProcessMonitor session exists (via Register-sqmBlockedProcessMonitor, skip with -SkipMonitorSetup), then reads and de-duplicates events from both sessions. Two hard limits are surfaced in the result rather than hidden: blocked process threshold (s) is 0 (disabled) by default, so no incidents can exist until it is raised; and the ring buffer target is memory-limited and wraps around, typically covering only the last few hours on a busy instance.

Parameters

ParameterTypeRequiredDefaultNotes
-SqlInstancestringOptional$env:COMPUTERNAMETarget SQL Server instance.
-SqlCredentialPSCredentialOptional, SQL or Windows credential.
-SincedatetimeOptional, Only return incidents at or after this timestamp. Default: no lower bound (everything still in the ring buffer).
-MinWaitSecondsintOptional0Only report incidents whose blocked-process wait time was at least this many seconds.
-SkipMonitorSetupswitchSwitch$falseSkip ensuring sqm_BlockedProcessMonitor exists/is running - read only what is already there. Use with a read-only account lacking ALTER ANY EVENT SESSION.
-OutputPathstringOptionalGet-sqmDefaultOutputPath\BlockingHistoryDirectory for the CSV/HTML report. Only written when at least one incident is found.
-EnableExceptionswitchSwitch$falseThrow exceptions immediately instead of returning as errors.
-NoOpenswitchSwitch$falseDo not automatically open the generated report.

Execution Flow

START dbatools installed? NO throw: dbatools not found YES Read 'blocked process threshold (s)' from sys.configurations ThresholdConfigured = value > 0 (default: 0, disabled - no incidents can exist until raised) -SkipMonitorSetup? NO YES Register-sqmBlockedProcessMonitor Ensures 'sqm_BlockedProcessMonitor' XE session exists and is running Shred ring_buffer target of both sessions sqm_BlockedProcessMonitor + system_health · DISTINCT blocked_process_report events .value() against XEventData directly (a materialized XML CTE returns NULL columns) Filter: -Since, -MinWaitSeconds DBNull-aware wait-time parsing (Invoke-DbaQuery returns SQL NULL as [DBNull], not $null) -OutputPath and incidents > 0? YES Export CSV + HTML Severity: ≥60s crit, ≥10s warn NO Return [PSCustomObject] ThresholdConfigured · HasIncidents · Incidents[] · IncidentCount OldestEventInBuffer · MonitorSessionStartTime · CsvFile · HtmlFile DONE

Examples

Read past blocking incidents on the local instance
Get-sqmBlockingHistory -SqlInstance "SQL01"
Only incidents from the last 2 hours, at least 10 seconds blocked
Get-sqmBlockingHistory -SqlInstance "SQL01" -Since (Get-Date).AddHours(-2) -MinWaitSeconds 10
Check whether the threshold even allows incidents to be captured
$h = Get-sqmBlockingHistory -SqlInstance "SQL01"
if (-not $h.ThresholdConfigured) { Write-Warning "blocked process threshold is 0 - no history possible." }