码迷,mamicode.com
首页 > 数据库 > 详细

sql server发生的等待统计信息

时间:2017-05-29 09:51:35      阅读:246      评论:0      收藏:0      [点我收藏+]

标签: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

 

sql server发生的等待统计信息

标签:order   ble   source   tab   pre   语句   into   color   clear   

原文地址:http://www.cnblogs.com/lovezmx2012/p/6917270.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!