SBO进程阻塞的检查和解决办法
2011-09-19 13:04
423 查看
create procedure sp_who_lock
as
begin
declare @spid int,@bl int,
@intTransactionCountOnEntry int,
@intRowcount int,
@intCountProperties int,
@intCounter int
create table #tmp_lock_who (
id int identity(1,1),
spid smallint,
bl smallint)
IF @@ERROR<>0 RETURN @@ERROR
insert into #tmp_lock_who(spid,bl) select 0 ,blocked
from (select * from sysprocesses where blocked>0 ) a
where not exists(select * from (select * from sysprocesses where blocked>0 ) b
where a.blocked=spid)
union select spid,blocked from sysprocesses where blocked>0
IF @@ERROR<>0 RETURN @@ERROR
-- 找到临时表的记录数
select @intCountProperties = Count(*),@intCounter = 1
from #tmp_lock_who
IF @@ERROR<>0 RETURN @@ERROR
if @intCountProperties=0
select '现在没有阻塞信息' as message
-- 循环开始
while @intCounter <= @intCountProperties
begin
-- 取第一条记录
select @spid = spid,@bl = bl
from #tmp_lock_who where Id = @intCounter
begin
if @spid =0
select '引起数据库阻塞的是: '+ CAST(@bl AS VARCHAR(10)) + '进程号,其执行的SQL语法如下'
else
select '进程号SPID:'+ CAST(@spid AS VARCHAR(10))+ '被' + '进程号SPID:'+ CAST(@bl AS VARCHAR(10)) +'阻塞,其当前进程执行的SQL语法如下'
DBCC INPUTBUFFER (@bl )
end
-- 循环指针下移
set @intCounter = @intCounter + 1
end
drop table #tmp_lock_who
return 0
end
GO
--结束SQL阻塞的进程%%%%%%%%%%%%%%%%%%%%%%
create procedure sp_Kill_lockProcess
as
begin
SET NOCOUNT ON
declare @spid int,@bl int,
@intTransactionCountOnEntry int,
@intRowcount int,
@intCountProperties int,
@intCounter int,
@sSql nvarchar (200)
create table #tmp_lock_who (
id int identity(1,1),
spid smallint,
bl smallint)
IF @@ERROR<>0 RETURN @@ERROR
insert into #tmp_lock_who(spid,bl)
select 0 ,blocked
from
(select * from sysprocesses where blocked>0 ) a
where not exists
(
select * from (select * from sysprocesses where blocked>0 ) b
where a.blocked=spid
)
union select spid,blocked from sysprocesses where blocked>0
IF @@ERROR<>0 RETURN @@ERROR
-- 找到临时表的记录数
select @intCountProperties = Count(*),@intCounter = 1
from #tmp_lock_who
IF @@ERROR<>0 RETURN @@ERROR
while @intCounter <= @intCountProperties
begin
-- 取第一条记录
select @spid = spid,@bl = bl
from #tmp_lock_who where Id = @intCounter
begin
if @spid =0
begin
set @sSql='kill ' + CAST(@bl AS VARCHAR(10))
exec sp_executesql @sSql
end
end
-- 循环指针下移
set @intCounter = @intCounter + 1
end
drop table #tmp_lock_who
SET NOCOUNT OFF
return 0
end
GO本文出自 “阚山” 博客,请务必保留此出处http://kanshan.blog.51cto.com/111574/668292
as
begin
declare @spid int,@bl int,
@intTransactionCountOnEntry int,
@intRowcount int,
@intCountProperties int,
@intCounter int
create table #tmp_lock_who (
id int identity(1,1),
spid smallint,
bl smallint)
IF @@ERROR<>0 RETURN @@ERROR
insert into #tmp_lock_who(spid,bl) select 0 ,blocked
from (select * from sysprocesses where blocked>0 ) a
where not exists(select * from (select * from sysprocesses where blocked>0 ) b
where a.blocked=spid)
union select spid,blocked from sysprocesses where blocked>0
IF @@ERROR<>0 RETURN @@ERROR
-- 找到临时表的记录数
select @intCountProperties = Count(*),@intCounter = 1
from #tmp_lock_who
IF @@ERROR<>0 RETURN @@ERROR
if @intCountProperties=0
select '现在没有阻塞信息' as message
-- 循环开始
while @intCounter <= @intCountProperties
begin
-- 取第一条记录
select @spid = spid,@bl = bl
from #tmp_lock_who where Id = @intCounter
begin
if @spid =0
select '引起数据库阻塞的是: '+ CAST(@bl AS VARCHAR(10)) + '进程号,其执行的SQL语法如下'
else
select '进程号SPID:'+ CAST(@spid AS VARCHAR(10))+ '被' + '进程号SPID:'+ CAST(@bl AS VARCHAR(10)) +'阻塞,其当前进程执行的SQL语法如下'
DBCC INPUTBUFFER (@bl )
end
-- 循环指针下移
set @intCounter = @intCounter + 1
end
drop table #tmp_lock_who
return 0
end
GO
--结束SQL阻塞的进程%%%%%%%%%%%%%%%%%%%%%%
create procedure sp_Kill_lockProcess
as
begin
SET NOCOUNT ON
declare @spid int,@bl int,
@intTransactionCountOnEntry int,
@intRowcount int,
@intCountProperties int,
@intCounter int,
@sSql nvarchar (200)
create table #tmp_lock_who (
id int identity(1,1),
spid smallint,
bl smallint)
IF @@ERROR<>0 RETURN @@ERROR
insert into #tmp_lock_who(spid,bl)
select 0 ,blocked
from
(select * from sysprocesses where blocked>0 ) a
where not exists
(
select * from (select * from sysprocesses where blocked>0 ) b
where a.blocked=spid
)
union select spid,blocked from sysprocesses where blocked>0
IF @@ERROR<>0 RETURN @@ERROR
-- 找到临时表的记录数
select @intCountProperties = Count(*),@intCounter = 1
from #tmp_lock_who
IF @@ERROR<>0 RETURN @@ERROR
while @intCounter <= @intCountProperties
begin
-- 取第一条记录
select @spid = spid,@bl = bl
from #tmp_lock_who where Id = @intCounter
begin
if @spid =0
begin
set @sSql='kill ' + CAST(@bl AS VARCHAR(10))
exec sp_executesql @sSql
end
end
-- 循环指针下移
set @intCounter = @intCounter + 1
end
drop table #tmp_lock_who
SET NOCOUNT OFF
return 0
end
GO本文出自 “阚山” 博客,请务必保留此出处http://kanshan.blog.51cto.com/111574/668292
相关文章推荐
- SQL Server进程阻塞的检查和解决办法
- SQL Server进程阻塞的检查和解决办法
- SQL Server进程阻塞的检查和解决办法
- SQL Server进程阻塞的检查和解决办法(转自好友Blog)
- 解决Process因缓冲区满而导至进程阻塞的办法
- SQLSERVER阻塞,显示一直在查询和取消不了解决办法
- 由于启动用户实例的进程时出错,导致无法生成 SQL Server 的用户实例 解决办法
- 通过top命令发现plymouthd进程cpu负载达到近100% 解决办法
- WireShark默认不检查校验和的解决办法
- 重启或杀掉Nginx进程后丢失nginx.pid的解决办法
- VS编译WebService 报 进程不具有此命名空间的访问权限的解决办法
- 下载软件仓库信息失败,检查您的internet连接--解决办法
- MySQL服务器进程CPU占用100%解决办法
- kill -9杀掉nginx主进程、reload失败解决办法
- 防止JAVA程序重复启动进程的解决办法
- win7出现任务栏不见了,各个进程莫名被终止解决办法
- ubuntu 启动GNOME设置守护进程时出错 解决办法
- 关于VS2008 中添加成员变量提示 此网站的某个加载项运行失败 请检查“Internet选项”中的安全设置是否存在潜在冲突 问题解决办法
- IIS出现“另一个程序正在使用此文件,进程无法访问。”错误提示的解决办法
- VS通过添加到进程调试时没法选择w3wp.exe的解决办法