Search the Blog

Monday, September 12, 2022

SQL Server DMV to get the blocker query

 SELECT session_id, command, blocking_session_id, wait_type, wait_time, wait_resource, t.TEXT

FROM sys.dm_exec_requests 

CROSS apply sys.dm_exec_sql_text(sql_handle) AS t

WHERE session_id > 50 

AND blocking_session_id > 0

UNION

SELECT session_id, '', '', '', '', '', t.TEXT

FROM sys.dm_exec_connections 

CROSS apply sys.dm_exec_sql_text(most_recent_sql_handle) AS t

WHERE session_id IN (SELECT blocking_session_id 

                    FROM sys.dm_exec_requests 

                    WHERE blocking_session_id > 0)

No comments:

Post a Comment

Translate