Thursday 15 August 2013

SQL Server Wait Types - SQL Server Performance Troubleshooting

T-SQL Query to rank SQL Server Wait Types by highest percentage of total wait time

Below query uses the SQL Server Dynamic Management View (DMV) sys.dm_os_wait_stats in order to extrapolate the desired information. A column has also been added to provide details of the percentage of total wait time that a particular Wait Type is responsible for.

SELECT
wait_type,
waiting_tasks_count,
max_wait_time_ms,
resource_wait_time_ms = (wait_time_ms - signal_wait_time_ms),
PercentOfAllResourceWaitTime =
(cast((wait_time_ms - signal_wait_time_ms) as decimal(19,2)) /
(select sum((wait_time_ms - signal_wait_time_ms)) from sys.dm_os_wait_stats))
* 100
FROM sys.dm_os_wait_stats
ORDER BY PercentOfAllResourceWaitTime DESC

No comments: