The application starts timing out, CPU on the SQL Server instance is low, and sys.dm_exec_requests fills with suspended sessions waiting on LCK_M_U, LCK_M_X, or LCK_M_S. Some callers give up with error 1222, Lock request time-out period exceeded. Almost always, the problem is not the queries that are waiting. It is one session at the top of the chain that holds locks and has not finished, often a connection that went quiet with a transaction still open. This guide shows how to find that head blocker on SQL Server 2019, 2022, and 2025 and Azure SQL Database, capture blocking after it ends, and stop it coming back.
- Follow
blocking_session_idup the chain to the session that blocks others but waits on nothing: the head blocker. - A head blocker with status
sleepingandopen_transaction_countabove 0 is an application that left a transaction open. It will not clear on its own. - Set
blocked process thresholdand captureblocked_process_reportwith Extended Events to see blocking that ended before you looked. No reports are produced by default. KILLrolls back the head blocker's whole transaction, and the rollback can take as long as the work did. Check the transaction's log use first.- RCSI stops readers and writers blocking each other. Optimized locking, available in SQL Server 2025 (off by default) and always on in Azure SQL Database, cuts writer blocking further.
Scope and review date: November 2026. This post covers SQL Server 2019, 2022, and 2025 and Azure SQL Database, with notes where Azure SQL Managed Instance differs. Queries, defaults, and permissions were checked against Microsoft's documentation, not run in a lab, and all output shown is illustrative.
What is blocking in SQL Server, and how is it different from a deadlock?
Blocking happens when one session holds a lock and another session asks for a conflicting lock on the same resource. Microsoft's guide to understanding and resolving SQL Server blocking calls this normal and by design. It becomes a problem when a session holds locks for a long time, or never releases them. Write locks are held until the transaction ends, so a statement that finished minutes ago still blocks others if its transaction is open.
A deadlock is a cycle: two sessions each wait for the other, and the lock monitor ends one as the victim. Plain blocking has no cycle and no automatic exit: the default LOCK_TIMEOUT of -1 means a blocked statement waits until the client gives up. Deadlocks get their own post.
-- Requests that are waiting right now, and who they wait on
SELECT session_id,
status,
blocking_session_id,
wait_type,
wait_time / 1000 AS wait_s,
wait_resource,
transaction_id
FROM sys.dm_exec_requests
WHERE blocking_session_id <> 0;Interpretation: every row is a victim, not a cause. wait_time is in milliseconds and covers the current wait only. A growing wait on the same wait_resource across runs means the request is stuck; a new resource means it is progressing.
How do I see which requests are blocked right now?
blocking_session_id in sys.dm_exec_requests is the ID of the session that blocks the request. A value of 0 or NULL means the request is not blocked or the blocker cannot be identified. Negative values have specific meanings:
| Value | Meaning |
|---|---|
-2 | The resource is owned by an orphaned distributed transaction |
-3 | The resource is owned by a deferred recovery transaction |
-4 | Latch owner could not be determined because of internal latch state transitions |
-5 | Latch owner is not tracked for this latch type; not a problem by itself |
Two details trip people up. sys.dm_exec_requests lists only executing sessions, so an idle session with an uncommitted transaction appears only in sys.dm_exec_sessions. And for a parallel query only the coordinator thread is shown; use sys.dm_os_waiting_tasks for each task.
On Azure SQL Database, run every query in this post in the user database itself, as Microsoft's Azure SQL Database blocking guide notes.
A typical blocking chain
Session 61 is idle with an open transaction; everything below it waits until 61 ends
Read the chain from the top: killing 74, 80, or 82 changes nothing while 61 holds its locks. Only the head blocker clears the chain.
How do I find the head blocker?
The head blocker is a session that other sessions wait on, directly or indirectly, while it waits on nothing itself. This recursive query starts from every such session in sys.dm_exec_sessions, so idle head blockers are included, and walks down the chain. It follows the same approach as the head-blocker script in Microsoft's blocking guide, with fewer columns.
WITH s AS (
SELECT es.session_id,
er.blocking_session_id,
es.status AS session_status,
es.open_transaction_count,
er.wait_type,
er.wait_time,
er.wait_resource,
es.program_name
FROM sys.dm_exec_sessions AS es
LEFT JOIN sys.dm_exec_requests AS er
ON er.session_id = es.session_id
),
chain AS (
SELECT session_id AS head_blocker, session_id, 0 AS lvl
FROM s
WHERE ISNULL(blocking_session_id, 0) = 0
AND session_id IN (SELECT blocking_session_id FROM s
WHERE blocking_session_id > 0)
UNION ALL
SELECT c.head_blocker, s.session_id, c.lvl + 1
FROM s
JOIN chain AS c
ON s.blocking_session_id = c.session_id
AND s.session_id <> c.session_id
)
SELECT c.head_blocker,
REPLICATE(' ', c.lvl) + CAST(c.session_id AS varchar(10)) AS tree,
s.session_status,
s.open_transaction_count AS open_tran,
s.wait_type,
s.wait_time / 1000 AS wait_s,
s.wait_resource,
s.program_name,
LEFT(ib.event_info, 200) AS last_input
FROM chain AS c
JOIN s ON s.session_id = c.session_id
OUTER APPLY sys.dm_exec_input_buffer(c.session_id, NULL) AS ib
ORDER BY c.head_blocker, c.lvl
OPTION (MAXRECURSION 100);Interpretation: level 0 rows are the sessions to act on. For a sleeping head blocker, last_input is the last batch the client sent; the statement that took the locks may have run earlier in the transaction. No level 0 row means a deadlock about to be broken, or a negative blocking_session_id such as -2.
The head-blocker query during an incident
Illustrative output: one sleeping session with an open transaction at the head of a three-level chain
Reading it: session 61 waits on nothing and holds an open transaction while sleeping. That is the application-side open transaction pattern, and it will not clear by itself.
Can sp_WhoIsActive find block leaders?
Yes. Adam Machanic's free sp_WhoIsActive has a @find_block_leaders parameter that walks the blocking chain and counts how many sessions each session blocks, all the way down. Sorting by that count puts the head blockers first.
EXEC dbo.sp_WhoIsActive
@find_block_leaders = 1,
@get_locks = 1,
@get_plans = 1,
@sort_order = '[blocked_session_count] DESC';Interpretation: rows with a high blocked_session_count and no blocking_session_id are the head blockers. @get_locks = 1 adds the locks each request holds as XML. The default @show_sleeping_spids = 1 includes sleeping sessions only when they have an open transaction, which is the case you care about.
What lock is the head blocker holding, and on which table?
Once you have the session ID, sys.dm_tran_locks shows what it holds. Run this in the affected database; it can return a lot of rows on a busy server, so filter by session.
DECLARE @head int = 61;
SELECT tl.resource_type,
tl.request_mode,
tl.request_status,
COUNT(*) AS lock_count,
OBJECT_NAME(COALESCE(p.object_id,
CASE WHEN tl.resource_type = 'OBJECT'
THEN CAST(tl.resource_associated_entity_id AS int) END)) AS object_name
FROM sys.dm_tran_locks AS tl
LEFT JOIN sys.partitions AS p
ON p.hobt_id = tl.resource_associated_entity_id
WHERE tl.request_session_id = @head
AND tl.resource_database_id = DB_ID()
GROUP BY tl.resource_type, tl.request_mode, tl.request_status,
p.object_id, tl.resource_associated_entity_id
ORDER BY lock_count DESC;Interpretation: many KEY or RID locks in mode X are row changes held by an open transaction. An OBJECT lock in mode X or S with few row locks points to lock escalation; an intent mode (IX, IS, IU) is normal. With optimized locking, a writer may hold one XACT lock instead.
On the waiting side, a key wait resource such as KEY: 5:72057594044284928 (3300a4f361aa) holds a database ID and a hobt_id; join the hobt_id to sys.partitions and sys.indexes to name the table and index.
Finally, check how old and how large the head blocker's transaction is. Size matters later, because it predicts how long a rollback will take.
SELECT st.session_id,
es.status,
es.open_transaction_count,
at.transaction_begin_time,
DATEDIFF(SECOND, at.transaction_begin_time, SYSDATETIME()) AS tran_age_s,
es.last_request_end_time,
dt.database_transaction_log_bytes_used / 1048576.0 AS log_used_mb
FROM sys.dm_tran_session_transactions AS st
JOIN sys.dm_tran_active_transactions AS at
ON at.transaction_id = st.transaction_id
JOIN sys.dm_exec_sessions AS es
ON es.session_id = st.session_id
LEFT JOIN sys.dm_tran_database_transactions AS dt
ON dt.transaction_id = st.transaction_id
AND dt.database_id = DB_ID()
WHERE st.is_user_transaction = 1
ORDER BY at.transaction_begin_time;Interpretation: an old transaction on a session whose last_request_end_time is also old belongs to a client that stopped mid-transaction. log_used_mb roughly shows how much a rollback must undo.
How do I capture blocking that already ended?
Most blocking incidents are over by the time someone looks. On SQL Server, the blocked process threshold option makes the engine emit a blocked process report for every task blocked longer than the threshold, in seconds. It accepts 0 to 86,400, where 0 disables it, and by default no reports are produced. It is an advanced option and takes effect without a restart. Detection is best effort, so reports can arrive a few seconds late.
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'blocked process threshold', 15;
RECONFIGURE;Interpretation: the event fires once per interval for each blocked task, so very low values flood the target when many tasks are blocked. Start around 10 to 20 seconds and adjust.
The reports go nowhere until something captures them. An Extended Events session on sqlserver.blocked_process_report writes them to a file:
CREATE EVENT SESSION [blocked_process] ON SERVER
ADD EVENT sqlserver.blocked_process_report
ADD TARGET package0.event_file (
SET filename = N'D:\XE\blocked_process.xel',
max_file_size = 64,
max_rollover_files = 8)
WITH (EVENT_RETENTION_MODE = ALLOW_SINGLE_EVENT_LOSS,
MAX_DISPATCH_LATENCY = 30 SECONDS,
STARTUP_STATE = ON);
ALTER EVENT SESSION [blocked_process] ON SERVER STATE = START;Interpretation: STARTUP_STATE = ON brings the session back after a restart. On Linux, use a path the mssql user can write. Each event holds an XML report with a blocked-process node and a blocking-process node, including each side's input buffer, login, host, and wait time.
SELECT x.ev.value('(event/@timestamp)[1]', 'datetime2') AS utc_time,
x.ev.query('(event/data[@name="blocked_process"]/value/blocked-process-report)[1]') AS report
FROM (
SELECT CAST(event_data AS xml) AS ev
FROM sys.fn_xe_file_target_read_file(N'D:\XE\blocked_process*.xel', NULL, NULL, NULL)
) AS x
ORDER BY utc_time DESC;Interpretation: one long block shows up as a run of reports with the same blocking session. Group by the blocking process's input buffer to find the code path behind most of your blocking.
Server options such as blocked process threshold are set with sp_configure on SQL Server. Microsoft's Azure SQL Database blocking guide instead uses DMV snapshots plus database-scoped Extended Events sessions (attention, RPC and batch events). A practical substitute is to run the head-blocker query on a schedule and store the rows with a timestamp.
What usually causes long blocking in SQL Server?
Microsoft's blocking guide lists six scenarios. In production, four causes account for most of what you will see: open transactions left by the application, lock escalation, writes without a supporting index, and long reports under locking read committed.
Open transactions from the application
When a client hits a query timeout or cancels, SQL Server ends the current batch but does not roll back the transaction. Microsoft's guide is explicit that this is the application's job. With connection pooling the problem gets worse: the connection goes back to the pool with the transaction open and is not reset until it is reused. Two defences are recommended: run IF @@TRANCOUNT > 0 ROLLBACK TRAN in every error handler, and set XACT_ABORT so a run-time error rolls the transaction back.
CREATE OR ALTER PROCEDURE dbo.ShipOrder @OrderID int
AS
BEGIN
SET XACT_ABORT ON; -- a run-time error rolls back the transaction
BEGIN TRY
BEGIN TRANSACTION;
UPDATE dbo.Orders SET Status = 'Shipped' WHERE OrderID = @OrderID;
COMMIT TRANSACTION;
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
THROW;
END CATCH;
END;Interpretation: with XACT_ABORT on, statements after an error do not run, which can change the flow of older code, so test it. A client timeout is an attention event, not an error, so the client's error path still needs the rollback.
Lock escalation
According to the lock escalation troubleshooting article, escalation is triggered when a single statement acquires more than 5,000 locks on one table or index, or when lock memory crosses 40 percent of its limit. It always goes to a table lock, never a page lock. Escalation is not the cause of most blocking, so confirm it first with an Extended Events session on the lock_escalation event: no events means escalation is not your problem, and its escalated_lock_count and escalation_cause fields show which threshold was reached. The preferred fix is to split the work so each statement stays well under 5,000 locks:
DECLARE @done bit = 0;
WHILE (@done = 0)
BEGIN
DELETE TOP (1000) FROM dbo.AuditLog WHERE LogDate < '20250101';
IF @@ROWCOUNT < 1000 SET @done = 1;
END;Interpretation: each batch is a short transaction, so other sessions get in between batches. LOCK_ESCALATION = DISABLE and trace flags 1211 and 1224 exist, but Microsoft does not recommend them: lock memory can run out and statements fail with error 1204.
Missing indexes and long reports
Without optimized locking, an UPDATE or DELETE checks its predicate row by row by taking an update (U) lock on each row it reads. A write with no index on its WHERE clause scans the table, so it touches, and briefly locks, far more rows than it changes. That raises its chance of colliding with other sessions and of reaching the escalation threshold. Non-SARGable predicates such as WHERE CONVERT(int, col) = @x have the same effect even when an index exists. The wait stats playbook separates lock waits from I/O and CPU waits, and the Query Store regression guide helps when a write that used to seek starts scanning.
Long reports cause the opposite problem. Under locking read committed (RCSI off), a SELECT takes shared locks as it reads, waits behind writers on its path, and holds up writers on the rows it is reading. A lookup using PREFETCH can even read at repeatable read and escalate to a shared table lock.
How do RCSI and optimized locking reduce blocking?
With READ_COMMITTED_SNAPSHOT on, read committed uses row versioning: a SELECT reads the last committed version as of the statement start and takes no row or page locks. Readers stop blocking writers and writers stop blocking readers. Writers still block writers. RCSI is off by default in SQL Server and Azure SQL Managed Instance and on by default in Azure SQL Database, according to Microsoft's transaction locking and row versioning guide.
Optimized locking targets writer blocking. Transaction ID (TID) locking releases each row lock once the row is modified and holds one X lock on the transaction until commit, so escalation becomes much less likely. Lock after qualification (LAQ), which needs RCSI, checks an UPDATE or DELETE predicate against the latest committed row version without taking U locks, so writers that touch different rows stop blocking each other.
SELECT name,
is_read_committed_snapshot_on,
snapshot_isolation_state_desc,
is_accelerated_database_recovery_on,
DATABASEPROPERTYEX(name, 'IsOptimizedLockingOn') AS optimized_locking
FROM sys.databases
WHERE database_id > 4;Interpretation: optimized_locking is 1 when enabled, 0 when disabled, and NULL where the feature does not exist, as on SQL Server 2019 and 2022. It needs ADR on first.
Blocking-related defaults by platform
Switch platforms to see what is on by default
SQL Server 2019 and 2022
| Feature | SQL Server 2019 and 2022 |
|---|---|
| RCSI | Off by default; enable per database |
| Accelerated database recovery | Available per database (added in 2019) |
| Optimized locking | Not available |
| Blocked process report | sp_configure 'blocked process threshold', off by default |
SQL Server 2025
| Feature | SQL Server 2025 |
|---|---|
| RCSI | Off by default; enable per database |
| Accelerated database recovery | Available per database; required for optimized locking |
| Optimized locking | Available, off by default; enable per database |
| Blocked process report | sp_configure 'blocked process threshold', off by default |
Azure SQL Database
| Feature | Azure SQL Database |
|---|---|
| RCSI | On by default for new databases |
| Accelerated database recovery | Always on |
| Optimized locking | Always on |
| Blocked process report | Not used in Microsoft's Azure guide; capture DMV snapshots and XE instead |
Managed Instance: optimized locking is always on with the SQL Server 2025 or Always-up-to-date update policy and not available with the SQL Server 2022 policy. RCSI is off by default, as on SQL Server.
On SQL Server 2025, turning both on looks like this. READ_COMMITTED_SNAPSHOT needs to be the only connection, so WITH ROLLBACK IMMEDIATE rolls back everyone else: use a maintenance window.
ALTER DATABASE [Sales] SET READ_COMMITTED_SNAPSHOT ON WITH ROLLBACK IMMEDIATE;
ALTER DATABASE [Sales] SET ACCELERATED_DATABASE_RECOVERY = ON; -- 2019 and later
ALTER DATABASE [Sales] SET OPTIMIZED_LOCKING = ON; -- 2025 onlyInterpretation: row versioning adds up to 14 bytes per row, and versions live in tempdb, or in the persistent version store when ADR is on, so watch space. Code that relies on reads blocking, such as claiming queue rows, needs a READCOMMITTEDLOCK or UPDLOCK hint. With optimized locking, writer blocking shows up as LCK_M_S_XACT_MODIFY and LCK_M_S_XACT_READ waits, so update alerts. The SQL Server 2025 features guide covers LAQ's edge cases.
Should I KILL the head blocker?
Sometimes, but treat KILL as starting a rollback, not pressing stop. It rolls back the whole open transaction, and a change that ran for an hour can take as long to undo, while the session keeps blocking as KILLED/ROLLBACK. Restarting the instance does not help, because recovery must do the same rollback. With accelerated database recovery on, long rollbacks are rare.
Killing a head blocker safely
Six steps; steps 5 and 6 are past the point of no return
-
Confirm the head blocker twice
Rerun the query a few seconds later. If the head keeps changing, you have a slow-query problem, not a stuck session.
-
Identify the owner
Check host, program, and login, and read the last batch. The owner may be able to commit or roll back.
SELECT host_name, program_name, login_name FROM sys.dm_exec_sessions WHERE session_id = 61; DBCC INPUTBUFFER(61); -
Estimate the rollback
Use the open-transactions query: transaction age and log used. A large write without ADR means a long rollback that keeps blocking.
-
Save the evidence
Copy the head-blocker output and lock summary into the ticket. After the kill they are gone.
-
Kill the session
Rollback startsThe client gets an error and its transaction is rolled back. You cannot kill your own session or system processes.
KILL 61; -
Watch the rollback, then recheck
RollbackUse WITH STATUSONLY; repeating KILL could hit a new session that reuses the ID. Then rerun the head-blocker query.
KILL 61 WITH STATUSONLY;
Point of no return: once step 5 runs, the rollback must finish. If step 3 shows a very large transaction, asking the owner to commit may clear the chain faster.
SQL Server needs ALTER ANY CONNECTION (in sysadmin and processadmin); Azure SQL Database needs KILL DATABASE CONNECTION. For an orphaned distributed transaction (-2), take the GUID from request_owner_guid in sys.dm_tran_locks and run KILL '<UOW>'.
How do I stop a statement from waiting forever?
SET LOCK_TIMEOUT sets how many milliseconds a statement waits for a lock. The default -1 waits forever; 0 does not wait. On timeout the statement fails with error 1222, Lock request time-out period exceeded, but its transaction is not rolled back, so the caller must retry or roll back.
SET LOCK_TIMEOUT 5000; -- wait at most 5 seconds for any lock
BEGIN TRY
BEGIN TRANSACTION;
ALTER TABLE dbo.Orders ADD Channel varchar(20) NULL;
COMMIT TRANSACTION;
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
IF ERROR_NUMBER() = 1222
PRINT 'Blocked for 5 s; retry later.';
ELSE
THROW;
END CATCH;Interpretation: this suits deploys and maintenance jobs: the schema change gives up instead of waiting indefinitely in the chain. The setting lasts for the rest of the connection, and CREATE, ALTER, and DROP DATABASE ignore it. SELECT @@LOCK_TIMEOUT; shows the current value.
If the application does not trap error 1222, its transaction stays open after the cancelled statement, and that session becomes the next head blocker.
Frequently asked questions
How do I find the head blocker in SQL Server?
Join sys.dm_exec_sessions to sys.dm_exec_requests and look for a session that other sessions list in blocking_session_id but whose own blocking_session_id is 0. Include sessions with no current request, because the head blocker is often sleeping with an open transaction. sp_WhoIsActive with @find_block_leaders = 1 gives the same answer.
Does KILL roll back the transaction in SQL Server?
Yes. KILL ends the session and rolls back its open transaction. The rollback can take as long as the original work, and the session keeps its locks until it finishes. Use KILL with WITH STATUSONLY to see progress. Restarting the instance does not skip it; recovery has to finish the rollback.
Does read committed snapshot isolation stop all blocking?
No. RCSI stops readers and writers blocking each other, because reads use row versions instead of shared locks. Two sessions writing the same rows still block, and so do schema changes and queries with locking hints or stricter isolation levels.
Is optimized locking on by default?
It is always on in Azure SQL Database and in Azure SQL Managed Instance with the 2025 or Always-up-to-date update policy. In SQL Server 2025 it is off by default and enabled per database after accelerated database recovery. SQL Server 2022 and earlier do not have it. The lock after qualification part also needs RCSI.
Key takeaways
- Find the head blocker from
sys.dm_exec_sessions, not justsys.dm_exec_requests, because the usual culprit is a sleeping session with an open transaction. - Turn on
blocked process thresholdand ablocked_process_reportExtended Events session now, so the next incident leaves evidence. - Fix the cause in the application:
SET XACT_ABORT ON, a rollback in every error path, short transactions, and batched large writes. - Enable RCSI after testing, and optimized locking on SQL Server 2025, then update alerts for the new
XACTwait types. - Before a
KILL, check the transaction's size and owner; the rollback cannot be skipped once it starts.
Find and fix SQL Server blocking with JusDB
JusDB's SQL Server performance tuning team can review your blocking chains and wait statistics, trace recurring head blockers back to the code paths that leave transactions open, and help plan the move to RCSI or optimized locking with a test and rollback step.
Bring your SQL Server version or Azure SQL tier, recent blocked process reports or head-blocker captures, and the isolation settings of your main databases. Your team approves every production change.
Related reading
- SQL Server Deadlock Troubleshooting: Find, Read and Fix Error 1205
- SQL Server High CPU Usage: Find the Query and Fix the Cause
- SQL Server wait stats: a diagnostic playbook for slow queries
- SQL Server Query Store: identifying and fixing plan regressions
- SQL Server 2025 for DBAs: features that change day-to-day operations
- Microsoft Learn: Understand and resolve SQL Server blocking problems