SQL Flow Field Guide

Trace a live blocking chain

Identify blocked requests, their blocker session, current wait evidence, and the SQL text available for each session.

What you are trying to do

Use a SQL Server sandbox with two SSMS sessions and permission to read the required server DMVs. On SQL Server 2022 and later, the required performance-state permission differs from earlier versions. Use only a disposable lab row.

Work through it

  1. In Session A, begin a transaction and update the instructor-seeded lab row. Leave the transaction open. Do not use a real application table.
  2. In Session B, issue a statement that needs the same row. Leave it waiting while the observer query runs.
  3. Read blocking_session_id, wait_type, wait_time, and wait_resource for the blocked request. Match its session ID to the blocker row. A blocker can be sleeping and have no active request row.
  4. Read the SQL text and open transaction count as clues. Record the head blocker and wait resource. Do not kill a session or change server configuration as part of this lab.
  5. Commit or roll back Session A, then confirm Session B completes. Repeat with a short transaction and compare the duration of the wait.
  6. Review Microsoft's blocking troubleshooting guidance and the version-specific DMV permissions before accessing a real instance. Blocking troubleshooting · sys.dm_exec_requests · sys.dm_exec_input_buffer

Check your work

While the lab lock is held, Session B shows the blocker session ID and a current wait. After Session A ends its transaction, the blocked request completes. The evidence identifies the head blocker without assuming every wait is a lock wait.

Practice SQL

Open in SQL Flow
SELECT s.session_id, s.status AS session_status, s.open_transaction_count, r.status AS request_status, r.blocking_session_id, r.wait_type, r.wait_time, r.wait_resource, inputbuffer.event_info AS recent_sql
FROM sys.dm_exec_sessions AS s
LEFT JOIN sys.dm_exec_requests AS r ON r.session_id = s.session_id
OUTER APPLY sys.dm_exec_input_buffer(s.session_id, NULL) AS inputbuffer
WHERE s.is_user_process = 1
  AND (r.blocking_session_id > 0 OR EXISTS (SELECT 1 FROM sys.dm_exec_requests AS blocked WHERE blocked.blocking_session_id = s.session_id))
ORDER BY s.session_id;

Knowledge check

Commands in this lesson

Next lesson Read a deadlock graph and explain the victim