November 6, 2012 at 12:34 am
Hello All
I'm trying to find the cause of blocking on my system
I've found the following script to check for queries most often blocked
SELECT TOP 10
[Average Time Blocked] = (total_elapsed_time - total_worker_time) / qs.execution_count
,[Total Time Blocked] = total_elapsed_time - total_worker_time
,[Execution count] = qs.execution_count
,[Individual Query] = SUBSTRING (qt.text,qs.statement_start_offset/2,
(CASE WHEN qs.statement_end_offset = -1
THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2
ELSE qs.statement_end_offset END - qs.statement_start_offset)/2)
,[Parent Query] = qt.text
,DatabaseName = DB_NAME(qt.dbid)
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) as qt
ORDER BY [Average Time Blocked] DESC;
If the elapsed_time is less more than the worker_time, does that automatically mean that blocking has occured? Surely there are other factors that would prevent the Query from getting the CPU that it needs.
Am I correct here or is this script a definitive way to check for queries being blocked?
Any Ideas?
Thanks Guys
November 6, 2012 at 5:03 am
you can use sp_who2 to check blocking.
November 6, 2012 at 9:19 am
I'm trying to find the cause of blocking on my system
If you are truly trying to find the cause of the blocking that is occurring on your system, then I would suggest that you look into using the blocked process report. I have used it many times in the past to track down the source of blocking in our production systems. You first have to configure an option to enable it using sp_configure and the duration of the blocked event to capture. Then you run a profiler trace to capture the blocking events. We run ours as a background trace that is kicked off every morning from a scheduled job. It generates an XML output that can be used to track the source of the blocking.
Here's a SQLServerCentral article with the detailed information on how to set it up:
http://www.sqlservercentral.com/blogs/aschenbrenner/2011/12/01/the-blocked-process-report/
And here's a link where you can find code that will interpret the results of the blocked process report more easily:
http://michaeljswart.com/2011/04/a-new-way-to-examine-blocked-process-reports/
November 6, 2012 at 12:56 pm
Check out Adam Machanic's WhoIsActive procedure. Its fantastic for this sort of thing and comes with excellent documentation on multiple uses of it
http://sqlblog.com/blogs/adam_machanic/archive/2012/03/22/released-who-is-active-v11-11.aspx
Hope there isn't any issues with linking it here. If there is then feel free to delete the post mods.
November 6, 2012 at 1:53 pm
Animal Magic (11/6/2012)
Check out Adam Machanic's WhoIsActive procedure. Its fantastic for this sort of thing and comes with excellent documentation on multiple uses of ithttp://sqlblog.com/blogs/adam_machanic/archive/2012/03/22/released-who-is-active-v11-11.aspx
Hope there isn't any issues with linking it here. If there is then feel free to delete the post mods.
We use that as well and it is a very handy SP. The advantage of the sp_blocked_process_report_viewer is that it gives the the actual blocked process chain with the lead blocker at the top of the chain and the XML output to determine what is causing the blocking. We've customized the original version of the stored procedure to parse out the PAGE and OBJECT data as well so you can easily determine what is being locked that is causing the blocking to occur.
November 6, 2012 at 1:55 pm
Chapter 6
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
November 6, 2012 at 11:38 pm
GilaMonster (11/6/2012)
http://www.simple-talk.com/books/sql-books/troubleshooting-sql-server-a-guide-for-the-accidental-dba/Chapter 6
Thanks Gail
Besides finding the cause of blocking on my system, is it safe to say that if I find queries in my cache where the elapsed_time is more than the worker_time, this doesn't necessarily mean that it's because of blocking?
Thanks
November 6, 2012 at 11:55 pm
Yup. There are plenty of waits other than lock waits
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
November 7, 2012 at 12:06 am
GilaMonster (11/6/2012)
Yup. There are plenty of waits other than lock waits
Thanks
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply