https://support.microsoft.com/en-us/help/832524/sql-server-technical-bulletin-how-to-resolve-a-deadlock

How to identify a deadlock

Step 1

To identify a deadlock, you must first obtain log information.

If you suspect a deadlock, you must gather information about the (SPIDs) and the resources that are involved in the deadlock.

To do this, add the -T1204 and the -T3605 startup parameters to SQL Server.

https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/scm-services-configure-server-startup-options?view=sql-server-2017

To add these two startup parameters, follow these steps:

  • Start SQL Server Enterprise Manager. 【这里可以使用sql server configuration manager
  • Select, and then right-click the server.
  • Click Properties.
  • Click Startup Parameters.
  • In the Startup Parameters dialog box, type -T1204 in the Parameters text box, and then click Add.
  • In the Parameters text box, type
    -T3605, and then click Add.
  • Click OK.

The startup parameters will take effect when SQL Server is stopped and then re-started.

The -T1204 startup parameter collects information about the process and the resources when the deadlock detection algorithm encounters a deadlock.

The -T3605 startup parameter writes this information to the SQL Server error logs.

1205

The -T1205 startup parameter collects
information every time that the deadlock algorithm checks for a
deadlock, not when a deadlock is encountered. You do not have to use the
-T1205 startup parameter.

If you do use the -T1205 startup parameter, the following is a sample of the output that will be in the SQL Server error log:

2003-05-14 11:46:26.76 spid4     Starting deadlock search 1
2003-05-14 11:46:26.76 spid4 Target Resource Owner:
2003-05-14 11:46:26.76 spid4 ResType:LockOwner Stype:'OR' Mode: S SPID:55 ECID:0 Ec:(0x43CAB580) Value:0x42bdf340
2003-05-14 11:46:26.76 spid4 Node:1 ResType:LockOwner Stype:'OR' Mode: S SPID:55 ECID:0 Ec:(0x43CAB580) Value:0x42bdf340
2003-05-14 11:46:26.76 spid4
2003-05-14 11:46:26.76 spid4 End deadlock search 1 ... a deadlock was not found.
2003-05-14 11:46:26.76 spid4 ----------------------------------
2003-05-14 11:46:31.76 spid4 ----------------------------------
2003-05-14 11:46:31.76 spid4 Starting deadlock search 2

备选

Sometimes, you might not be able to stop and re-start SQL Server. In that case, you can use Query Analyzer to run the following command to enable the deadlock trace flags.

Note This way you can gather information about the deadlocks immediately. The "-1" indicates all SPIDs.

dbcc traceon (1204, 3605, -1)
go
dbcc tracestatus(-1)
go

Step 2

Next, you must collect a SQL Profiler trace.

If you turn on the deadlock trace flag, you will get most of the required information, but not always.

For example, in a case study the trace flag output identified that a sp_cursoropen system stored procedure and an "UPDATE tblQueuedEvents set notifyid = 3, ResynchDate" statement were involved in a deadlock.

Unfortunately, you do not know the definition of the sp_cursoropen system stored procedure.

You also do not have the complete UPDATE statement because it was truncated.

SQL
Profiler can obtain the full statements in addition to the execution
plans of the statements.

A SQL Profiler trace also has a lock event for
"deadlock" and for "deadlock chain."

"Deadlock" corresponds to the
-T1204 flag, and "deadlock chain" corresponds to the -T1205 flag.

Turning on the deadlock trace flags and running a SQL Profiler trace
during the occurrence of a deadlock should provide you the data that you
must have to troubleshoot a deadlock.

In this case, and in others,
running SQL Profiler changes the timing of execution enough to prevent
the deadlock.

Therefore, you will typically capture the deadlock
information with the trace flags, and then you run SQL Profiler.

Troubleshooting a deadlock

After a deadlock occurs, you can gather information about the deadlock by using the
sqldiag
utility and by using SQL Profiler. In the output of the SQLDiag.txt
file, look for a "Wait-for-graph" entry. A "Wait-for graph" entry
indicates that a deadlock was encountered.

