Retrieving Deadlock Graphs with SQL Server 2008 Extended Events

  • hello mahesh (9/17/2012)


    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'

    We had the same issues here as hello mahesh...

    select @@version

    Microsoft SQL Server 2008 (SP3) - 10.0.5512.0 (X64) Aug 22 2012 19:25:47 Copyright (c) 1988-2008 Microsoft Corporation Standard Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) (VM)

    I found that the issue was with this line:

    cross apply TargetData.nodes ('//RingBufferTarget/event') as XEventData (XEvent)

    Using either one of the following two lines returned the expected results:

    cross apply TargetData.nodes ('/RingBufferTarget/event') as XEventData (XEvent)

    cross apply TargetData.nodes ('RingBufferTarget/event') as XEventData (XEvent)

    Hope this helps.

  • Hi Jonathan, I read your article, but I am still unsure how to see the graphical view of the deadlock. The query returns several rows of xml data and when I click on one, it opens up the raw xml. How do I see the graph? Thanks.

  • shahgols (9/26/2013)


    Hi Jonathan, I read your article, but I am still unsure how to see the graphical view of the deadlock. The query returns several rows of xml data and when I click on one, it opens up the raw xml. How do I see the graph? Thanks.

    When you click on one and the xml opens, save it with .xdl extension. Close it and reopen it.

    Jared
    CE - Microsoft

  • Thank you Jared.

  • When I try to open the xdl file in SSMS 2012, I get:

    Failed to initialize deadlock control.

    Key cannot be null.

    Parameter name: key

    When I try to open it in SSMS 2008 R2, I get:

    Failed to initialize deadlock control.

    There is an error in XML document (1, 2).

    <deadlock xmlns="> was not expected.

    Any help would be appreciated.

  • AnthonyR, I don't think there is a issue with my syntax, but it was with SSMS 2008 or older. Even your suggested change didn't work.

    In SSMS 2012 version it works!

    http://www.sqlskills.com/blogs/jonathan/graphically-viewing-extended-events-deadlock-graphs/

    Thanks

  • @shahgols: The Deadlock Graph visualizer in SSMS expects XDL (XML Deadlock List) files as output from SQL Profiler using the following technique: How to save deadlock graph events as .xdl file in SQL Server?[/url]

    At least in the case of SQL Server 2008, the XML output from Extended Events using Jonathan's code is very similar, but not quite the same. Thankfully there are not too many modifications that need to be done:

    1. The root node needs to be <deadlock-list>, one level above <deadlock>

    2. The id attribute of the <victimProcess> tag needs to be copied into the victim attribute of the <deadlock> tag.

    3. I don't know if this is necessary, but I've also been deleting the <victim-list>...</victim-list> tag block.

    So you should transform your output from something like this:

    <deadlock>

    <victim-list>

    <victimProcess id="process62a988" />

    </victim-list>

    <process-list>

    ...

    </process-list>

    <resource-list>

    ...

    </resource-list>

    </deadlock>

    To something like this:

    <deadlock-list>

    <deadlock victim="process62a988">

    <process-list>

    ...

    </process-list>

    <resource-list>

    ...

    </resource-list>

    </deadlock>

    </deadlock-list>

    Hope this helps!

  • Many, many thanks!!! Great, in-depth explanation!

  • When I execute the SQL posted by Grasshopper that starts with:

    IF OBJECT_ID('tempdb..#ZZ_DeadlockEvents2008') IS NOT NULL Drop Table #ZZ_DeadlockEvents2008

    in a Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64) instance, I get:

    Msg 402, Level 16, State 1, Line 24

    The data types datetime and time are incompatible in the add operator.

  • m60freeman (6/11/2014)


    When I execute the SQL posted by Grasshopper that starts with:

    IF OBJECT_ID('tempdb..#ZZ_DeadlockEvents2008') IS NOT NULL Drop Table #ZZ_DeadlockEvents2008

    in a Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64) instance, I get:

    Msg 402, Level 16, State 1, Line 24

    The data types datetime and time are incompatible in the add operator.

    Since you don't have 24 lines in your example query I'd guess that you probably have a problematic DDL Trigger generating the error.

  • I am scratching my head for quite a few hours now. When i run the script:

    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(max)') = 'xml_deadlock_report'

    I get invalid information for deadlocks. Example:-

    <deadlock>

    <victim-list />

    <process-list>

    It misses out on the victim-processid field and when i try to open this graph up on SSMS, i get "Failed to Initialize Control. Key cannot be null. Parameter name: key"

    This is only on 1 of the servers. Version is Microsoft SQL Server 2008 R2 (SP2) - 10.50.4000.0 (X64).

  • I am getting this on SQL SP3 and also when accessing 2008 deadlock graphs in SQL 2012 management studio.

  • The deadlock XML from Extended Events in 2008/R2 is not compatible with SSMS being able to graphically display the deadlock graph.

    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[/url]

  • Jonathan Kehayias (10/20/2014)


    The deadlock XML from Extended Events in 2008/R2 is not compatible with SSMS being able to graphically display the deadlock graph.

    Thanks for the update. Someone could become quite wealthy by creating a utility that will do this! 😉

    JT

  • SQLSentry Plan Explorer Pro already does this. You have to have a pro edition license though

    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[/url]

Viewing 15 posts - 61 through 75 (of 83 total)

You must be logged in to reply to this topic. Login to reply