Thor Logo dbatools

Get-DbaWaitStatistic

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

Synopsis

Retrieves SQL Server wait statistics for performance analysis and troubleshooting

Description

Analyzes SQL Server wait statistics from sys.dm_os_wait_stats to identify performance bottlenecks and resource contention issues. This function categorizes wait types, calculates timing metrics and percentages, and provides diagnostic explanations based on Paul Randal’s methodology. Use this to pinpoint whether your SQL Server is waiting on disk I/O, memory pressure, locking issues, or other resource constraints that are slowing down query performance.

Returns:
WaitType
Category
WaitSeconds
ResourceSeconds
SignalSeconds
WaitCount
Percentage
AverageWaitSeconds
AverageResourceSeconds
AverageSignalSeconds
URL

Reference: https://www.sqlskills.com/blogs/paul/wait-statistics-or-please-tell-me-where-it-hurts/

Syntax

Get-DbaWaitStatistic
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [[-Threshold] <Int32>]
    [-IncludeIgnorable]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Get-DbaWaitStatistic -SqlInstance sql2008, sqlserver2012

Check wait statistics for servers sql2008 and sqlserver2012

Example: 2
PS C:\> Get-DbaWaitStatistic -SqlInstance sql2008 -Threshold 98 -IncludeIgnorable

Check wait statistics on server sql2008 for thresholds above 98% and include wait stats that are most often, but not always, ignorable

Example: 3
PS C:\> Get-DbaWaitStatistic -SqlInstance sql2008 | Select-Object *

Shows detailed notes, if available, from Paul’s post

Example: 4
PS C:\> $output = Get-DbaWaitStatistic -SqlInstance sql2008 -Threshold 100 -IncludeIgnorable | Select-Object * | ConvertTo-DbaDataTable

Collects all Wait Statistics (including ignorable waits) on server sql2008 into a Data Table.

Example: 5
PS C:\> $output = Get-DbaWaitStatistic -SqlInstance sql2008
PS C:\> foreach ($row in ($output | Sort-Object -Unique Url)) { Start-Process ($row).Url }

Displays the output then loads the associated sqlskills website for each result. Opens one tab per unique URL.

Required Parameters

-SqlInstance

The target SQL Server instance or instances. Server version must be SQL Server version 2005 or higher.

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

Sets the cumulative percentage threshold for filtering wait statistics results. Only wait types that fall within this percentage of total wait time are returned.
Use this to focus on the most significant waits rather than seeing every minor wait type on your system. For example, 95% shows waits that make up 95% of all wait time.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value95
-IncludeIgnorable

Includes wait types that are typically benign and can be safely ignored during troubleshooting, such as Service Broker idle waits and background task waits.
Use this when you need to see all wait activity or when investigating unusual issues with specific features like mirroring or Availability Groups.

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

Returns one object per wait type found in sys.dm_os_wait_stats matching the specified threshold criteria. Each object contains detailed wait statistics and diagnostic information for a specific SQL Server wait type.

Default display properties (via Select-DefaultView):

  • ComputerName: The name of the computer hosting the SQL Server instance
  • InstanceName: The SQL Server instance name
  • SqlInstance: The full SQL Server instance name (computer\instance)
  • WaitType: The name of the SQL Server wait type (e.g., PAGEIOLATCH_EX, LCK_M_IX)
  • Category: The wait category classification (e.g., Buffer IO, Lock, Network IO, CPU, Idle, Memory, etc.)
  • WaitSeconds: Total time in seconds the system has waited on this wait type (decimal)
  • ResourceSeconds: Time in seconds spent waiting for a resource to become available (decimal)
  • SignalSeconds: Time in seconds spent waiting for a signal after acquiring the resource (decimal)
  • WaitCount: Total number of times this wait type has occurred (bigint)
  • Percentage: Percentage of total system wait time consumed by this wait type (0-100, decimal)
  • AverageWaitSeconds: Average time per wait occurrence in seconds (decimal)
  • AverageResourceSeconds: Average resource wait time per occurrence in seconds (decimal)
  • AverageSignalSeconds: Average signal wait time per occurrence in seconds (decimal)
  • URL: Hyperlink to sqlskills.com detailed documentation for this wait type (XML/string)

*Additional properties available (use Select-Object ):

  • Notes: Detailed diagnostic explanation of the wait type and troubleshooting guidance from Paul Randal’s methodology (when using Select-Object *)
  • Ignorable: Boolean indicating whether this wait type is typically safe to ignore during troubleshooting (only shown when -IncludeIgnorable is specified) When -IncludeIgnorable is not specified, the Notes and Ignorable properties are excluded from output. Use Select-Object * to access all properties including detailed diagnostic notes for each wait type.