Sql-server – Find Queries that Are Causing Waits

sql-server-2008waits

Given a certain kind of wait, how do you find which queries are causing those waits safely on a production SQL 2008 R2 Server?

In this particular case I am wondering about async_network_io.

Best Answer

My favorite way to check these is to use Adam Machanic's excellent sp_WhoIsActive stored proc. Here's a video on how to use it and a link to download the code:

http://www.brentozar.com/archive/2010/09/sql-server-dba-scripts-how-to-find-slow-sql-server-queries/

The catch is that you have to run it periodically to check for results. If you want this data to be gathered for you periodically, check out Kendra Little's tutorial on capturing sp_WhoIsActive results to a table:

http://www.littlekendra.com/2011/02/01/whoisactive/

Finally, if you want something to fire whenever a query waits for async_network_io, you can use a new tool called Extended Events. It's like debug points inside the SQL Server engine where you can make magic happen. Frankly, it's a little painful to use right now in 2008.