Hello Geeks and welcome to the Day 17 of the long series of One DMV a day. In this series of blogs I will be exploring and explaining the most useful DMVs in SQL Server. As we go ahead in this series we will also talk about the usage, linking between DMVs and some scenarios where these DMVs will be helpful while you are using SQL Server. For the complete list in the series please click here.

Today I am going to cover one of the most famous DMV of all, sys.dm_os_wait_stats. This DMV has solved so many cases and gives a lot of information which just needs to be read and used correctly to your benefit.

In SQL Server if a task is not completed and not running it should be waiting. First question to answer before you even start troubleshooting is – What is the resource it is waiting on? In an ideal world you will have once procedure/query or application which is slow. In such cases you will use another DMV which I am going to cover tomorrow.

But, all my DBA friends who work on chaotic Production servers, we do not live in an ideal world. :( Every issue we get is server level and all the applications are affected. Most of our Production servers are designed to host multiple applications or multiple functionalities in sites.



So to start with we need to identify if the problem is at the server level. Sys.dm_os_wait_stats is the right place to start our troubleshooting. This helps you identify what is the highest waits on my SQL Server. The straight forward output of this DMV doesn’t make much sense as the stats in this DMV are accumulated over time. They get flushed when a SQL instance is restarted. So to get the reliable and relevant details from sys.dm_os_wait_stats you need to get the delta of waits for a significant time frame.

There are ways to flush the data out of sys.dm_os_wait_stats without restarting SQL Server by running below script. But I warn you that this is a very bad practice. You can get the delta waits difference without flushing the data out of this DMV.

The below query pulls out the delta waits for one minute from sys.dm_os_wait_stats. You can confirm based on the output if the problem is with signal waits or any wait type. Dealing with each wait type is a huge topic in itself. I would recommend to follow MS whitepaper on waits. I will be filtering on the wait types from the CSS repository.

Based on the above output we can take necessary action based on the wait types. As I have already mentioned in the beginning of the post, sys.dm_os_wait_stats can only guide you get the pain area. I have showed you how to use this DMV to get the details. Troubleshooting based on each wait type will be a long series. I hope someone would be starting that soon on SQL Server Geeks. :) If not I will do it some time within an years time from now. 😉

Tomorrow I will talk about another OS related DMV. So, stay tuned. Till then

Happy Learning,

Like us on FaceBook | Join the fastest growing SQL Server group on FaceBook |
Follow me on Twitter | Follow me on FaceBook