October 6, 2015 at 6:46 pm
Hi All ,
I have a deadlock in my system and am suspicious about index defragmentation that I run at 8 PM . How do we make SQL server always choose index defragmentation as a victim ?
Many thanks on your feedback !
Cheers
October 6, 2015 at 8:04 pm
You can use the SET DEADLOCK_PRIORITY to make it the lowest priority. That should result in it always being the victim.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
October 6, 2015 at 10:30 pm
OK COOL . Thanks for that
Btw how do I catch the deadlock process so I will know which queries that are involved at specific time?
October 6, 2015 at 11:07 pm
Turn traceflag 1222 on. That will result in a deadlock graph being written to the error log.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
October 6, 2015 at 11:59 pm
Thanks so much Gail !!
I just enable it using DBCC TRACEON(1222,-1)
and will see how it goes
Can I turn it on forever ? just in case one day I need to check the deadlock again
cheers
October 7, 2015 at 3:16 am
You're already capturing deadlock information in the system_health extended event session. You don't have to clutter up your error log with deadlock graphs through the traceflag if you don't want to. The only issue with this is that the output is in XML. However, here's a query[/url] to make that simple too.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
October 7, 2015 at 5:00 am
Grant Fritchey (10/7/2015)
You're already capturing deadlock information in the system_health extended event session.
On 2008?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
October 7, 2015 at 6:33 am
GilaMonster (10/7/2015)
Grant Fritchey (10/7/2015)
You're already capturing deadlock information in the system_health extended event session.On 2008?
Yep.
No gui, but it works.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
October 7, 2015 at 6:27 pm
HI guys ,
I got something from Error Log but I couldn’t read the deadlock culprit ( The result as attached )
I assume the yellow highlighted is the Victim and the Red one is the culprit ?? But the information that I can read is the object name , No query there
Still confused with it
Anyone knows how to read it ?Please kindly help
Many thanks
October 7, 2015 at 11:14 pm
Hi Guys ,
I just run the script from Extended Event and here what I get ( but I still don’t know what is the cause of this deadlock ) – The query that I highlighted in Yellow is the deadlock Victim
Can you please kindly help how to read this ?
</event>
<event name="xml_deadlock_report" package="sqlserver" id="123" version="1" timestamp="2015-10-05T09:01:31.279Z">
<data name="xml_report">
<type name="unicode_string" package="package0" />
<value><deadlock>
<victim-list>
<victimProcess id="process9e3b4c8"/>
</victim-list>
<process-list>
<process id="process9e3b4c8" taskpriority="0" logused="16984" waitresource="KEY: 27:72057594040942592 (1c00c4c874c4)" waittime="3272" ownerId="67425560" transactionname="user_transaction" lasttranstarted="2015-10-05T20:00:09.247" XDES="0x49265f990" lockMode="S" schedulerid="6" kpid="740" status="suspended" spid="125" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2015-10-05T20:00:36.620" lastbatchcompleted="2015-10-05T20:00:36.620" clientapp=".Net SqlClient Data Provider" hostname="ETSPDCTMS1-VW" hostpid="4068" loginname="PARKEON\PKNAdmin" isolationlevel="read committed (2)" xactid="67425560" currentdb="27" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056">
<executionStack>
<frame procname="" line="1" stmtstart="40" sqlhandle="0x02000000f03aee301d3e9d0e43abafa7f772fdb42020cffd">
</frame>
<frame procname="" line="1" sqlhandle="0x000000000000000000000000000000000000000000000000">
</frame>
</executionStack>
<inputbuf>
(@p0 int,@p1 bigint)DELETE FROM ManifestExportRecord WHERE Id = @p0 AND VersionNumber = @p1 </inputbuf>
</process>
<process id="process9e30988" taskpriority="0" logused="21244" waitresource="KEY: 27:72057594040942592 (0d003ef8d12c)" waittime="3277" ownerId="67429895" transactionname="user_transaction" lasttranstarted="2015-10-05T20:00:10.770" XDES="0xdc39cea0" lockMode="S" schedulerid="5" kpid="3540" status="suspended" spid="119" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2015-10-05T20:00:36.617" lastbatchcompleted="2015-10-05T20:00:36.613" clientapp=".Net SqlClient Data Provider" hostname="ETSPDCTMS1-VW" hostpid="4068" loginname="PARKEON\PKNAdmin" isolationlevel="read committed (2)" xactid="67429895" currentdb="27" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056">
<executionStack>
<frame procname="" line="1" stmtstart="40" sqlhandle="0x02000000f03aee301d3e9d0e43abafa7f772fdb42020cffd">
</frame>
<frame procname="" line="1" sqlhandle="0x000000000000000000000000000000000000000000000000">
</frame>
</executionStack>
<inputbuf>
(@p0 int,@p1 bigint)DELETE FROM ManifestExportRecord WHERE Id = @p0 AND VersionNumber = @p1 </inputbuf>
</process>
</process-list>
<resource-list>
<keylock hobtid="72057594040942592" dbid="27" objectname="" indexname="" id="lockb0c6100" mode="X" associatedObjectId="72057594040942592">
<owner-list>
<owner id="process9e30988" mode="X"/>
</owner-list>
<waiter-list>
<waiter id="process9e3b4c8" mode="S" requestType="wait"/>
</waiter-list>
</keylock>
<keylock hobtid="72057594040942592" dbid="27" objectname="" indexname="" id="lock127266780" mode="X" associatedObjectId="72057594040942592">
<owner-list>
<owner id="process9e3b4c8" mode="X"/>
</owner-list>
<waiter-list>
<waiter id="process9e30988" mode="S" requestType="wait"/>
</waiter-list>
</keylock>
</resource-list>
</deadlock>
</event>
<event name="xml_deadlock_report" package="sqlserver" id="123" version="1" timestamp="2015-10-06T09:00:08.214Z">
<data name="xml_report">
<type name="unicode_string" package="package0" />
<value><deadlock>
<victim-list>
<victimProcess id="processb80f4c8"/>
</victim-list>
<process-list>
<process id="processb80f4c8" taskpriority="0" logused="16840" waitresource="KEY: 27:72057594040942592 (1600a028c9ab)" waittime="3097" ownerId="95374168" transactionname="user_transaction" lasttranstarted="2015-10-06T19:59:06.290" XDES="0x424195990" lockMode="S" schedulerid="5" kpid="4424" status="suspended" spid="143" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2015-10-06T19:59:18.283" lastbatchcompleted="2015-10-06T19:59:18.280" clientapp=".Net SqlClient Data Provider" hostname="ETSPDCTMS1-VW" hostpid="4068" loginname="PARKEON\PKNAdmin" isolationlevel="read committed (2)" xactid="95374168" currentdb="27" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056">
<executionStack>
<frame procname="" line="1" stmtstart="40" sqlhandle="0x02000000f03aee301d3e9d0e43abafa7f772fdb42020cffd">
</frame>
<frame procname="" line="1" sqlhandle="0x000000000000000000000000000000000000000000000000">
</frame>
</executionStack>
<inputbuf>
(@p0 int,@p1 bigint)DELETE FROM ManifestExportRecord WHERE Id = @p0 AND VersionNumber = @p1 </inputbuf>
</process>
<process id="process9e1ddc8" taskpriority="0" logused="17936" waitresource="KEY: 27:72057594040942592 (0c005b9f6d94)" waittime="3397" ownerId="95370152" transactionname="user_transaction" lasttranstarted="2015-10-06T19:59:04.267" XDES="0x248e8aea0" lockMode="S" schedulerid="3" kpid="5536" status="suspended" spid="135" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2015-10-06T19:59:18.787" lastbatchcompleted="2015-10-06T19:59:18.783" clientapp=".Net SqlClient Data Provider" hostname="ETSPDCTMS1-VW" hostpid="4068" loginname="PARKEON\PKNAdmin" isolationlevel="read committed (2)" xactid="95370152" currentdb="27" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056">
<executionStack>
<frame procname="" line="1" stmtstart="40" sqlhandle="0x02000000f03aee301d3e9d0e43abafa7f772fdb42020cffd">
</frame>
<frame procname="" line="1" sqlhandle="0x000000000000000000000000000000000000000000000000">
</frame>
</executionStack>
<inputbuf>
(@p0 int,@p1 bigint)DELETE FROM ManifestExportRecord WHERE Id = @p0 AND VersionNumber = @p1 </inputbuf>
</process>
</process-list>
<resource-list>
<keylock hobtid="72057594040942592" dbid="27" objectname="" indexname="" id="lockafa2f80" mode="X" associatedObjectId="72057594040942592">
<owner-list>
<owner id="process9e1ddc8" mode="X"/>
</owner-list>
<waiter-list>
<waiter id="processb80f4c8" mode="S" requestType="wait"/>
</waiter-list>
</keylock>
<keylock hobtid="72057594040942592" dbid="27" objectname="" indexname="" id="lockb9b7180" mode="X" associatedObjectId="72057594040942592">
<owner-list>
<owner id="processb80f4c8" mode="X"/>
</owner-list>
<waiter-list>
<waiter id="process9e1ddc8" mode="S" requestType="wait"/>
</waiter-list>
</keylock>
</resource-list>
</deadlock>
October 8, 2015 at 2:41 am
WhiteLotus (10/7/2015)
I assume the yellow highlighted is the Victim and the Red one is the culprit ?? But the information that I can read is the object name , No query there
No. The yellow is one of the queries (not the victim process) and the red is one of the wait resources. The two queries involved in the deadlock are the same, both sessions are running that delete. Since there's a user transaction, there was probably a statement run before the delete. You'll need to dig into the .net code and identify it
This may help you read the XE dedlock graph: https://www.simple-talk.com/sql/performance/sql-server-deadlocks-by-example/
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
October 8, 2015 at 4:56 am
They're both running this query:
(@p0 int,@p1 bigint)DELETE FROM ManifestExportRecord WHERE Id = @p0 AND VersionNumber = @p1
Deadlocks are usually multi-statement issues involving access across multiple resources, not a single statement. As Gail says, something else is involved in there.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
October 8, 2015 at 6:23 pm
Thanks so much Gail
That’s a very good Information for me! I will work it out with my team
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply