blocking SQL Server

Published on by LakshmiSaahul,Dhana Royal

What is blocking and how would you troubleshoot it?

Blocking occurs when two or more rows are locked by one SQL connection and a second connection to the SQL server requires a conflicting on lock on those rows. This results in the second connection to wait until the first lock is released.

Troubleshooting blocking:
• SQL scripts can be written that constantly monitor the state of locking and blocking on SQL Server
• The common blocking scenarios must be identified and resolved.
• The scripts output must be checked constantly,
• The SQL profilers data must be examined regularly to detect blocking.

How to identify blocking in SQL Server 2005 and 2008

There are many ways to find out the details of the Blocking . Please see below query to check blocking in sql database

1) select * from sys.sysprocessess where blocked<>0
2) using SP_who

            USE Master
            GO
            EXEC sp_who2
            GO

3) using DMVs

USE Master
GO
SELECT * 
FROM sys.dm_exec_requests
WHERE blocking_session_id <> 0;
GO
and 

USE Master
GO
SELECT session_id, wait_duration_ms, wait_type, blocking_session_id 
FROM sys.dm_os_waiting_tasks 
WHERE blocking_session_id <> 0
GO
Advertising
To be informed of the latest articles, subscribe:
Comment on this post