The following is a
sample of the output that you might see in the SQL Server error log when
you use the -T1205 startup parameter.

2003-05-05 15:11:50.80 spid4    Wait-for graph
2003-05-05 15:11:50.80 spid4 Node:1
2003-05-05 15:11:50.80 spid4 ResType:LockOwner Stype:'OR' Mode: S SPID:55 ECID:0 Ec:(0x33AE1538) Value:0x193
2003-05-05 15:11:50.80 spid4 Victim Resource Owner:
2003-05-05 15:11:50.80 spid4 ResType:LockOwner Stype:'OR' Mode: X SPID:60 ECID:0 Ec:(0x1F1BB5B0) Value:0x193
2003-05-05 15:11:50.80 spid4 Requested By:
2003-05-05 15:11:50.80 spid4 Input Buf: RPC Event: sp_cursoropen;1
2003-05-05 15:11:50.80 spid4 SPID: 55 ECID: 0 Statement Type: EXECUTE Line #: 1
2003-05-05 15:11:50.80 spid4 Owner:0x1937f2a0 Mode: S Flg:0x0 Ref:1 Life:00000000 SPID:55 ECID:0
2003-05-05 15:11:50.80 spid4 Grant List 0::
2003-05-05 15:11:50.80 spid4 KEY: 8:1653632984:2 (da00ce043a9e) CleanCnt:1 Mode: U Fl ags: 0x0 2003-05-05 15:11:50.80 spid4 Node:2
2003-05-05 15:11:50.80 spid4 ResType:LockOwner Stype:'OR' Mode: S SPID:55 ECID:0 Ec:(0x33AE1538) Value:0x193
2003-05-05 15:11:50.80 spid4 Requested By:
2003-05-05 15:11:50.80 spid4 Input Buf: Language Event: Update tblQueuedEvents Set NotifyID = 2, ResynchDate
2003-05-05 15:11:50.80 spid4 SPID: 60 ECID: 0 Statement Type: UPDATE Line #: 1
2003-05-05 15:11:50.80 spid4 Owner:0x1936e420 Mode: X Flg:0x0 Ref:0 Life:02000000 SPID:60 ECID:0
2003-05-05 15:11:50.80 spid4 Grant List 0::
2003-05-05 15:11:50.80 spid4 KEY: 8:1653632984:1 (2d018af70d80) CleanCnt:1 Mode: X Flags: 0x0

In the "Wait-for-graph" entry, you have Node 1 and Node 2. In each node, you have a grant section and a request section. The grant section is the "Grant List", and the request section is the "Request By."
In each node, you can identify the following:

  • The SPID.
  • The command the SPID was executing.
  • The resource.
  • The lock mode on the resource.

For example, in Node 1, the Grant List, SPID 55 had been granted an
update lock, Mode: U, on resource KEY: 8:1653632984:2. 8=DBID,
1653632984=ObjectID, and 2=Indid.

To obtain the database identification
number, run the sp_helpdb stored procedure. To obtain the table, run the following code:

select * from sysobjects where id = 1653632984

To obtain the index, run the following code:

select * from sysindexes where indid = 2 and id = 1653632984

