Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««34567»»»

Retrieving Deadlock Graphs with SQL Server 2008 Extended Events Expand / Collapse
Author
Message
Posted Wednesday, April 11, 2012 2:59 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, August 19, 2014 11:13 AM
Points: 14, Visits: 281
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.
Post #1281983
Posted Wednesday, April 11, 2012 8:58 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, August 19, 2014 11:13 AM
Points: 14, Visits: 281
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?
Post #1282103
Posted Friday, June 15, 2012 12:00 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Wednesday, August 20, 2014 9:31 AM
Points: 3,903, Visits: 7,138
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"
Post #1316826
Posted Monday, September 17, 2012 1:05 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, August 28, 2014 9:10 AM
Points: 16, Visits: 199
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)
Post #1360414
Posted Monday, September 17, 2012 1:35 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, August 19, 2014 11:13 AM
Points: 14, Visits: 281
What requirement? For the deadlock notification? Its the same as it is on reg 2008.
Post #1360431
Posted Monday, September 17, 2012 3:11 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, August 28, 2014 9:10 AM
Points: 16, Visits: 199
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'

Post #1360471
Posted Monday, September 17, 2012 4:00 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, May 28, 2014 5:57 AM
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.



Post #1360487
Posted Monday, September 17, 2012 4:11 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, August 28, 2014 9:10 AM
Points: 16, Visits: 199
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
Post #1360489
Posted Monday, September 17, 2012 4:20 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, August 19, 2014 11:13 AM
Points: 14, Visits: 281
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

  Post Attachments 
Deadlock Event Notification - Handout.txt (63 views, 15.68 KB)
Post #1360491
Posted Monday, September 17, 2012 4:35 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Monday, June 23, 2014 11:55 AM
Points: 1,708, Visits: 1,792
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
Post #1360493
« Prev Topic | Next Topic »

Add to briefcase «««34567»»»

Permissions Expand / Collapse