SQL Server 上的死锁跟踪
Posted
技术标签:
【中文标题】SQL Server 上的死锁跟踪【英文标题】:Deadlock tracing on SQL Server 【发布时间】:2014-05-05 13:06:50 【问题描述】:我正在调查死锁跟踪,但我发现没有受害进程的死锁,那么如果没有跟踪受害进程或受害进程的 inputbuf 为空,死锁意味着什么?
请在下面找到没有为受害进程定义 inputbuf 的死锁 XML 图。
<event name="xml_deadlock_report" package="sqlserver" id="123" version="1" timestamp="2014-05-04T12:44:37.917Z">
<data name="xml_report">
<type name="unicode_string" package="package0" />
<value><deadlock>
<victim-list>
<victimProcess id="process1369fdc8"/>
</victim-list>
<process-list>
<process id="process1369fdc8" taskpriority="0" logused="0" waitresource="PAGE: 7:1:1859678" waittime="39886" ownerId="26953881" transactionname="UPDATE" lasttranstarted="2014-05-04T15:44:01.870" XDES="0x7b2bca2f0" lockMode="U" schedulerid="79" kpid="9072" status="suspended" spid="94" sbid="0" ecid="15" priority="0" trancount="0" lastbatchstarted="2014-05-04T15:44:01.540" lastbatchcompleted="2014-05-04T15:44:01.540" clientapp=".Net SqlClient Data Provider" hostname="E-DHQ-UMRSDB" hostpid="21448" isolationlevel="read committed (2)" xactid="26953881" currentdb="7" lockTimeout="4294967295" clientoption1="673185824" clientoption2="128056">
<executionStack>
<frame procname="" line="17" stmtstart="1166" stmtend="1840" sqlhandle="0x03000700cc7bde09501015010da300000100000000000000">
</frame>
<frame procname="" line="1" stmtstart="68" sqlhandle="0x01000700cb9c391ff09dd28a0a0000000000000000000000">
</frame>
<frame procname="" line="1" sqlhandle="0x000000000000000000000000000000000000000000000000">
</frame>
</executionStack>
<inputbuf>
</inputbuf>
</process>
<process id="process12d76bc8" taskpriority="0" logused="473152" waitresource="PAGE: 7:1:1859677" waittime="1787" ownerId="26919083" transactionname="user_transaction" lasttranstarted="2014-05-04T15:42:05.963" XDES="0xadb2a63b0" lockMode="IX" schedulerid="55" kpid="23948" status="suspended" spid="72" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2014-05-04T15:44:40" lastbatchcompleted="2014-05-04T15:44:39.950" lastattention="2014-05-04T15:31:58.570" clientapp=".Net SqlClient Data Provider" hostname="E-DHQ-UMRSAPPN2" hostpid="21300" loginname="SEC\S-ISD-UMRS" isolationlevel="read committed (2)" xactid="26919083" currentdb="7" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056">
<executionStack>
<frame procname="" line="1" stmtstart="1270" sqlhandle="0x02000000e5c9362166f41bf7f95f3653aba53c8419996b90">
</frame>
<frame procname="" line="1" sqlhandle="0x000000000000000000000000000000000000000000000000">
</frame>
</executionStack>
<inputbuf>
(@p0 int,@p1 varchar(8000),@p2 varchar(8000),@p3 int,@p4 varchar(8000),@p5 int,@p6 int,@p7 int,@p8 float,@p9 varchar(8000),@p10 tinyint,@p11 int,@p12 int,@p13 varchar(8000),@p14 int,@p15 varchar(8000),@p16 varchar(8000),@p17 varchar(8000),@p18 varchar(8000),@p19 varchar(8000),@p20 int,@p21 int,@p22 int,@p23 int,@p24 datetime,@p25 datetime,@p26 int,@p27 varchar(8000),@p28 int,@p29 int,@p30 int,@p31 datetime,@p32 int,@p33 float,@p34 int,@p35 int,@p36 int,@p37 int,@p38 int,@p39 int,@p40 varchar(8000),@p41 int,@p42 varchar(8000),@p43 decimal(18,8),@p44 smalldatetime,@p45 smalldatetime,@p46 varchar(8000),@p47 int,@p48 smalldatetime)UPDATE [dbo].[Meter]
SET [ReadingStatusID] = @p47, [LastEditDate] = @p48
WHERE ([ID] = @p0) AND ([SerialNumber] = @p1) AND ([SubscribtionNumber] = @p2) AND ([SubscriberID] = @p3) AND ([SubscriberNumber] = @p4) AND ([NumberOfDigits] IS NULL) AND ([BreakerCapacity] = @p5) AND ([TariffTypeID] = @p6) AND ([BusinessUnitID] = @p7) AND ([MultiplicationFactor] = @p8) AND ([AccumulationNumber </inputbuf>
</process>
</process-list>
<resource-list>
<pagelock fileid="1" pageid="1859678" dbid="7" objectname="" id="lockb618fbd00" mode="IX" associatedObjectId="72057594953859072">
<owner-list>
<owner id="process12d76bc8" mode="IX"/>
</owner-list>
<waiter-list>
<waiter id="process1369fdc8" mode="U" requestType="wait"/>
</waiter-list>
</pagelock>
<pagelock fileid="1" pageid="1859677" dbid="7" objectname="" id="lock1e573c580" mode="U" associatedObjectId="72057594953859072">
<owner-list>
<owner id="process1369fdc8" mode="U"/>
</owner-list>
<waiter-list>
<waiter id="process12d76bc8" mode="IX" requestType="wait"/>
</waiter-list>
</pagelock>
</resource-list>
</deadlock>
</value>
<text />
</data>
</event>
【问题讨论】:
你能发布一个死锁图 XML 吗? 在不了解的情况下,听起来像是查询内的死锁。我建议尝试设置 Max DOP = 1 并试一试。 @RazzleDazzle 如果这是两个相互死锁的进程,您会推荐可序列化隔离级别还是将数据库设置为单用户模式?这不是解决方案。 【参考方案1】:尝试打开这些 SQL 服务器标志。我发现这些标志对于定位有问题的 SQL 非常有用,还可以为您提供额外的信息。
dbcc tracestatus(-1)
DBCC Traceon (1204, 1222, -1)
dbcc tracestatus(-1)
-- 1204 Deadlock resources and type of locks participating in a deadlock
-- 1222 Deadlock resources and also current command affected.
/*
dbcc traceoff (1204 ,-1)
dbcc traceoff (1222 ,-1)
*/
RosSQL.blogspot.com
【讨论】:
这些 TF 将如何减少死锁?? 标志本身不会减少死锁,但它们允许您查看更多数据以及在探查器不显示任何数据的情况下。我发现这让我可以看到有问题的存储过程(或任何被锁定的东西)并进行所需的代码更改。 当然,1222 对找到原因有很大帮助。但是请从答案中删除“减少”部分,事实并非如此。 谢谢院长!看到我写的内容后,我意识到我没有输入我想说的话!再次感谢。以上是关于SQL Server 上的死锁跟踪的主要内容,如果未能解决你的问题,请参考以下文章