SQL Server Running Requests and Blocking Chain
Shows active requests, wait types, blocking sessions and the running statement together. The first diagnostic query to run during a slowdown.
SELECT r.session_id, r.blocking_session_id, r.status, r.command,
r.wait_type, r.wait_time AS wait_ms,
r.cpu_time, r.logical_reads,
DB_NAME(r.database_id) AS db_name,
s.login_name, s.host_name,
SUBSTRING(t.text, (r.statement_start_offset/2)+1,
((CASE r.statement_end_offset WHEN -1 THEN DATALENGTH(t.text)
ELSE r.statement_end_offset END - r.statement_start_offset)/2)+1) AS running_statement
FROM sys.dm_exec_requests r
JOIN sys.dm_exec_sessions s ON s.session_id = r.session_id
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) t
WHERE r.session_id <> @@SPID
AND s.is_user_process = 1
ORDER BY r.blocking_session_id DESC, r.wait_time DESC;Verify in a staging environment prior to running in production. This is a read-only diagnostic query; it does not acquire exclusive locks.
- This script is designed for read-only diagnostics; it does not alter schema or modify data directly.
- Prior to executing on production systems under high load, verify the target database version (Min. Version: 2012).
- Exercise caution with mutating actions (e.g., terminating sessions or dropping indexes) referenced in the notes section.
Engineering Triad: Related Runbooks & Incident Response
Which production incidents and emergency drills execute this script as a diagnosis step?
SQL Server Blocking Chain: Find and Resolve the Head Blocker
Finds the head blocker, detects the open transaction and ends it safely. Covers RCSI and threshold settings to prevent recurrence.
SQL Server Deadlock Investigation: From system_health Graph to Root Cause
Analyzes error 1205 using the deadlock graph, distinguishes victim from the lock cycle and prevents recurrence through access-order and index fixes.
Other SQLSERVER Diagnostic Scripts
View All (100)Top CPU-Consuming Queries in SQL Server
Lists the top 20 queries by total and average CPU time from the plan cache. Pinpoints the source of CPU pressure at query level.
SQL Server Missing Index Recommendations (Missing Index DMVs)
Ranks the optimizer's missing index suggestions by estimated benefit. Merge them with existing indexes before applying.
SQL Server Index Fragmentation with Rebuild/Reorganize Advice
Measures fragmentation on large indexes and recommends rebuild or reorganize. Lets you plan maintenance windows without wasted work.
SQL Server Data and Log File Size, Free Space and Autogrowth
Shows file size, used and free space, and growth settings. Used for capacity planning and catching bad autogrowth configs.