블로킹(락) 체인 찾기
SQL Server세션명령어
SELECT r.session_id AS waiting_spid,
r.blocking_session_id AS blocking_spid,
r.wait_type,
r.wait_time / 1000.0 AS wait_sec,
r.status, r.command,
DB_NAME(r.database_id) AS db,
t.text AS waiting_query
FROM sys.dm_exec_requests r
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) t
WHERE r.blocking_session_id <> 0
ORDER BY r.wait_time DESC;
-- To find the head (root) blocker of the chain, look for the SPID whose
-- own blocking_session_id is not set (it is not blocked itself).하는 일
대기 중인 세션과 이를 블로킹하는 세션을 대기 시간 및 실행 쿼리와 함께 나열하여 락 체인을 보이게 한다.
사용 시점
"애플리케이션이 멈춘다 / 타임아웃된다"는 불만이 있을 때 락 경합의 원인을 찾기 위해.
주의
루트 블로커(누구에게도 블로킹되지 않지만 다른 세션을 블로킹하는 SPID)를 종료하기 전에 업무 담당자와 확인한다. 조회 전용이며 위험 없음.