如何排查SQL死锁的错误
1个回答
2017-04-18 · 知道合伙人软件行家
关注
展开全部
1. 开启死锁日志输出(deadlock trace)
DBCC TRACEON(1204,1222)
Trace flag 1204 reports deadlock information formatted by each node involved in the deadlock.
Trace flag 1222 formats deadlock information, first by processes and then by resources.
开启了上面的选项之后, SQL会输出死锁的细节信息到SQL Error Log中(默认位置Program Files\Microsoft SQL Server\MSSQL.n\MSSQL\LOG\ERRORLOG and ERRORLOG.n)
2. 开启SQL Profiler.
Start SQL profiler
On the Trace Properties dialog box, on the General tab, check Save to file and specify a path to save the trace
Click the Events tab, only add Locks\Lock:deadlock and Locks\Lock:deadlock chain
Click the Data columns tab, add DatabaseID, IndexID, ObjectID
可以通过下面的语句把DatabaseID和ObjectID换成DatabaseName和ObjectName
SELECT database_name(DatabaseID)
SELECT object_name(ObjectID)
3. 使用下面的查询语句来检查那个进程被锁住了.
SELECT * FROM sys.sysprocesses WHERE blocked <> 0
从Blocked列中得到SPID
DBCC inputbuffer (SPID)
sp_who2
sp_lock2
DBCC TRACEON(1204,1222)
Trace flag 1204 reports deadlock information formatted by each node involved in the deadlock.
Trace flag 1222 formats deadlock information, first by processes and then by resources.
开启了上面的选项之后, SQL会输出死锁的细节信息到SQL Error Log中(默认位置Program Files\Microsoft SQL Server\MSSQL.n\MSSQL\LOG\ERRORLOG and ERRORLOG.n)
2. 开启SQL Profiler.
Start SQL profiler
On the Trace Properties dialog box, on the General tab, check Save to file and specify a path to save the trace
Click the Events tab, only add Locks\Lock:deadlock and Locks\Lock:deadlock chain
Click the Data columns tab, add DatabaseID, IndexID, ObjectID
可以通过下面的语句把DatabaseID和ObjectID换成DatabaseName和ObjectName
SELECT database_name(DatabaseID)
SELECT object_name(ObjectID)
3. 使用下面的查询语句来检查那个进程被锁住了.
SELECT * FROM sys.sysprocesses WHERE blocked <> 0
从Blocked列中得到SPID
DBCC inputbuffer (SPID)
sp_who2
sp_lock2
大雅新科技有限公司
2024-11-19 广告
2024-11-19 广告
这方面更多更全面的信息其实可以找下大雅新。深圳市大雅新科技有限公司从事KVM延长器,DVI延长器,USB延长器,键盘鼠标延长器,双绞线视频传输器,VGA视频双绞线传输器,VGA延长器,VGA视频延长器,DVI KVM 切换器等,优质供应商,...
点击进入详情页
本回答由大雅新科技有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询