SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Retrieving Deadlock Graphs with SQL Server 2008 Extended Events


Retrieving Deadlock Graphs with SQL Server 2008 Extended Events

Author
Message
john.m.couch@gmail.com
john.m.couch@gmail.com
Grasshopper
Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)

Group: General Forum Members
Points: 22 Visits: 337
OK, so, I used your code, and noted that in the code I have written that it was taken from your code provided in the PASS Summit, and I setup a Notification Event as you did. I have a couple of questions:

1. Used some logic found here, http://forums.overclockers.com.au/showthread.php?t=689566, thinking maybe I could attach the XML output to the email vs. just using the text version in the body??? Haven't seen a deadlock come through yet, but will shortly, without a doubt.


On a side note, thanks for all your guidance and information. Appreciate it.
john.m.couch@gmail.com
john.m.couch@gmail.com
Grasshopper
Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)

Group: General Forum Members
Points: 22 Visits: 337
OK, dumb question, does the deadlock notification event you created only work on 1 database? Or does it apply to the whole server, and deadlock that occurs?
MyDoggieJessie
MyDoggieJessie
SSCertifiable
SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)

Group: General Forum Members
Points: 6656 Visits: 7392
I've tried every version of the code pasted on the page and consistently get this error:
Msg 9436, Level 16, State 1, Line 1
XML parsing: line 5, character 15, end tag does not match start tag

______________________________________________________________________________
"Never argue with an idiot; They'll drag you down to their level and beat you with experience" ;-)
hello mahesh
hello mahesh
SSC Rookie
SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)

Group: General Forum Members
Points: 48 Visits: 255
Jonathan Kehayias (2/20/2009)
Comments posted to this topic are about the item <A HREF="/articles/deadlocks/65658/">Retrieving Deadlock Graphs with SQL Server 2008 Extended Events</A>



Whats the requirement for it to work on 2008 R2 version?
select @@VERSION
Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (X64) Jun 17 2011 00:54:03 Copyright (c) Microsoft Corporation Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1)
john.m.couch@gmail.com
john.m.couch@gmail.com
Grasshopper
Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)

Group: General Forum Members
Points: 22 Visits: 337
What requirement? For the deadlock notification? Its the same as it is on reg 2008.
hello mahesh
hello mahesh
SSC Rookie
SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)

Group: General Forum Members
Points: 48 Visits: 255
We had couple of deadlock issues,
but nothing is captured with this query..

select XEventData.XEvent.value('(data/value)[1]', 'varchar(max)') as DeadlockGraph
FROM
(select CAST(target_data as xml) as TargetData
from sys.dm_xe_session_targets st
join sys.dm_xe_sessions s on s.address = st.event_session_address
where name = 'system_health') AS Data
CROSS APPLY TargetData.nodes ('//RingBufferTarget/event') AS XEventData (XEvent)
where XEventData.XEvent.value('@name', 'varchar(4000)') = 'xml_deadlock_report'
douglar
douglar
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 71
hello mahesh (9/17/2012)
We had couple of deadlock issues,
but nothing is captured with this query..


First try this:
WITH SessionData as (
SELECT
XEventData.XEvent.value('(data/value)[1]', 'varchar(max)') VarcharResults
FROM (
select CAST(target_data as xml) as TargetData
from sys.dm_xe_session_targets st
join sys.dm_xe_sessions s on s.address = st.event_session_address
where name = 'system_health'
) AS Data
CROSS APPLY TargetData.nodes ('RingBufferTarget/event[@name="xml_deadlock_report"]') AS XEventData (XEvent)
)
SELECT
substring(VarcharResults, charindex( 'lasttranstarted="', VarcharResults) + len('lasttranstarted="'),19) ApproxDateGuess
, cast (
REPLACE(REPLACE(
case
-- bad tag, should be <victimProcess id="process_______"/>
when patindex( '%<victimProcess id="process_______">%', VarcharResults ) > 1 then
stuff( VarcharResults , patindex( '%<victimProcess id="process_______">%', VarcharResults )+34,0,'/')
else VarcharResults
end
, '<victim-list>', '<deadlock><victim-list>'), '<process-list>','</victim-list><process-list>')
as XML ) DeadlockTree
FROM SessionData
ORDER BY 1;



if that doesn't work, I can think of two things--
1) If you have a lot of extended events, the ring buffer may have lapped itself
2) I've seen cases where it appears like an event with bad XML gets stuck in the ring buffer and you can't see past it until the bad event gets over written.



hello mahesh
hello mahesh
SSC Rookie
SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)

Group: General Forum Members
Points: 48 Visits: 255
Still noluck. I tried searching for key words: 'dead' , 'victim' in xml and not found any.

May be it got overlapped as the deadlock event occured couple of weeks back.

Thanks
john.m.couch@gmail.com
john.m.couch@gmail.com
Grasshopper
Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)

Group: General Forum Members
Points: 22 Visits: 337
Attached is the script I created using Jonathon's provided code. If you replace all the values I have marked with <xxx in the script and run it, it will setup the deadlock queue for you. It works on all my 2008 and 2008 R2 environments. Change the extension to .sql
Attachments
Jonathan Kehayias
Jonathan Kehayias
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2876 Visits: 1807
hello mahesh (9/17/2012)
Still noluck. I tried searching for key words: 'dead' , 'victim' in xml and not found any.

May be it got overlapped as the deadlock event occured couple of weeks back.

Thanks


If you restarted the instance since the deadlock occurred it won't be in the system_health event session since it is a memory resident target and not persisted across service failures/restarts.

Jonathan Kehayias | Principal Consultant | MCM: SQL Server 2008
My Blog | Twitter | MVP Profile
Training | Consulting | Become a SQLskills Insider
Troubleshooting SQL Server: A Guide for Accidental DBAs
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search