Back to results for “SQL Queries”
SQL Server › Isolation & Locking

How would you diagnose and resolve a blocking problem where many queries are waiting on a single long running transaction?

Advanced

Answer

You would query dynamic management views like sys.dm_exec_requests and sys.dm_tran_locks to identify the specific session holding the blocking locks, examine what that session is currently doing, and then either wait for it to complete, optimize the underlying query causing the delay, or in an emergency, safely terminate the blocking session if appropriate.
SELECT blocking_session_id, session_id, wait_type, wait_time
FROM sys.dm_exec_requests
WHERE blocking_session_id <> 0;
Real-world example A database administrator quickly identifies a poorly optimized report that had been holding locks for several minutes, blocking dozens of other users, and works with the reporting team to optimize the underlying query and prevent it from happening again.

Common follow-ups: How do you safely terminate a blocking session without causing data problems?;What tools provide a visual representation of blocking chains?