Thor Logo dbatools

Get-DbaWaitResource

View Source
Stuart Moore (@napalmgram), stuart-moore.com
Windows, Linux, macOS

Synopsis

Translates wait resource strings into human-readable database object information for troubleshooting blocking and deadlocks

Description

Converts cryptic wait resource identifiers from sys.dm_exec_requests into readable database object details that DBAs can actually use for troubleshooting. When you’re investigating blocking chains or deadlocks, you see wait_resource values like ‘PAGE: 10:1:9180084’ or ‘KEY: 7:35457594073541168 (de21f92a1572)’ in DMVs, but these don’t tell you which actual table or index is involved.

For PAGE wait resources, this function uses DBCC PAGE internally to identify the specific database, data file, schema, and object that owns the contested page. For KEY wait resources, it queries system catalog views to determine the database, schema, table, and index being waited on. With the -Row parameter, you can also retrieve the actual data from the locked row, which is invaluable for understanding what specific record is causing contention.

This eliminates the manual detective work of decoding resource IDs and saves time when you need to quickly identify the root cause of blocking issues in production environments.

Syntax

Get-DbaWaitResource
    [-SqlInstance] <DbaInstanceParameter>
    [[-SqlCredential] <PSCredential>]
    [-WaitResource] <String>
    [-Row]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Get-DbaWaitResource -SqlInstance server1 -WaitResource 'PAGE: 10:1:9180084'

Will return an object containing; database name, data file name, schema name and the object which owns the resource

Example: 2
PS C:\> Get-DbaWaitResource -SqlInstance server2 -WaitResource 'KEY: 7:35457594073541168 (de21f92a1572)'

Will return an object containing; database name, schema name and index name which is being waited on.

Example: 3
PS C:\> Get-DbaWaitResource -SqlInstance server2 -WaitResource 'KEY: 7:35457594073541168 (de21f92a1572)' -row

Will return an object containing; database name, schema name and index name which is being waited on, and in addition the contents of the locked row at the time the command is run.

Required Parameters

-SqlInstance

The target SQL Server instance or instances.

PropertyValue
Alias
RequiredTrue
Pipelinefalse
Default Value
-WaitResource

Specifies the cryptic wait resource identifier from sys.dm_exec_requests that you need to decode into readable database object information.
Accepts PAGE format like ‘PAGE: 10:1:9180084’ or KEY format like ‘KEY: 7:35457594073541168 (de21f92a1572)’.
Use this when troubleshooting blocking chains or deadlocks to identify which specific table, index, or page is causing contention.

PropertyValue
Alias
RequiredTrue
Pipelinetrue (ByValue)
Default Value

Optional Parameters

-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
-Row

Returns the actual data from the locked row in addition to the object information for KEY wait resources.
Provides the specific record values that are causing the lock contention, which helps identify patterns or problematic data.
Only works with KEY wait resources and uses NOLOCK hint to retrieve the current row data safely.

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

Output varies based on the wait resource type specified:

PAGE Wait Resources (when WaitResource matches ‘PAGE: dbid:fileid:pageid’ format):

Returns one object with the following properties:

  • DatabaseID: The database ID from the wait resource
  • DatabaseName: The name of the database containing the page
  • DataFileName: The logical name of the data file containing the page
  • DataFilePath: The physical file system path to the data file
  • ObjectID: The internal object ID (table or index) owning the page
  • ObjectName: The name of the table or index that owns the page
  • ObjectSchema: The schema name containing the object
  • ObjectType: The type of object (USER_TABLE, CLUSTERED_INDEX, NONCLUSTERED_INDEX, HEAP, etc.) KEY Wait Resources (when WaitResource matches ‘KEY: hobtid (physicallocation)’ format):

Returns one object with the following properties:

  • DatabaseID: The database ID from the wait resource
  • DatabaseName: The name of the database containing the key
  • SchemaName: The schema name containing the object
  • IndexName: The name of the index or heap being waited on
  • ObjectID: The internal object ID of the table
  • ObjectName: The name of the table that owns the index or heap
  • HobtID: The heap or B-tree ID (allocation unit ID) being waited on

When -Row is specified with KEY wait resources:

The output is expanded to include the actual data row from the table. The full row contents are returned as properties matching the table’s column names. When the row data cannot be retrieved (row was deleted or moved), only the key resource object properties are returned.