Get a blocking list for the objects & indexes using DMV

Published 13 June 07 07:44 AM | SQL Master 

Yet another help from DMV I would like to share here, say on a SQL Instance you are getting low-level I/O and blocking intermittently. For the I/O issues using SYSMON (PERFMON) is ideal to get more information during the busy times and low-usage times (for memory too WhatUNeed2Check post).

For the blocking in SQL 2000 & 70 version you can take help of sp_blocker_pss80 stored procedure or by running PROFILER (Server side trace is ideal)  refer to this KBA224453 in this case. Similarly in SQL 2005 you can still use PROFILER and look for the Blocked Process Report event class that will obtain information to capture the task that has been blocked for more than a specified amount of time, for more information on this event class visit BOL too.

Also I would like to copy reply from a post that I have replied on SSP: If you are observing the blocking for sp_cursorclose(), then these are stored procedures are called by the SQL Server ODBC Driver or OLE DB Provider. You can see they are server-side cursors. By default within ADO, a server-side cursor occurs if the application specifies a keyset, dynamic or static cursor type on a Recordset object. If you are using ADO then test and set the CacheSize property of the Recordset object to a value that gets the result set rows back in a small number or a single call to sp_cursorfetch.

Additionally that doesn't mean cursors are always causing blocking in this case, you may be aware database & system locks dynamically occur all the time and not always they are necessarily bad things. If you finding few deadlocks during any transactions then check for process info using SP_WHO2 and look for blocking & blockedby columns. IN general the performance or blocking is affected for the applications due to the long running transactions.

Coming to using DMVs in SQL 2005 you could get more information such as list of objects (tables & SPs) and indexes that has most contention during the blocking. Using sys.dm_db_index_operational_stats DMV with following TSQL get such list :

--** Change the current database context to relevant database

declare @dbid int
select @dbid = db_id()
Select dbid=database_id, objectname=object_name(s.object_id)
 , indexname=i.name, i.index_id 
 , [block %]=cast (100.0 * row_lock_wait_count / (1 + row_lock_count) as numeric(15,2))
 , row_lock_wait_in_ms
 , [avg row lock waits in ms]=cast (1.0 * row_lock_wait_in_ms / (1 + row_lock_wait_count) as numeric(15,2))
from sys.dm_db_index_operational_stats (@dbid, NULL, NULL, NULL) s
 ,sys.indexes i
where objectproperty(s.object_id,'IsUserTable') = 1
and i.object_id = s.object_id
and i.index_id = s.index_id
order by row_lock_wait_count desc

(this script is supplied by MSFT, I've modified as per my requirement)

Additionally I would like to remind the following 2 blogs in this site that helps to identify the relevant query & fine tune the performance:

IdentifySlowQueries & DetectTableFragmentation 

Comments

# SSQA - SqlServer-QA.net said on June 13, 2007 3:58 PM:

Yet another help from DMV I would like to share here, say on a SQL Instance you are getting low-level

# thomas said on June 14, 2007 2:38 AM:

When I click on the 2 links at the bottom I am getting this error message

Access Denied: Post Permission Denied

Either this forum does not exist or you are not allowed to post.

# SQL Master said on June 15, 2007 12:45 AM:

Thanks Thomas, I have corrected the links now.

# Log Buffer #49: a Carnival of the Vanities for DBAs « Coskans Approach to Oracle said on June 15, 2007 5:50 AM:

PingBack from http://coskan.wordpress.com/2007/06/15/log-buffer-49-a-carnival-of-the-vanities-for-dbas/

# SQL Server Security, Performance & Tuning (SSQA.net) said on September 24, 2007 7:41 AM:

As a DBA you must be aware that slow or long running queries can contribute to excessive resource consumption

# SQL Server Storage Engine & Tools (SSQA.net) said on March 17, 2008 3:01 AM:

DMV - has got very special place for DBAs since the inception of SQL Server 2005. In this case one of

Anonymous comments are disabled

About SQL Master

**__________________________________** SQL Server MVP, Sr. DBA & industry expert. - Knowledge is of two kinds. We know a subject ourselves or we know where we can find information on it. It is also a power and you will gain by sharing it.

Search

Go

This Blog

«June 2007»
SMTWTFS
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

Syndication