Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Blocked Queries Expand / Collapse
Author
Message
Posted Tuesday, November 06, 2012 12:34 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, April 17, 2014 7:44 AM
Points: 1,371, Visits: 2,597
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
Post #1381414
Posted Tuesday, November 06, 2012 5:03 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 7:45 AM
Points: 2,508, Visits: 3,647
you can use sp_who2 to check blocking.
Post #1381505
Posted Tuesday, November 06, 2012 9:19 AM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Tuesday, November 19, 2013 8:15 AM
Points: 653, Visits: 1,428

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/
Post #1381626
Posted Tuesday, November 06, 2012 12:56 PM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Thursday, March 27, 2014 2:29 PM
Points: 990, Visits: 13,439
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.
Post #1381695
Posted Tuesday, November 06, 2012 1:53 PM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Tuesday, November 19, 2013 8:15 AM
Points: 653, Visits: 1,428
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 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.


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.

Post #1381706
Posted Tuesday, November 06, 2012 1:55 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 7:05 AM
Points: 41,532, Visits: 34,449
http://www.simple-talk.com/books/sql-books/troubleshooting-sql-server-a-guide-for-the-accidental-dba/
Chapter 6



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1381707
Posted Tuesday, November 06, 2012 11:38 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, April 17, 2014 7:44 AM
Points: 1,371, Visits: 2,597


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
Post #1381798
Posted Tuesday, November 06, 2012 11:55 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 7:05 AM
Points: 41,532, Visits: 34,449
Yup. There are plenty of waits other than lock waits


Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1381802
Posted Wednesday, November 07, 2012 12:06 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, April 17, 2014 7:44 AM
Points: 1,371, Visits: 2,597
GilaMonster (11/6/2012)
Yup. There are plenty of waits other than lock waits


Thanks

Post #1381806
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse