标签:order ble source tab pre 语句 into color clear
SELECT * FROM sys.dm_os_wait_stats WHERE wait_time_ms>0 ORDER BY wait_time_ms DESC
只有sql server重启的时候才会自动清除等待统计信息,可以通过 DBCC SQLPERF("sys.dm_os_wait_stats", CLEAR)命令清除统计信息。
通过一个临时表和waitfor delay 语句跟踪一段时间内发生的变化,从而判断当前正在发生的等待。
IF OBJECT_ID(‘tempdb..#wait_stats‘) IS NOT NULL DROP TABLE #wait_stats SELECT * INTO #wait_stats FROM sys.dm_os_wait_stats WAITFOR DELAY ‘00:00:05‘ SELECT ws1.wait_type, ws2.waiting_tasks_count - ws1.waiting_tasks_count AS waiting_tasks_count, ws2.wait_time_ms - ws1.wait_time_ms AS wait_time_ms, CASE WHEN ws2.max_wait_time_ms > ws1.max_wait_time_ms THEN ws2.max_wait_time_ms ELSE ws1.max_wait_time_ms END AS max_wait_time_ms, ws2.signal_wait_time_ms - ws1.signal_wait_time_ms AS signal_wait_time_ms, (ws2.wait_time_ms - ws1.wait_time_ms)-(ws2.signal_wait_time_ms - ws1.signal_wait_time_ms) AS resource_wait_time_ms FROM sys.dm_os_wait_stats AS ws2 JOIN #wait_stats AS ws1 ON ws1.wait_type=ws2.wait_type WHERE ws2.wait_time_ms - ws1.wait_time_ms > 0 ORDER BY ws2.wait_time_ms - ws1.wait_time_ms DESC
在查看资源等待时间和信号等待时间的差别的时候,最好观察两者在总时间内所占的比例。
SELECT SUM(signal_wait_time_ms) AS total_signal_wait_time_ms, SUM(wait_time_ms - signal_wait_time_ms) AS resource_wait_time_ms, SUM(signal_wait_time_ms) * 1.0 / SUM(wait_time_ms) * 100 AS signal_wait_percent, SUM(wait_time_ms - signal_wait_time_ms) * 1.0 / SUM(wait_time_ms) * 100 AS resource_wait_percent FROM sys.dm_os_wait_stats
标签:order ble source tab pre 语句 into color clear
原文地址:http://www.cnblogs.com/lovezmx2012/p/6917270.html