Get-sqmDeadlockReport
Deadlock Analysis
sqmSQLTool v1.8.2+ · Get
🔓 VIEW SERVER STATE required
Note: The Ring Buffer holds 4 MB by default. At high deadlock frequency export early; older events are silently discarded once the buffer wraps.
Parameters
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
| -SqlInstance | string | Optional | $env:COMPUTERNAME | Target SQL Server instance. |
| -SqlCredential | PSCredential | Optional | — | SQL or Windows credential. |
| -StartTime | datetime | Optional | (Get-Date).AddHours(-24) | Return deadlocks from this point in time. |
| -EndTime | datetime | Optional | Get-Date | Return deadlocks up to this point in time. |
| -MaxDeadlocks | int | Optional | 100 | Maximum number of deadlock records to return (newest first). |
| -OutputPath | string | Optional | — | When provided, writes one .xdl file per deadlock. File name: Deadlock_Instance_timestamp_N.xdl. Directory is created automatically. |
| -EnableException | switch | Switch | $false | Throw on error instead of Write-Error. |
Execution Flow
Return Object (per deadlock)
| Property | Type | Description |
|---|---|---|
| .Timestamp | datetime2 | Time the deadlock was recorded by the XE session. |
| .DeadlockIndex | int | Sequential index within this call (1-based, newest first). |
| .VictimSpid | string | SPID of the session chosen as victim. |
| .VictimLogin / .VictimHost / .VictimProgram | string | Identity of the victim session. |
| .VictimStatement | string | SQL statement the victim was executing (from inputbuf). |
| .VictimWaitTime | string | Wait time of the victim at deadlock time. |
| .ProcessCount | int | Total number of processes involved in the deadlock. |
| .Processes | List | All involved processes: IsVictim, SpId, LoginName, HostName, Statement, LockMode, WaitResource, LogUsed. |
| .Resources | List | Contested resources: ResourceType, ObjectName, IndexName, LockMode, AssociatedProcesses. |
| .DeadlockGraphXml | string | Raw deadlock XML node — save as .xdl for SSMS visualization. |
Examples
Deadlocks in the last 24 hours (default)
Get-sqmDeadlockReport
Deadlocks of the last 7 days on a named instance
Get-sqmDeadlockReport -SqlInstance "SQL01" -StartTime (Get-Date).AddDays(-7)
Export deadlock graphs as XDL files for SSMS
Get-sqmDeadlockReport -SqlInstance "SQL01" -OutputPath "C:\System\WinSrvLog\MSSQL\Deadlocks"
Show victim and statement for each deadlock in the last hour
Get-sqmDeadlockReport -StartTime (Get-Date).AddHours(-1) |
Select-Object Timestamp, VictimLogin, VictimStatement, ProcessCount