SQL 死鎖程序查詢

2022-07-15 08:24:08 字數 2077 閱讀 5883

use

master

godeclare

@spid

int,@bl

intdeclare s_cur cursor

forselect

0,blocked

from (select

*from sysprocesses where blocked>

0) a

where

notexists(select

*from (select

*from sysprocesses where blocked>

0) b

where a.blocked=

spid)

union

select spid,blocked from sysprocesses where blocked>

0open

s_cur

fetch

next

from s_cur into

@spid,@bl

while

@@fetch_status=0

begin

if@spid=0

select

'引起資料庫死鎖的是: '+

cast(@bl

asvarchar(10)) +

'程序號,其執行的sql語法如下

'else

select

'程序號spid:'+

cast(@spid

asvarchar(10))+'被

'+'程序號spid:'+

cast(@bl

asvarchar(10)) +

'阻塞,其當前程序執行的sql語法如下

'dbcc inputbuffer (@bl

)fetch

next

from s_cur into

@spid,@bl

endclose

s_cur

deallocate

s_cur

--死鎖查詢

select

標誌,程序id

=spid,執行緒id=kpid,塊程序id=blocked,資料庫id=

dbid,

資料庫名

=db_name(dbid),使用者id=uid,使用者名稱=loginame,累計cpu時間=

cpu,

登陸時間

=login_time,開啟事務數=open_tran, 程序狀態=

status,

工作站名

=hostname,應用程式名=program_name,工作站程序id=

hostprocess,

網域名稱=nt_domain,網絡卡位址=

net_address

from

(select 標誌=

'死鎖的程序',

spid,kpid,a.blocked,dbid,uid,loginame,cpu,login_time,open_tran,

status,hostname,program_name,hostprocess,nt_domain,net_address,

s1=a.spid,s2=

0from master..sysprocesses a join

(select blocked from master..sysprocesses group

byblocked

)b on a.spid=b.blocked where a.blocked=

0union

allselect

'|_犧牲品_>',

spid,kpid,blocked,dbid,uid,loginame,cpu,login_time,open_tran,

status,hostname,program_name,hostprocess,nt_domain,net_address,

s1=blocked,s2=

1from master..sysprocesses a where blocked<>

0)a

order

by s1,s2

mysql 查詢死鎖sql

1.檢視程序 show processlist 2.檢視是否鎖表 show open tables where in use 0 3.檢視正在鎖的事務 select from information schema.innodb locks 4.檢視等待鎖的事務 select from informa...

Oracle使用者查詢死鎖程序

oracle使用者查詢死鎖程序的sql select s.sid,s.serial decode t.type,mr media recovery rt redo thread un user name tx transaction tm dml ul pl sql user lock dx dis...

ORACLE查詢並解除死鎖程序

oracle查詢並解除死鎖程序 1 查詢死鎖程序 select rule v lock.sid,decode v lock.type,mr media recovery rt redo thread un user name tx transaction tm dml ul pl sql user ...