3. 跟踪标记 (Trace Flag) 1204, 1222 抓取死锁信息
跟踪标记:1204/1222
功能及用途:
捕获SQL Server死锁信息,并自动存放到错误日志(ERRORLOG)中。
举例:
USE tempdb
GO CREATE TABLE t1(id int)
INSERT t1 SELECT 1 CREATE TABLE t2(id int)
INSERT t2 SELECT 1
GO --开启1204/1222跟踪标记(任何查询窗口)
DBCC TRACEON(1204,-1)
--DBCC TRACEON(1205,3605,-1)
--DBCC TRACEON(1206,3605,-1) --DBCC TRACEON(1222,-1)
GO --查询窗口1
SET LOCK_TIMEOUT -1
SET TRANSACTION ISOLATION LEVEL READ COMMITTED BEGIN TRAN
UPDATE t1 SET id = 0 WHERE id=1
WAITFOR DELAY '00:00:05'
UPDATE t2 SET id = 0 WHERE id=1
--COMMIT TRAN
GO --查询窗口2
SET LOCK_TIMEOUT -1
SET TRANSACTION ISOLATION LEVEL READ COMMITTED --死锁优先级为low,将被选择作为牺牲品
SET DEADLOCK_PRIORITY LOW BEGIN TRAN
UPDATE t2 SET id = 0 WHERE id=1
UPDATE t1 SET id = 0 WHERE id=1
--COMMIT TRAN
GO --关闭1204/1222跟踪标记(任何查询窗口)
DBCC TRACEOFF(1204,-1)
--DBCC TRACEOFF(1205,3605,-1)
--DBCC TRACEOFF(1206,3605,-1) --DBCC TRACEOFF(1222,-1)
GO --查看错误日志里的死锁信息
exec xp_readerrorlog 0,1 DROP TABLE t1,t2
跟踪标记1204 在错误日志中记录的死锁信息
DBCC TRACEON 1204, server process ID (SPID) 56. This is an informational message only; no user action is required.
Deadlock encountered .... Printing deadlock information
Wait-for graph
NULL
Node:1 RID: 2:1:624:0 CleanCnt:2 Mode:X Flags: 0x3
Grant List 1:
Owner:0x00000034DF20D840 Mode: X Flg:0x40 Ref:0 Life:02000000 SPID:56 ECID:0 XactLockInfo: 0x00000034DDE34440
SPID: 56 ECID: 0 Statement Type: UPDATE Line #: 9
Input Buf: Language Event:
--查询窗口1
SET LOCK_TIMEOUT -1
SET TRANSACTION ISOLATION LEVEL READ COMMITTED BEGIN TRAN
UPDATE t1 SET id = 0 WHERE id=1
WAITFOR DELAY '00:00:05'
UPDATE t2 SET id = 0 WHERE id=1
--COMMIT TRAN Requested by:
ResType:LockOwner Stype:'OR'Xdes:0x00000034E122B2B8 Mode: U SPID:58 BatchID:0 ECID:0 TaskProxy:(0x00000034BB418870) Value:0xdf20d040 Cost:(5/224)
NULL
Node:2 RID: 2:3:944:0 CleanCnt:2 Mode:X Flags: 0x3
Grant List 1:
Owner:0x00000034DF20D980 Mode: X Flg:0x40 Ref:0 Life:02000000 SPID:58 ECID:0 XactLockInfo: 0x00000034E122B2F0
SPID: 58 ECID: 0 Statement Type: UPDATE Line #: 8
Input Buf: Language Event:
--查询窗口2
SET LOCK_TIMEOUT -1
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
SET DEADLOCK_PRIORITY LOW BEGIN TRAN
UPDATE t2 SET id = 0 WHERE id=1
UPDATE t1 SET id = 0 WHERE id=1
--COMMIT TRAN
Requested by:
ResType:LockOwner Stype:'OR'Xdes:0x00000034DDE34408 Mode: U SPID:56 BatchID:0 ECID:0 TaskProxy:(0x00000034BB1DC870) Value:0xdf20ec00 Cost:(0/224)
NULL
Victim Resource Owner:
ResType:LockOwner Stype:'OR'Xdes:0x00000034E122B2B8 Mode: U SPID:58 BatchID:0 ECID:0 TaskProxy:(0x00000034BB418870) Value:0xdf20d040 Cost:(5/224)
DBCC TRACEOFF 1204, server process ID (SPID) 56. This is an informational message only; no user action is required.
跟踪标记1222 在错误日志中记录的死锁信息
DBCC TRACEON 1222, server process ID (SPID) 56. This is an informational message only; no user action is required.
deadlock-list
deadlock victim=process34d71fc4e8
process-list
process id=process34d71fc4e8 taskpriority=5 logused=224 waitresource=RID: 2:1:624:0 waittime=3012 ownerId=1281992 transactionname=user_transaction lasttranstarted=2016-10-12T10:11:24.513 XDES=0x34dde34408 lockMode=U schedulerid=2 kpid=5736 status=suspended spid=58 sbid=0 ecid=0 priority=-5 trancount=2 lastbatchstarted=2016-10-12T10:11:24.513 lastbatchcompleted=2016-10-12T10:11:12.760 lastattention=2016-10-12T10:10:46.323 clientapp=Microsoft SQL Server Management Studio - Query hostname=CHRZHANG hostpid=6924 loginname=PCLC0\chrzhang isolationlevel=read committed (2) xactid=1281992 currentdb=2 lockTimeout=4294967295 clientoption1=671090784 clientoption2=390200
executionStack
frame procname=adhoc line=9 stmtstart=38 stmtend=116 sqlhandle=0x020000006f1dc606af4ee82be297cae142d4eca1b1b26d840000000000000000000000000000000000000000
unknown
frame procname=adhoc line=9 stmtstart=324 stmtend=384 sqlhandle=0x02000000c9c0f33adb0fe790eb6b0e4c7175f9f4b5931a970000000000000000000000000000000000000000
unknown
inputbuf
--查询窗口2
SET LOCK_TIMEOUT -1
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
SET DEADLOCK_PRIORITY LOW
BEGIN TRAN
UPDATE t2 SET id = 0 WHERE id=1
UPDATE t1 SET id = 0 WHERE id=1
--COMMIT TRAN
process id=process34ddc6a4e8 taskpriority=0 logused=224 waitresource=RID: 2:3:944:0 waittime=1071 ownerId=1281979 transactionname=user_transaction lasttranstarted=2016-10-12T10:11:21.440 XDES=0x34e122b2b8 lockMode=U schedulerid=2 kpid=968 status=suspended spid=56 sbid=0 ecid=0 priority=0 trancount=2 lastbatchstarted=2016-10-12T10:11:21.440 lastbatchcompleted=2016-10-12T10:11:04.287 lastattention=1900-01-01T00:00:00.287 clientapp=Microsoft SQL Server Management Studio - Query hostname=CHRZHANG hostpid=6924 loginname=PCLC0\chrzhang isolationlevel=read committed (2) xactid=1281979 currentdb=2 lockTimeout=4294967295 clientoption1=671090784 clientoption2=390200
executionStack
frame procname=adhoc line=8 stmtstart=38 stmtend=116 sqlhandle=0x0200000083cd4832d993ca3b2dcaae9f9cc70a25e718dbe90000000000000000000000000000000000000000
unknown
frame procname=adhoc line=8 stmtstart=326 stmtend=386 sqlhandle=0x02000000ff6a84274c6888c86c481ae84300231e8f5fb8000000000000000000000000000000000000000000
unknown
inputbuf
--查询窗口1
SET LOCK_TIMEOUT -1
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
BEGIN TRAN
UPDATE t1 SET id = 0 WHERE id=1
WAITFOR DELAY '00:00:05'
UPDATE t2 SET id = 0 WHERE id=1
--COMMIT TRAN
resource-list
ridlock fileid=1 pageid=624 dbid=2 objectname=tempdb.dbo.t1 id=lock34d8ea3200 mode=X associatedObjectId=2017612634171244544
owner-list
owner id=process34ddc6a4e8 mode=X
waiter-list
waiter id=process34d71fc4e8 mode=U requestType=wait
ridlock fileid=3 pageid=944 dbid=2 objectname=tempdb.dbo.t2 id=lock34d8ea3780 mode=X associatedObjectId=2089670228250132480
owner-list
owner id=process34d71fc4e8 mode=X
waiter-list
waiter id=process34ddc6a4e8 mode=U requestType=wait
DBCC TRACEOFF 1222, server process ID (SPID) 56. This is an informational message only; no user action is required.
小结:
(1) 不需要加跟踪标记3605,跟踪标记1204,1222捕获的死锁信息便会被写到错误日志;
(2) 跟踪标记 1222以XML样式返回死锁信息,相比跟踪标记1204,返回的信息也更为丰富;
(3) 无文档记载的跟踪标记1205,1206,据说可以用来丰富1204捕获死锁的信息,在SQL Server 2016下简单测试同时开启1204,1205,1206,和单独开启1204并没发现有什么不同,个人猜测是随着版本更替,跟踪标记捕获的死锁信息已经被整合,直接用1204或1222即可;
(4) 从SQL Server 2008开始,引进了扩展事件(Extended Events),也可以用来捕获死锁信息。
参考:
Tracing a SQL Server Deadlock
https://www.mssqltips.com/sqlservertutorial/252/tracing-a-sql-server-deadlock/
Trace Flags - SQL Server Wiki - SQL Server - Toad World
https://www.toadworld.com/platforms/sql-server/w/wiki/9790.trace-flags
Using SQL Server 2008 Extended Events
https://technet.microsoft.com/en-us/library/dd822788%28v=sql.100%29.aspx?f=255&MSPPError=-2147217396
3. 跟踪标记 (Trace Flag) 1204, 1222 抓取死锁信息的更多相关文章
- 0. 跟踪标记 (Trace Flag) 简介
一. 什么是跟踪标记 SQL Server 跟踪标记(Trace Flag),像是一个开关,可用来自定义SQL Server的某种行为或特性,在性能诊断,系统调试等方面较为常用.比如:开启1204或1 ...
- 2. 跟踪标记 (Trace Flag) 3604, 3605 输出DBCC命令结果
跟踪标记:3604 功能: 输出DBCC命令返回结果到查询窗口(通常是SSMS窗口),类似print命令的显示效果: 用途: 常用于获取DBCC IND, DBCC PAGE命令的输出结果,因为这2个 ...
- 4. 跟踪标记 (Trace Flag) 610 对索引组织表(IOT)最小化日志
跟踪标记:610 功能: 用批量导入操作(Bulk Import Operations)加载数据时,对于索引组织表(即有聚集索引的表) 最小化日志: 上图为simple/bulk-logged恢复模式 ...
- 5. 跟踪标记 (Trace Flag) 834, 845 对内存页行为的影响
跟踪标记:834 功能: 在64位的windows环境下,为SQL Server开启这个跟踪标记,那么SQL Server 会使用大页(Large pages)为内存缓冲区(buffer pool)分 ...
- 1. 跟踪标记 (Trace Flag) 1117, 1118 文件增长及空间分配方式
跟踪标记:1117 功能: 默认,同一个文件组下的多个文件,如果某个文件没有可用空间,且设置了自动增长,则该文件自动增长,其他文件大小保持不变: 开启后,同一文件组下的多个文件,如果某个文件没有可用空 ...
- (5.2.2)配置服务器参数——dbcc跟踪标记(trace)
关键字:跟踪标记,跟踪 [1]常规dbcc命令 dbcc help('?') --查看dbcc 所有命令,常规下只有32个常用的dbcc TRACEON(2588) --指定了2588标记的话,你就可 ...
- PHP快速抓取快递信息
<?php header("Content-type:text/html;charset=utf-8"); /** * Express.class.php 快递查询类 * @ ...
- 网络爬虫: 从allitebooks.com抓取书籍信息并从amazon.com抓取价格(3): 抓取amazon.com价格
通过上一篇随笔的处理,我们已经拿到了书的书名和ISBN码.(网络爬虫: 从allitebooks.com抓取书籍信息并从amazon.com抓取价格(2): 抓取allitebooks.com书籍信息 ...
- 网络爬虫: 从allitebooks.com抓取书籍信息并从amazon.com抓取价格(2): 抓取allitebooks.com书籍信息及ISBN码
这一篇首先从allitebooks.com里抓取书籍列表的书籍信息和每本书对应的ISBN码. 一.分析需求和网站结构 allitebooks.com这个网站的结构很简单,分页+书籍列表+书籍详情页. ...
随机推荐
- ES6-Proxy and Reflect
依赖文件地址 :https://github.com/chanceLe/ES6-Basic-Syntax/tree/master/js <!DOCTYPE html> <html&g ...
- EXCEL导出工具类及调用
一.Excel导出工具类代码 package com.qiyuan.util; import java.io.OutputStream; import java.io.UnsupportedEncod ...
- oracle序列的创建和使用
oracle 序列的创建与使用 (2012-03-15 16:14:09) -------------------------------------------------------------- ...
- windows10下mysql8.0.11忘记密码的解决办法
首先输入 新开一个cmd窗口,登录mysql,刷新权限表 FLUSH PRIVILEGES; 经过我再次修改密码测试,只用下面这条语句就可以了 ALTER USER 'root'@'localhost ...
- package.json参数简单介绍
概述: 每个项目的根目录下都会有一个package.json文件,定义了项目所需的模块,以及项目信息.执行npm install 命令会自动下载package.json中配置的模块,也就是配置项目的运 ...
- jedis、jedisPool、jedisCluster的使用方法
jedis 连接redis(单机): 使用jedis如何操作redis,但是其实方法是跟redis的操作大部分是相对应的. 所有的redis命令都对应jedis的一个方法 1.在macen工程 ...
- 2015.09.16 SCADA系统介绍及应用
SCADA(Supervisory Control And Data Acquisition)系统,即数据采集与监视控制系统.SCADA系统是以计算机为基础的DCS与电力自动化监控系统:它应用领域很广 ...
- Android屏幕适配工具
这里需要用到一个jar包,下载拿到这个jar包后直接双击就可以生成市场大部分主流屏幕尺寸了.然后只要把生成好的xml尺寸文件拷贝到相应的value文件中即可.很方便,以后再也不用担心适配繁琐的问题了. ...
- 图片加载库Glide的封装工具类,方便以后使用
直接上源码.注释得已经很清晰了,直接调用即可. package com.liuguilin.lovewallpaper.utils; /* * Created by 火龙裸先生 on 2017/3/3 ...
- Android ListView左滑删除、左滑自定义功能
最近项目需要ListView左滑删除功能,搜集了很多资料发现了一个某一前辈写的库能很简单的实现这个功能,而且有源码,直接拿来使用了. 库名字叫做SwipeMenuListView,下面给大家演示一下使 ...