国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

處理死鎖

2024-07-21 02:08:04
字體:
來源:轉載
供稿:網友



use master --必須在master數據庫中創建
go

if exists (select * from dbo.sysobjects where id = object_id(n'[dbo].[p_lockinfo]') and objectproperty(id, n'isprocedure') = 1)
drop procedure [dbo].[p_lockinfo]
go

/*--處理死鎖

 查看當前進程,或死鎖進程,并能自動殺掉死進程

 因為是針對死的,所以如果有死鎖進程,只能查看死鎖進程
 當然,你可以通過參數控制,不管有沒有死鎖,都只查看死鎖進程

 感謝: caiyunxia,jiangopen 兩位提供的參考信息

--鄒建 2004.4--*/

/*--調用示例

 exec p_lockinfo
--*/
create proc p_lockinfo
@kill_lock_spid bit=1,  --是否殺掉死鎖的進程,1 殺掉, 0 僅顯示
@show_spid_if_nolock bit=1 --如果沒有死鎖的進程,是否顯示正常進程信息,1 顯示,0 不顯示
as
declare @count int,@s nvarchar(1000),@i int
select id=identity(int,1,1),標志,
 進程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
into #t 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=0
 from master..sysprocesses a join (
  select blocked from master..sysprocesses group by blocked
  )b on a.spid=b.blocked where a.blocked=0
 union all
 select '|_犧牲品_>',
  spid,kpid,blocked,dbid,uid,loginame,cpu,login_time,open_tran,
  status,hostname,program_name,hostprocess,nt_domain,net_address,
  s1=blocked,s2=1
 from master..sysprocesses a where blocked<>0
)a order by s1,s2

select @[email protected]@rowcount,@i=1

if @count=0 and @show_spid_if_nolock=1
begin
 insert #t
 select 標志='正常的進程',
  spid,kpid,blocked,dbid,db_name(dbid),uid,loginame,cpu,login_time,
  open_tran,status,hostname,program_name,hostprocess,nt_domain,net_address
 from master..sysprocesses
 set @[email protected]@rowcount
end

if @count>0
begin
 create table #t1(id int identity(1,1),a nvarchar(30),b int,eventinfo nvarchar(255))
 if @kill_lock_spid=1
 begin
  declare @spid varchar(10),@標志 varchar(10)
  while @i<[email protected]
  begin
   select @spid=進程id,@標志=標志 from #t where [email protected]
   insert #t1 exec('dbcc inputbuffer('[email protected]+')')
   if @標志='死鎖的進程' exec('kill '[email protected])
   set @[email protected]+1
  end
 end
 else
  while @i<[email protected]
  begin
   select @s='dbcc inputbuffer('+cast(進程id as varchar)+')' from #t where [email protected]
   insert #t1 exec(@s)
   set @[email protected]+1
  end
 select a.*,進程的sql語句=b.eventinfo
 from #t a join #t1 b on a.id=b.id
end
go


 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 浪卡子县| 大关县| 西华县| 河北省| 股票| 化德县| 武强县| 久治县| 黄平县| 阜新市| 东城区| 荣昌县| 吴川市| 合江县| 大新县| 光山县| 曲沃县| 白山市| 台南市| 天气| 东乌珠穆沁旗| 济南市| 丹阳市| 景洪市| 新建县| 平度市| 蕉岭县| 邮箱| 扶绥县| 白水县| 丘北县| 壤塘县| 昌平区| 呈贡县| 酉阳| 汤阴县| 孝昌县| 阿拉善左旗| 阜城县| 陆良县| 古田县|