%3CLINGO-SUB%20id%3D%22lingo-sub-1431932%22%20slang%3D%22en-US%22%3EWho%20is%20blocking%20me%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1431932%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20title%3D%22sp_who%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fsystem-stored-procedures%2Fsp-who-transact-sql%3Fview%3Dsql-server-ver15%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Esp_who%3C%2FA%3E%26nbsp%3Bhas%20always%20been%20a%20handy%20tool%20at%20the%20disposal%20of%20every%20DBA%20to%20quickly%20retrieve%20information%20about%20processes%2C%20sessions%20and%20users%20in%20SQL%20Server.%3C%2FP%3E%0A%3CP%3EOne%20of%20the%20typical%20uses%20was%20to%20run%20it%20to%20identify%20which%20processes%20are%20blocked%20by%20other%20executions%20and%2C%20more%20importantly%2C%20who%20is%20the%20blocker.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhile%26nbsp%3B%3CA%20title%3D%22Workload%20Management%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsynapse-analytics%2Fsql-data-warehouse%2Fsql-data-warehouse-workload-management%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EWorkload%20Management%3C%2FA%3E%26nbsp%3Boffers%20the%20ability%20to%20define%20importance%20and%20priority%20of%20running%20workloads%2C%20there%20could%20still%20be%20the%20chance%20of%20overlapping%20executions%2C%20especially%20if%20the%20SQL%20Pool%20instance%20is%20%22open%22%20to%20users%20for%20ad-hoc%20query%20execution.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIt%20is%20usually%20easy%20to%20determine%20if%20your%20session%20is%20blocked%2C%20but%20it%20is%20not%20as%20easy%20to%20identify%20which%20session%20is%20the%20blocker.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EA%26nbsp%3B%20query%20like%20the%20following%20can%20help%20you%20identify%20blocked%20and%20blocking%20processes%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3E--%20blocked%20session%20info%0AWITH%20blocked_sessions%20(login_name%2C%20blocked_session%2C%20state%2C%20type%2C%20command%2C%20object)%0AAS%0A(%0ASELECT%20%0A%20%20%20%20sessions.login_name%2C%0A%20%20%20%20blocked.session_id%20as%20blocked_session%2C%20%0A%20%20%20%20blocked.state%20%2C%20%0A%20%20%20%20blocked.type%2C%0A%20%20%20%20requests.command%2C%0A%20%20%20%20blocked.object_name%0A%20%20%20%20FROM%20sys.dm_pdw_waits%20blocked%0A%20%20%20%20JOIN%20sys.dm_pdw_exec_requests%20requests%0A%20%20%20%20%20%20%20%20ON%20blocked.request_id%20%3D%20requests.request_id%0A%20%20%20%20JOIN%20sys.dm_pdw_exec_sessions%20sessions%0A%20%20%20%20%20%20%20%20ON%20blocked.session_id%20%3D%20sessions.session_id%0A%20%20%20%20WHERE%20blocked.state%20%26lt%3B%26gt%3B%20'Granted'%0A%20%20%20%20)%0A--merging%20with%20blocking%20session%20info%0ASELECT%20%0A%20%20%20%20blocked_sessions.login_name%20as%20blocked_user%2C%0A%20%20%20%20blocked_sessions.blocked_session%20as%20blocked_session%2C%0A%20%20%20%20blocked_sessions.state%20as%20blocked_state%2C%0A%20%20%20%20blocked_sessions.type%20as%20blocked_type%2C%0A%20%20%20%20blocked_sessions.command%20as%20blocked_command%2C%0A%20%20%20%20sessions.login_name%20as%20blocking_user%2C%0A%20%20%20%20blocking.session_id%20as%20blocking_session%2C%20%0A%20%20%20%20blocking.state%20as%20blocking_state%2C%20%0A%20%20%20%20blocking.type%20as%20blocking_type%2C%0A%20%20%20%20requests.command%20as%20blocking_command%0A%20%20%20%20FROM%20sys.dm_pdw_waits%20blocking%0A%20%20%20%20JOIN%20blocked_sessions%20%0A%20%20%20%20%20%20%20%20ON%20blocked_sessions.object%20%3D%20blocking.object_name%0A%20%20%20%20JOIN%20sys.dm_pdw_exec_requests%20requests%0A%20%20%20%20%20%20%20%20ON%20blocking.request_id%20%3D%20requests.request_id%0A%20%20%20%20JOIN%20sys.dm_pdw_exec_sessions%20sessions%0A%20%20%20%20%20%20%20%20ON%20blocking.session_id%20%3D%20sessions.session_id%0A%20%20%20%20WHERE%20blocking.state%20%3D%20'Granted'%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EEnjoy!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1431932%22%20slang%3D%22en-US%22%3E%3CP%3EDetermine%20which%20session%20and%20processes%20are%20blocking%20your%20queries.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1431932%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESynapse%20Support%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E

sp_who has always been a handy tool at the disposal of every DBA to quickly retrieve information about processes, sessions and users in SQL Server.

One of the typical uses was to run it to identify which processes are blocked by other executions and, more importantly, who is the blocker.

 

While Workload Management offers the ability to define importance and priority of running workloads, there could still be the chance of overlapping executions, especially if the SQL Pool instance is "open" to users for ad-hoc query execution. 

 

It is usually easy to determine if your session is blocked, but it is not as easy to identify which session is the blocker. 

 

A  query like the following can help you identify blocked and blocking processes:

 

-- blocked session info
WITH blocked_sessions (login_name, blocked_session, state, type, command, object)
AS
(
SELECT 
    sessions.login_name,
    blocked.session_id as blocked_session, 
    blocked.state , 
    blocked.type,
    requests.command,
    blocked.object_name
    FROM sys.dm_pdw_waits blocked
    JOIN sys.dm_pdw_exec_requests requests
        ON blocked.request_id = requests.request_id
    JOIN sys.dm_pdw_exec_sessions sessions
        ON blocked.session_id = sessions.session_id
    WHERE blocked.state <> 'Granted'
    )
--merging with blocking session info
SELECT 
    blocked_sessions.login_name as blocked_user,
    blocked_sessions.blocked_session as blocked_session,
    blocked_sessions.state as blocked_state,
    blocked_sessions.type as blocked_type,
    blocked_sessions.command as blocked_command,
    sessions.login_name as blocking_user,
    blocking.session_id as blocking_session, 
    blocking.state as blocking_state, 
    blocking.type as blocking_type,
    requests.command as blocking_command
    FROM sys.dm_pdw_waits blocking
    JOIN blocked_sessions 
        ON blocked_sessions.object = blocking.object_name
    JOIN sys.dm_pdw_exec_requests requests
        ON blocking.request_id = requests.request_id
    JOIN sys.dm_pdw_exec_sessions sessions
        ON blocking.session_id = sessions.session_id
    WHERE blocking.state = 'Granted'

 

Enjoy!