SQL Server technical bulletin - How to resolve a deadlock的更多相关文章

  1. sql server 小技巧(6) Cannot resolve the collation conflict between "Latin1_General_CI_AI" and "Chinese_PRC_CI_AS" in the equal to operation

    今天查询二个db,出现这个错误,二种方法,一种是把db里的collation改成一样的:如果不方便可以直接在sql语句后面转一下: select * from table where crm_mscr ...

  2. sql server deadlock problem

    https://www.red-gate.com/simple-talk/sql/learn-sql-server/how-to-track-down-deadlocks-using-sql-serv ...

  3. SQL Server 2008性能故障排查(一)——概论

    原文:SQL Server 2008性能故障排查(一)--概论 备注:本人花了大量下班时间翻译,绝无抄袭,允许转载,但请注明出处.由于篇幅长,无法一篇博文全部说完,同时也没那么快全部翻译完,所以按章节 ...

  4. [转]Using the Microsoft Connector for Oracle by Attunity with SQL Server 2008 Integration Services

    本文转自:http://technet.microsoft.com/en-us/library/ee470675(v=sql.100).aspx SQL Server Technical Articl ...

  5. sql server 小技巧 集锦

    sql server 小技巧(1) 导入csv数据到sql server sql server 小技巧(2) 删除sql server中重复的数据 sql server 小技巧(3) SQL Serv ...

  6. 了解和解决SQL SERVER阻塞问题(copy)

    http://support.microsoft.com/kb/224453 Summary In this article, the term "connection" refe ...

  7. SQL Server, Cannot resolve the collation conflict

    今天遇到一个较为头痛的问题: Cannot resolve the collation conflict between "Chinese_PRC_90_CI_AS" and &q ...

  8. 招聘 微软全球技术支持中心 sql server组

    微软亚太区全球技术支持中心(APGC CSS)是微软为个人用户.开发者.IT 专业人员到合作伙伴和企业级合作伙伴提供全方位.多元化的服务和技术支持的部门.一个优秀的SQL Server技术支持工程师应 ...

  9. ORACLE透明网关访问SQL Server配置总结

      透明网关概念 ORACLE透明网关(Oracle Transparent Gateway)可以解决ORACLE数据库和非ORACLE数据库交互数据的需求.在一个异构的分布式环境中,通过ORACLE ...

随机推荐

  1. 事务处理笔记《二》.Net框架下的事务处理技术

    术语:DTC(分布式事务协调器) .Net中实现事务的几种方法总结:一. 通过后台数据库的SQL语句实现事务,在台数据库端通过语句来实现转帐业务,如下: Set xact_abort on Begin ...

  2. Python抓取网页并保存为PDF

    https://blog.csdn.net/shenwanjiang111/article/details/67634794

  3. hdu 5452(树链刨分)

    看到题目,想了挺长时间,发现不会,然后看着样子像是树上成段操作,所以查了下树链刨分,结果真的就是这个东西... Minimum Cut Time Limit: 3000/2000 MS (Java/O ...

  4. 《从零开始学Swift》学习笔记(Day4)——用Playground工具编写Swift

    Swift 2.0学习笔记(Day4)——用Playground工具编写Swift 原创文章,欢迎转载.转载请注明:关东升的博客 用Playground编写Swift代码目的是为了学习.测试算法.验证 ...

  5. 1282 时钟(最小表示法+hash)

    1282 时钟 题目来源: Codility 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 有N个时钟,每个时钟有M个指针,P个刻度.时钟是圆形的,P个刻度均分整 ...

  6. SharePoint服务器端对象模型 之 使用CAML进行数据查询(Part 3)

    (四)使用SPSiteDataQuery进行多列表查询 1.概述 前面介绍的列表查询有很多优势,但是它的一个缺点就是一次只能在一个列表中进行查询,在SharePoint中,提供了一个跨网站.跨列表查询 ...

  7. Date、Calendar、DateFormat、SimpleDateFormat、Timer、TimerTask类

    类 Date 在 JDK 1.1 之前,类 Date 有两个其他的函数.它允许把日期解释为年.月.日.小时.分钟和秒值. 它也允许格式化和解析日期字符串.不过,这些函数的 API 不易于实现国际化.从 ...

  8. CF145E Lucky Queries

    CF145E Lucky Queries 英文题面不放了,直接上翻译: 题目描述 给你n个数,每个数是4或者7,给你m个任务完成 switch l r 把[l,r]位置的4换成7,7换成4 count ...

  9. Python3.6全栈开发实例[011]

    11.元素分类有如下值li= [11,22,33,44,55,66,77,88,99,90],将所有大于 66 的值保存至字典的第一个key中,将小于 66 的值保存至第二个key的值中.即: {'k ...

  10. git原理:提交原理

    当运行git add  git commit的时候,git底层都做了什么? 这里涉及到的底层命令:git hash-object 讲对象写入到git object中git update-index   ...