代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
MSSQL
】
建立 sp_blocker_pss80 預存程序
作者:
Dezai.CN
/ 发布于
2012/8/1
/
636
建立 sp_blocker_pss80 預存程序
use master GO if exists (select * from sysobjects where id = object_id('dbo.sp_blocker_pss80') and sysstat & 0xf = 4) drop procedure dbo.sp_blocker_pss80 GO create procedure dbo.sp_blocker_pss80 (@latch int = 0, @fast int = 1, @appname sysname='PSSDIAG') as --version 17SP3 if is_member('sysadmin')=0 begin print 'Must be a member of the sysadmin group in order to run this procedure' return end set nocount on SET LANGUAGE 'us_english' declare @spid varchar(6) declare @blocked varchar(6) declare @time datetime declare @time2 datetime declare @dbname nvarchar(128) declare @status sql_variant declare @useraccess sql_variant set @time = getdate() declare @probclients table(spid smallint, ecid smallint, blocked smallint, waittype binary(2), dbid smallint, ignore_app tinyint, primary key (blocked, spid, ecid)) insert @probclients select spid, ecid, blocked, waittype, dbid, case when convert(varchar(128),hostname) = @appname then 1 else 0 end from master.dbo.sysprocesses where blocked!=0 or waittype != 0x0000 if exists (select spid from @probclients where ignore_app != 1 or waittype != 0x020B) begin set @time2 = getdate() print '' print '8.2 Start time: ' + convert(varchar(26), @time, 121) + ' ' + convert(varchar(12), datediff(ms,@time,@time2)) insert @probclients select distinct blocked, 0, 0, 0x0000, 0, 0 from @probclients where blocked not in (select spid from @probclients) and blocked != 0 if (@fast = 1) begin print '' print 'SYSPROCESSES ' + ISNULL (@@servername,'(null)') + ' ' + str(@@microsoftversion) select spid, status, blocked, open_tran, waitresource, waittype, waittime, cmd, lastwaittype, cpu, physical_io, memusage, last_batch=convert(varchar(26), last_batch,121), login_time=convert(varchar(26), login_time,121),net_address, net_library, dbid, ecid, kpid, hostname, hostprocess, loginame, program_name, nt_domain, nt_username, uid, sid, sql_handle, stmt_start, stmt_end from master.dbo.sysprocesses where blocked!=0 or waittype != 0x0000 or spid in (select blocked from @probclients where blocked != 0) or spid in (select spid from @probclients where blocked != 0) print 'ESP ' + convert(varchar(12), datediff(ms,@time2,getdate())) print '' print 'SYSPROC FIRST PASS' select spid, ecid, waittype from @probclients where waittype != 0x0000 if exists(select blocked from @probclients where blocked != 0) begin print 'Blocking via locks at ' + convert(varchar(26), @time, 121) print '' print 'SPIDs at the head of blocking chains' select spid from @probclients where blocked = 0 and spid in (select blocked from @probclients where spid != 0) if @latch = 0 begin print 'SYSLOCKINFO' select @time2 = getdate() select spid = convert (smallint, req_spid), ecid = convert (smallint, req_ecid), rsc_dbid As dbid, rsc_objid As ObjId, rsc_indid As IndId, Type = case rsc_type when 1 then 'NUL' when 2 then 'DB' when 3 then 'FIL' when 4 then 'IDX' when 5 then 'TAB' when 6 then 'PAG' when 7 then 'KEY' when 8 then 'EXT' when 9 then 'RID' when 10 then 'APP' end, Resource = substring (rsc_text, 1, 16), Mode = case req_mode + 1 when 1 then NULL when 2 then 'Sch-S' when 3 then 'Sch-M' when 4 then 'S' when 5 then 'U' when 6 then 'X' when 7 then 'IS' when 8 then 'IU' when 9 then 'IX' when 10 then 'SIU' when 11 then 'SIX' when 12 then 'UIX' when 13 then 'BU' when 14 then 'RangeS-S' when 15 then 'RangeS-U' when 16 then 'RangeIn-Null' when 17 then 'RangeIn-S' when 18 then 'RangeIn-U' when 19 then 'RangeIn-X' when 20 then 'RangeX-S' when 21 then 'RangeX-U' when 22 then 'RangeX-X'end, Status = case req_status when 1 then 'GRANT' when 2 then 'CNVT' when 3 then 'WAIT' end, req_transactionID As TransID, req_transactionUOW As TransUOW from master.dbo.syslockinfo s, @probclients p where p.spid = s.req_spid print 'ESL ' + convert(varchar(12), datediff(ms,@time2,getdate())) end -- latch not set end else print 'No blocking via locks at ' + convert(varchar(26), @time, 121) print '' end -- fast set else begin -- Fast not set print '' print 'SYSPROCESSES ' + ISNULL (@@servername,'(null)') + ' ' + str(@@microsoftversion) select spid, status, blocked, open_tran, waitresource, waittype, waittime, cmd, lastwaittype, cpu, physical_io, memusage, last_batch=convert(varchar(26), last_batch,121), login_time=convert(varchar(26), login_time,121),net_address, net_library, dbid, ecid, kpid, hostname, hostprocess, loginame, program_name, nt_domain, nt_username, uid, sid, sql_handle, stmt_start, stmt_end from master.dbo.sysprocesses print 'ESP ' + convert(varchar(12), datediff(ms,@time2,getdate())) print '' print 'SYSPROC FIRST PASS' select spid, ecid, waittype from @probclients where waittype != 0x0000 if exists(select blocked from @probclients where blocked != 0) begin print 'Blocking via locks at ' + convert(varchar(26), @time, 121) print '' print 'SPIDs at the head of blocking chains' select spid from @probclients where blocked = 0 and spid in (select blocked from @probclients where spid != 0) if @latch = 0 begin print 'SYSLOCKINFO' select @time2 = getdate() select spid = convert (smallint, req_spid), ecid = convert (smallint, req_ecid), rsc_dbid As dbid, rsc_objid As ObjId, rsc_indid As IndId, Type = case rsc_type when 1 then 'NUL' when 2 then 'DB' when 3 then 'FIL' when 4 then 'IDX' when 5 then 'TAB' when 6 then 'PAG' when 7 then 'KEY' when 8 then 'EXT' when 9 then 'RID' when 10 then 'APP' end, Resource = substring (rsc_text, 1, 16), Mode = case req_mode + 1 when 1 then NULL when 2 then 'Sch-S' when 3 then 'Sch-M' when 4 then 'S' when 5 then 'U' when 6 then 'X' when 7 then 'IS' when 8 then 'IU' when 9 then 'IX' when 10 then 'SIU' when 11 then 'SIX' when 12 then 'UIX' when 13 then 'BU' when 14 then 'RangeS-S' when 15 then 'RangeS-U' when 16 then 'RangeIn-Null' when 17 then 'RangeIn-S' when 18 then 'RangeIn-U' when 19 then 'RangeIn-X' when 20 then 'RangeX-S' when 21 then 'RangeX-U' when 22 then 'RangeX-X'end, Status = case req_status when 1 then 'GRANT' when 2 then 'CNVT' when 3 then 'WAIT' end, req_transactionID As TransID, req_transactionUOW As TransUOW from master.dbo.syslockinfo print 'ESL ' + convert(varchar(12), datediff(ms,@time2,getdate())) end -- latch not set end else print 'No blocking via locks at ' + convert(varchar(26), @time, 121) print '' end -- Fast not set print 'DBCC SQLPERF(WAITSTATS)' dbcc sqlperf(waitstats) Print '' Print '*********************************************************************' Print 'Print out DBCC Input buffer for all blocked or blocking spids.' Print '*********************************************************************' declare ibuffer cursor fast_forward for select distinct cast (spid as varchar(6)) as spid from @probclients where (spid <> @@spid) and ((blocked!=0 or (waittype != 0x0000 and ignore_app = 0)) or spid in (select blocked from @probclients where blocked != 0)) open ibuffer fetch next from ibuffer into @spid while (@@fetch_status != -1) begin print '' print 'DBCC INPUTBUFFER FOR SPID ' + @spid exec ('dbcc inputbuffer (' + @spid + ')') fetch next from ibuffer into @spid end deallocate ibuffer Print '' Print '*******************************************************************************' Print 'Print out DBCC OPENTRAN for active databases for all blocked or blocking spids.' Print '*******************************************************************************' declare ibuffer cursor fast_forward for select distinct cast (dbid as varchar(6)) from @probclients where dbid != 0 open ibuffer fetch next from ibuffer into @spid while (@@fetch_status != -1) begin print '' set @dbname = db_name(@spid) set @status = DATABASEPROPERTYEX(@dbname,'Status') set @useraccess = DATABASEPROPERTYEX(@dbname,'UserAccess') print 'DBCC OPENTRAN FOR DBID ' + @spid + ' ['+ @dbname + ']' if @status = N'ONLINE' and @useraccess != N'SINGLE_USER' dbcc opentran(@dbname) else print 'Skipped: Status=' + convert(nvarchar(128),@status) + ' UserAccess=' + convert(nvarchar(128),@useraccess) print '' if @spid = '2' select @blocked = 'Y' fetch next from ibuffer into @spid end deallocate ibuffer if @blocked != 'Y' begin print '' print 'DBCC OPENTRAN FOR DBID 2 [tempdb]' dbcc opentran ('tempdb') end print 'End time: ' + convert(varchar(26), getdate(), 121) end -- All else print '8 No Waittypes: ' + convert(varchar(26), @time, 121) + ' ' + convert(varchar(12), datediff(ms,@time,getdate())) + ' ' + ISNULL (@@servername,'(null)') GO create procedure dbo.sp_blocker_pss80 (@latch int = 0, @fast int = 1, @appname sysname='PSSDIAG') as --version 17 if is_member('sysadmin')=0 begin print 'Must be a member of the sysadmin group in order to run this procedure' return end set nocount on declare @spid varchar(6) declare @blocked varchar(6) declare @time datetime declare @time2 datetime declare @dbname nvarchar(128) declare @status sql_variant declare @useraccess sql_variant set @time = getdate() declare @probclients table(spid smallint, ecid smallint, blocked smallint, waittype binary(2), dbid smallint, ignore_app tinyint, primary key (blocked, spid, ecid)) insert @probclients select spid, ecid, blocked, waittype, dbid, case when convert(varchar(128),hostname) = @appname then 1 else 0 end from master.dbo.sysprocesses where blocked!=0 or waittype != 0x0000 if exists (select spid from @probclients where ignore_app != 1 or waittype != 0x020B) begin set @time2 = getdate() print '' print '8 Start time: ' + convert(varchar(26), @time, 121) + ' ' + convert(varchar(12), datediff(ms,@time,@time2)) insert @probclients select distinct blocked, 0, 0, 0x0000, 0, 0 from @probclients where blocked not in (select spid from @probclients) and blocked != 0 if (@fast = 1) begin print '' print 'SYSPROCESSES ' + ISNULL (@@servername,'(null)') + ' ' + str(@@microsoftversion) select spid, status, blocked, open_tran, waitresource, waittype, waittime, cmd, lastwaittype, cpu, physical_io, memusage,last_batch=convert(varchar(26), last_batch,121), login_time=convert(varchar(26), login_time,121), net_address, net_library, dbid, ecid, kpid, hostname, hostprocess, loginame, program_name, nt_domain, nt_username, uid, sid from master.dbo.sysprocesses where blocked!=0 or waittype != 0x0000 or spid in (select blocked from @probclients where blocked != 0) or spid in (select spid from @probclients where waittype != 0x0000) print 'ESP ' + convert(varchar(12), datediff(ms,@time2,getdate())) print '' print 'SYSPROC FIRST PASS' select spid, ecid, waittype from @probclients where waittype != 0x0000 if exists(select blocked from @probclients where blocked != 0) begin print 'Blocking via locks at ' + convert(varchar(26), @time, 121) print '' print 'SPIDs at the head of blocking chains' select spid from @probclients where blocked = 0 and spid in (select blocked from @probclients where spid != 0) if @latch = 0 begin print 'SYSLOCKINFO' select @time2 = getdate() select spid = convert (smallint, req_spid), ecid = convert (smallint, req_ecid), rsc_dbid As dbid, rsc_objid As ObjId, rsc_indid As IndId, Type = case rsc_type when 1 then 'NUL' when 2 then 'DB' when 3 then 'FIL' when 4 then 'IDX' when 5 then 'TAB' when 6 then 'PAG' when 7 then 'KEY' when 8 then 'EXT' when 9 then 'RID' when 10 then 'APP' end, Resource = substring (rsc_text, 1, 16), Mode = case req_mode + 1 when 1 then NULL when 2 then 'Sch-S' when 3 then 'Sch-M' when 4 then 'S' when 5 then 'U' when 6 then 'X' when 7 then 'IS' when 8 then 'IU' when 9 then 'IX' when 10 then 'SIU' when 11 then 'SIX' when 12 then 'UIX' when 13 then 'BU' when 14 then 'RangeS-S' when 15 then 'RangeS-U' when 16 then 'RangeIn-Null' when 17 then 'RangeIn-S' when 18 then 'RangeIn-U' when 19 then 'RangeIn-X' when 20 then 'RangeX-S' when 21 then 'RangeX-U' when 22 then 'RangeX-X'end, Status = case req_status when 1 then 'GRANT' when 2 then 'CNVT' when 3 then 'WAIT' end, req_transactionID As TransID, req_transactionUOW As TransUOW from master.dbo.syslockinfo s, @probclients p where p.spid = s.req_spid print 'ESL ' + convert(varchar(12), datediff(ms,@time2,getdate())) end -- latch not set end else print 'No blocking via locks at ' + convert(varchar(26), @time, 121) print '' end -- fast set else begin -- Fast not set print '' print 'SYSPROCESSES ' + ISNULL (@@servername,'(null)') + ' ' + str(@@microsoftversion) select spid, status, blocked, open_tran, waitresource, waittype, waittime, cmd, lastwaittype, cpu, physical_io, memusage,last_batch=convert(varchar(26), last_batch,121), login_time=convert(varchar(26), login_time,121), net_address, net_library, dbid, ecid, kpid, hostname, hostprocess, loginame, program_name, nt_domain, nt_username, uid, sid from master.dbo.sysprocesses print 'ESP ' + convert(varchar(12), datediff(ms,@time2,getdate())) print '' print 'SYSPROC FIRST PASS' select spid, ecid, waittype from @probclients where waittype != 0x0000 if exists(select blocked from @probclients where blocked != 0) begin print 'Blocking via locks at ' + convert(varchar(26), @time, 121) print '' print 'SPIDs at the head of blocking chains' select spid from @probclients where blocked = 0 and spid in (select blocked from @probclients where spid != 0) if @latch = 0 begin print 'SYSLOCKINFO' select @time2 = getdate() select spid = convert (smallint, req_spid), ecid = convert (smallint, req_ecid), rsc_dbid As dbid, rsc_objid As ObjId, rsc_indid As IndId, Type = case rsc_type when 1 then 'NUL' when 2 then 'DB' when 3 then 'FIL' when 4 then 'IDX' when 5 then 'TAB' when 6 then 'PAG' when 7 then 'KEY' when 8 then 'EXT' when 9 then 'RID' when 10 then 'APP' end, Resource = substring (rsc_text, 1, 16), Mode = case req_mode + 1 when 1 then NULL when 2 then 'Sch-S' when 3 then 'Sch-M' when 4 then 'S' when 5 then 'U' when 6 then 'X' when 7 then 'IS' when 8 then 'IU' when 9 then 'IX' when 10 then 'SIU' when 11 then 'SIX' when 12 then 'UIX' when 13 then 'BU' when 14 then 'RangeS-S' when 15 then 'RangeS-U' when 16 then 'RangeIn-Null' when 17 then 'RangeIn-S' when 18 then 'RangeIn-U' when 19 then 'RangeIn-X' when 20 then 'RangeX-S' when 21 then 'RangeX-U' when 22 then 'RangeX-X'end, Status = case req_status when 1 then 'GRANT' when 2 then 'CNVT' when 3 then 'WAIT' end, req_transactionID As TransID, req_transactionUOW As TransUOW from master.dbo.syslockinfo print 'ESL ' + convert(varchar(12), datediff(ms,@time2,getdate())) end -- latch not set end else print 'No blocking via locks at ' + convert(varchar(26), @time, 121) print '' end -- Fast not set print 'DBCC SQLPERF(WAITSTATS)' dbcc sqlperf(waitstats) Print '' Print '*********************************************************************' Print 'Print out DBCC Input buffer for all blocked or blocking spids.' Print '*********************************************************************' declare ibuffer cursor fast_forward for select distinct cast (spid as varchar(6)) as spid from @probclients where (spid <> @@spid) and ((blocked!=0 or (waittype != 0x0000 and ignore_app = 0)) or spid in (select blocked from @probclients where blocked != 0)) open ibuffer fetch next from ibuffer into @spid while (@@fetch_status != -1) begin print '' print 'DBCC INPUTBUFFER FOR SPID ' + @spid exec ('dbcc inputbuffer (' + @spid + ')') fetch next from ibuffer into @spid end deallocate ibuffer Print '' Print '*******************************************************************************' Print 'Print out DBCC OPENTRAN for active databases for all blocked or blocking spids.' Print '*******************************************************************************' declare ibuffer cursor fast_forward for select distinct cast (dbid as varchar(6)) from @probclients where dbid != 0 open ibuffer fetch next from ibuffer into @spid while (@@fetch_status != -1) begin print '' set @dbname = db_name(@spid) set @status = DATABASEPROPERTYEX(@dbname,'Status') set @useraccess = DATABASEPROPERTYEX(@dbname,'UserAccess') print 'DBCC OPENTRAN FOR DBID ' + @spid + ' ['+ @dbname + ']' if @status = N'ONLINE' and @useraccess != N'SINGLE_USER' dbcc opentran(@dbname) else print 'Skipped: Status=' + convert(nvarchar(128),@status) + ' UserAccess=' + convert(nvarchar(128),@useraccess) print '' if @spid = '2' select @blocked = 'Y' fetch next from ibuffer into @spid end deallocate ibuffer if @blocked != 'Y' begin print '' print 'DBCC OPENTRAN FOR DBID 2 [tempdb]' dbcc opentran ('tempdb') end print 'End time: ' + convert(varchar(26), getdate(), 121) end -- All else print '8 No Waittypes: ' + convert(varchar(26), @time, 121) + ' ' + convert(varchar(12), datediff(ms,@time,getdate())) + ' ' + ISNULL (@@servername,'(null)') GO
试试其它关键字
建立
sp_blocker_pss80
預存程序
同语言下
.
SQL查询 多列合并成一行用逗号隔开
.
查看存储过程修改时间,最近执行时间
.
设置手动批量删除数据库相关进程
.
获取某个表中特定字段的所有字符串形式
.
SQL 如何去除重复的字符串
.
怎么去掉一个字段中的重复数据
.
String 去除空格 回车 换行 水平制表符
.
SQL查询和替换含有回车,空格,TAB
.
SQL SERVER 查询每日新增用户数量、次留数量
.
判断两个字符串是否存在相同的内容
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3