当前位置:   article > 正文

存储计划:自动kill掉死锁进程id_kill -segv id

kill -segv id
  1. CREATE PROCEDURE [dbo].[sp_who_lock1116] AS
  2. --exec sp_who_lock1116
  3. begin
  4. declare @spid int,@bl int,
  5. @intTransactionCountOnEntry int,
  6. @intRowcount int,
  7. @intCountProperties int,
  8. @intCounter int
  9. declare @sql varchar(1000)
  10. create table #tmp_lock_who(
  11. id int identity(1,1),
  12. spid smallint,
  13. bl smallint)
  14. if @@error<>0 return @@error
  15. insert into #tmp_lock_who(spid,bl)
  16. select 0,blocked
  17. from (select * from sysprocesses where blocked>0) a
  18. where not exists (select * from (select * from sysprocesses where blocked>0) b where a.blocked=spid)
  19. union select spid,blocked from sysprocesses where blocked>0
  20. if @@error<>0 return @@error
  21. --找到临时表的记录数
  22. select @intCountProperties=count(*),@intCounter=1
  23. from #tmp_lock_who
  24. if @@error<>0 return @@error
  25. if @intCountProperties=0
  26. select '现在没有阻塞信息' as message
  27. --循环开始
  28. while @intCounter<=@intCountProperties
  29. begin
  30. select @spid=spid,@bl=bl
  31. from #tmp_lock_who where id=@intCounter
  32. begin
  33. if @spid=0
  34. begin
  35. select '引起数据库死锁的是:'+cast(@bl as varchar(10))+'进程号,其执行的SQL语法如下'
  36. end
  37. else
  38. begin
  39. select '进程号spid:'+cast(@spid as varchar(10))+'被'+'进程号spid'+cast(@bl as varchar(10))+'阻塞,其执行的SQL语法如下'
  40. end
  41. DBCC inputbuffer(@bl)
  42. set @sql='kill '+cast(@bl as varchar(10))
  43. exec(@sql)
  44. end
  45. set @intCounter=@intCounter+1
  46. end
  47. drop table #tmp_lock_who
  48. return 0
  49. end

经常性的死锁,如果无法彻底解决的话,可建个计划定时执行以上存储过程

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/759744
推荐阅读
相关标签
  

闽ICP备14008679号