日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

数据库死锁查询及处理

發(fā)布時(shí)間:2025/5/22 数据库 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 数据库死锁查询及处理 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

創(chuàng)建存儲(chǔ)過程sp_who_lock,查詢死鎖的進(jìn)程

create procedure sp_who_lock WITH ENCRYPTION as begindeclare @spid int,@bl int,@intTransactionCountOnEntry int,@intRowcount int,@intCountProperties int,@intCounter intcreate table #tmp_lock_who (id int identity(1,1),spid smallint,bl smallint)IF @@ERROR <> 0 RETURN @@ERRORinsert into #tmp_lock_who(spid,bl) select spid,blocked from sysprocesses where blocked <> 0IF @@ERROR <> 0 RETURN @@ERROR-- 找到臨時(shí)表的記錄數(shù)select @intCountProperties = Count(1),@intCounter = 1 from #tmp_lock_whoIF @@ERROR <> 0 RETURN @@ERRORif @intCountProperties=0select '現(xiàn)在沒有阻塞和死鎖信息' as 'message'-- 循環(huán)開始while @intCounter = @intCountPropertiesbegin-- 取第一條記錄select @spid = spid,@bl = blfrom #tmp_lock_who where Id = @intCounterbeginselect '進(jìn)程號(hào)SPID:'+ CAST(@spid AS VARCHAR(10))+ ''+ '進(jìn)程號(hào)SPID:'+ CAST(@bl AS VARCHAR(10)) +'阻塞,其當(dāng)前進(jìn)程執(zhí)行的SQL語法如下'DBCC INPUTBUFFER (@bl )end-- 循環(huán)指針下移set @intCounter = @intCounter + 1enddrop table #tmp_lock_whoreturn 0 end View Code

下面我們自己構(gòu)建一個(gè)死鎖進(jìn)程:

BEGIN TRANSACTION--開始事務(wù)update T_Users set UserName='00000' where UserId='123'WAITFOR DELAY '01:00'; --指定1點(diǎn)執(zhí)行 View Code

執(zhí)行查詢語句:

select * from T_Users where UserId='123'

這時(shí)會(huì)發(fā)現(xiàn)一直在執(zhí)行查詢。得不到查詢結(jié)果,我們執(zhí)行第一步創(chuàng)建的存儲(chǔ)過程sp_who_lock.得到結(jié)果如下:

此時(shí)我們只需執(zhí)行

kill 53

然后再執(zhí)行查詢語句就可以得到結(jié)果了。

?

轉(zhuǎn)載于:https://www.cnblogs.com/XiaoZone/p/9511815.html

總結(jié)

以上是生活随笔為你收集整理的数据库死锁查询及处理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。