How to Find and Fix Blocking in SQL Server

SQL Server 4 min readUpdated Oct 29, 2026
2 views0 comments

One slow query is annoying. A pile of sessions all waiting on one forgotten transaction can stop an entire application. This guide shows how to see who is blocking whom in SQL Server, find the session at the root of the chain and fix the problem without making things worse.

What blocking actually is

Blocking happens when one session holds a lock that another session needs. The second session simply waits. This is normal for a few milliseconds. It becomes a problem when a transaction stays open for seconds or minutes and a queue builds up behind it.

Do not confuse blocking with a deadlock. In a deadlock two sessions wait for each other and SQL Server kills one of them automatically. Blocking never resolves on its own until the blocker finishes.

Step 1: See who is waiting

This query lists every request that is currently blocked, how long it has waited and what it was trying to run:

SELECT  r.session_id,
        r.blocking_session_id,
        r.wait_type,
        r.wait_time / 1000.0 AS wait_seconds,
        DB_NAME(r.database_id) AS database_name,
        s.login_name,
        s.host_name,
        t.text AS running_sql
FROM    sys.dm_exec_requests AS r
JOIN    sys.dm_exec_sessions AS s ON s.session_id = r.session_id
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS t
WHERE   r.blocking_session_id <> 0
ORDER BY r.wait_time DESC;

The column blocking_session_id tells you which session is in the way. A wait_type starting with LCK_M_ confirms a lock wait.

Step 2: Find the head blocker

Blocking often forms a chain: A blocks B, B blocks C. Fixing C or B achieves nothing. You want the session at the top, which blocks others but is not blocked itself:

SELECT DISTINCT blocking_session_id AS head_blocker
FROM   sys.dm_exec_requests
WHERE  blocking_session_id <> 0
  AND  blocking_session_id NOT IN (SELECT session_id
                                   FROM   sys.dm_exec_requests
                                   WHERE  blocking_session_id <> 0);

Step 3: See what the blocker is doing

The head blocker is frequently sleeping: it finished its statement but never committed, so it does not appear in sys.dm_exec_requests. Look at its last statement and its open transaction instead (replace 55 with your session id):

SELECT c.session_id, t.text AS last_sql
FROM   sys.dm_exec_connections AS c
CROSS APPLY sys.dm_exec_sql_text(c.most_recent_sql_handle) AS t
WHERE  c.session_id = 55;

SELECT s.session_id, s.login_name, s.host_name, s.program_name,
       s.open_transaction_count, s.last_request_end_time
FROM   sys.dm_exec_sessions AS s
WHERE  s.session_id = 55;

A session with open_transaction_count > 0 and an old last_request_end_time is the classic culprit: an application or a person in Management Studio ran BEGIN TRAN and walked away.

Step 4: Resolve it

  1. Ask first. If it is a person or a known job, let them commit or roll back.
  2. Kill only when you must. KILL 55; forces a rollback of everything that session did. A large transaction can take as long to roll back as it took to run, and the locks stay held during the rollback.
  3. Check progress of a rollback with KILL 55 WITH STATUSONLY;

Never kill system sessions (session id below 50) and never kill a session you do not understand on a production server without telling its owner.

How to prevent it

  • Keep transactions short. Do the slow work (calling an API, waiting for user input) outside the transaction.
  • Index the filter columns. A scan locks far more rows than a seek.
  • Consider row versioning. With read committed snapshot isolation, readers stop blocking on writers:
ALTER DATABASE YourDatabase
SET READ_COMMITTED_SNAPSHOT ON
WITH ROLLBACK IMMEDIATE;

Test this in a non-production copy first: it changes how reads behave and increases tempdb usage.

Quick checklist

  1. List blocked requests (step 1).
  2. Identify the head blocker (step 2).
  3. Read its last statement and open transaction count (step 3).
  4. Contact the owner, commit or roll back, kill as the last resort (step 4).
  5. Fix the root cause: shorter transactions, better indexes, row versioning.
Did you find this helpful?Tap the heart to let us know. It takes one second and no account.

More tutorials like this

Leave a Comment

Your email address will not be published. Required fields are marked *

Bigland Network IT

Practical tutorials for people who run, build and fix things: operating systems, databases, development, networking and security.

Topics

More

Site

© 2026 Bigland Network. All rights reserved.Always test commands on a non-production system first.
Scroll to Top