Wednesday 25 May 2016

How To Find The Lead Blocker Among All Blocking Sessions


You can use below query to get all blocking session 

Select * from sys.sysprocesses where blocked <> 0

Some times you may confuse which session is the lead blocker, So you can use the below script to find out which is the lead blocker


select loginame, cpu, memusage, physical_io, * 
  from  master..sysprocesses a
 where  exists ( select b.*
     from master..sysprocesses b
    where b.blocked > 0 and
   b.blocked = a.spid ) and not
 exists ( select b.*
     from master..sysprocesses b
    where b.blocked > 0 and
   b.spid = a.spid ) 
order by spid

No comments:

Post a Comment