-
syslocks
Is there a way to determine how many processes are directly or indirectly
blocked by a process?
I know the following query will give all processes which are blocking others but not blocked themselves:
select * from master..sysprocesses
where blocked = 0
and spid in (select blocked from master..sysprocesses where blocked>0)
However I would like to go further and determine how many processes are held up by the one process.
Is this possible in a query rather than a stored procedure?
-
syslocks (reply)
Try this SQL ( it is for 7.X ) run this in master though
SET NOCount on
exec sp_blockcnt
SELECT GETDATE(), @@servername + CHAR(10)
declare @blocker_spid smallint
declare @i_buff_string char(30)
set nocount on
select spid, blocked, hostname=substring (hostname, 1, 10),
progname=substring(program_name, 1, 10), cmd=substring(cmd, 1, 10),
status, physical_io, waittype
into #blk from master..sysprocesses (nolock) where blocked != 0
delete from #blk
where blocked in (select spid from #blk)
select "Blocking spid" = spid, loginame=substring(suser_name(suid),1,10),
hostname=substring (hostname, 1, 10), progname=substring(program_name, 1,
10),
cmd=substring(cmd, 1, 10), status, physical_io, waittype
from master..sysprocesses (nolock)
where spid in
(select blocked from #blk)
-- get root spid
declare blk_cursor CURSOR FOR SELECT blocked from #blk
open blk_cursor
fetch next from blk_cursor into @blocker_spid
while (@@fetch_status <> -1)
begin
select @i_buff_string = ("dbcc inputbuffer (" +
convert(char(6),@blocker_spid) +""
select "Below is input buffer for this blocking spid: ", @blocker_spid
select ""
exec (@i_buff_string)
fetch next from blk_cursor into @blocker_spid
end
deallocate blk_cursor
select spid, syslocks.type, locktype=name, table_id=id, page, dbid
from syslocks, master.dbo.spt_values v
where syslocks.type=v.number
and v.type='L'
and (syslocks.type & 256)=256
and spid in (select blocked from #blk)
order by spid
drop table #blk
select "Total users ",count(*) from sysprocesses (nolock)
select "Blocked users ",count(*) from sysprocesses (nolock) where blocked <> 0
print ""
/* Get blocked spids */
Print "Get blocked spids..."
go
select a.spid,
a.status,
a.hostname,
a.blocked "blocking spid",
a.login_time,
a.last_batch
from sysprocesses a (nolock)
where a.blocked <> 0
print ""
go
------------
Simon at 10/28/99 4:18:33 AM
Is there a way to determine how many processes are directly or indirectly
blocked by a process?
I know the following query will give all processes which are blocking others but not blocked themselves:
select * from master..sysprocesses
where blocked = 0
and spid in (select blocked from master..sysprocesses where blocked>0)
However I would like to go further and determine how many processes are held up by the one process.
Is this possible in a query rather than a stored procedure?
-
syslocks (reply)
If you are using SQL 7, another way to check out the blocking is using Enterprise Manager. Goto Management->Current Activity->Locks/Process ID. You will see who is blocker and who are being blocked.
------------
Simon at 10/28/99 4:18:33 AM
Is there a way to determine how many processes are directly or indirectly
blocked by a process?
I know the following query will give all processes which are blocking others but not blocked themselves:
select * from master..sysprocesses
where blocked = 0
and spid in (select blocked from master..sysprocesses where blocked>0)
However I would like to go further and determine how many processes are held up by the one process.
Is this possible in a query rather than a stored procedure?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|