MSSQL2008跟踪死锁或阻塞原因
2011-09-09 20:05
190 查看
/article/4674520.html
/article/5093277.html
http://hi.baidu.com/yizir123/blog/item/1e3714eca6cbfbc2b21cb130.html
http://www.jb51.net/article/27380.htm
http://hi.baidu.com/ahwyb/blog/item/2c90454fc6098222adc3ab67.html
1,使用 SQL Server Profiler跟踪
启动>性能> SQL Server Profiler,
>显示所有事件
or
TSQL_Locks模板
添加error Log
2,使用dbcc traceon来增加死锁的日志记录
--//查看数据库某个页面的内容
go
dbcc page(dbName,fileID,pageID,3)
go
DBCC TRACEON 跟踪标记说明
DBCC常用跟踪标记
260:输出有关扩展存储过程动态链接库(DLL)的版本信息
1204:返回参与死锁的锁的类型以及当前受影响的命令
SqlServer 2005中,对于1204进行了增强,这就是1222.
Trace flag 1222.返回参与死锁的锁的类型以及当前受影响的命令(格式类似于 XML,且不符合任何 XSD 架构)
2528:通过DBCC CHECKDB、DBCC CHECKFILEGROUP和DBCC CHECKTABLE禁用对象的并行检查
3205:禁用磁带驱动程序的硬件压缩
3604:将跟踪结果输出的屏幕
3605:将跟踪结果输出的SQL SERVER2000的错误日志文件
8602:停止索引提示功能
8722:停止最优化提示功能
8755:停止锁提示功能
3,使用SQL Server Management Studio查看>管理>日志
4,添加sp_who_lock自定义存储过程
/article/5602432.html
附删除ERRORLOG命令
EXEC sp_cycle_errorlog
http://space.itpub.net/16436858/viewspace-663211
原来mssql2005 默认就有跟踪的
查看是否打开默认跟踪
SELECT * FROM SYS.configurations WHERE configuration_id=1568
查看跟踪日志信息
SELECT * FROM ::fn_trace_getinfo(0)
/article/5093277.html
http://hi.baidu.com/yizir123/blog/item/1e3714eca6cbfbc2b21cb130.html
http://www.jb51.net/article/27380.htm
http://hi.baidu.com/ahwyb/blog/item/2c90454fc6098222adc3ab67.html
1,使用 SQL Server Profiler跟踪
启动>性能> SQL Server Profiler,
>显示所有事件
or
TSQL_Locks模板
添加error Log
2,使用dbcc traceon来增加死锁的日志记录
--//查看数据库某个页面的内容
DBCC errorlog DBCC TRACEON (1204, 1222, -1); DBCC tracestatus
go
dbcc page(dbName,fileID,pageID,3)
go
DBCC TRACEON 跟踪标记说明
DBCC常用跟踪标记
260:输出有关扩展存储过程动态链接库(DLL)的版本信息
1204:返回参与死锁的锁的类型以及当前受影响的命令
SqlServer 2005中,对于1204进行了增强,这就是1222.
Trace flag 1222.返回参与死锁的锁的类型以及当前受影响的命令(格式类似于 XML,且不符合任何 XSD 架构)
2528:通过DBCC CHECKDB、DBCC CHECKFILEGROUP和DBCC CHECKTABLE禁用对象的并行检查
3205:禁用磁带驱动程序的硬件压缩
3604:将跟踪结果输出的屏幕
3605:将跟踪结果输出的SQL SERVER2000的错误日志文件
8602:停止索引提示功能
8722:停止最优化提示功能
8755:停止锁提示功能
3,使用SQL Server Management Studio查看>管理>日志
4,添加sp_who_lock自定义存储过程
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_who_lock]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[sp_who_lock] GO /******************************************************** // 学习到并改写 // 说明 : 查看数据库里阻塞和死锁情况 ********************************************************/ use master go 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
/article/5602432.html
附删除ERRORLOG命令
EXEC sp_cycle_errorlog
http://space.itpub.net/16436858/viewspace-663211
原来mssql2005 默认就有跟踪的
查看是否打开默认跟踪
SELECT * FROM SYS.configurations WHERE configuration_id=1568
查看跟踪日志信息
SELECT * FROM ::fn_trace_getinfo(0)
相关文章推荐
- MSSQL2008跟踪死锁或阻塞原因
- oracle中锁与死锁,还有阻塞的原因。
- 分享:MSSQL找出发生死锁,阻塞的语句并直接KILL掉
- MSSQL死锁产生原因及解决方法
- MSSQL产生死锁的根本原因及解决方法
- 【转载】Oracle死锁概念,阻塞产生的原因以及解决方案
- oracle锁与死锁概念,阻塞产生的原因以及解决方案
- 【SQLServer 2008】数据库查看死锁、阻塞的SQL语句
- oracle锁与死锁概念,阻塞产生的原因以及解决方案
- oracle锁与死锁概念,阻塞产生的原因以及解决方案
- 找到死锁与阻塞的原因的方法
- MSSQL锁定-3.死锁与阻塞(myBased)
- MSSQL锁定-3.死锁与阻塞(myBased)
- MSSQL产生死锁的根本原因及解决方法
- 造成阻塞和死锁的3大原因:
- 数据库阻塞和死锁的区别
- MSSQL 2008不能用IP登录问题如何解决_Mssql数据
- 锁 死锁 阻塞
- 查看死锁原因 /data/anr/traces.txt
- SQL Server 2008应用 阻塞(Blocking)