Over the past few years, I have presented a number of sessions on Extended Events. As I prepare to present the topic a few more times in the coming weeks, I thought I would do a blog post on one particular event that has been very helpful to me when working with issues in a production environment. That event is related to the Deadlock graph.
There are a number of ways you can capture this. Profiler has been a very good and very effective way of capturing the Deadlock graph. However, starting with SQL Server 2008, there is now another option, Extended Events. RedGate also puts out a great tool named SQL Monitor that can be used.
I am not going to get into the ins and outs of Extended Events in the post, I am simply going to cover how to use Extended Events to capture the deadlock graph. There are a total of five events that have the word “deadlock” in the event name.
Let’s take a moment and quickly go over each of these five events.
database_xml_deadlock_report – This will be the same as the xml_deadlock_report, with one noticeable exception. The xml_deadlock_report event has an additional tab, while the database_xml_deadlock_report does not have this. This tab is where we will find the graph.
xml_deadlock_report – This is very similar to the database_xml_deadlock_report with the addition of the deadlock graph. To see the deadlock graph, simply click on the Deadlock tab.
lock_deadlock – “Occurs when an attempt to acquire a lock is canceled for the victim of a deadlock.” This definition is from SQL Server. Of the events we have discussed so far, this event has the most data points.
lock_deadlock_chain – “Occurs when an attempt to acquire a lock generates a deadlock. This event is raised for each participant in the deadlock.” This definition is from SQL Server.
scheduler_monitor_deadlock_ring_buffer_recorded – “The session tracks other useful events which makes it easy to trace back the series of events which led to the deadlocked schedulers condition!” – From www.troubleshootingsql.com
Since this post is about the deadlock graph, we will focus on the xml_deadlock_report event. As mentioned before, this is the event you will need to capture the deadlock graph. There are two points to look at, the column is “XML_report” and the other is the graph itself. In the image below you will see that there are two places to look at the actual XML. If you do not see this column in the grid, you can right click on it in the details at the bottom and then click “Show column in table”. It might be very challenging to read due to formatting. If you are having a difficult time reading the XML, this online formatting tool can be very helpful to get good formatting.
This is the actual XML that is used to build the graph. This is quite a bit of useful information in the XML. You can see the victim query as well as many other good data points. The victim process can be found in the “victim-list” node. In the image below, you will then see two processes, the first one listed matches the victim process id. The UPDATE just below it is the T-SQL that was chosen as the victim.
The deadlock graph, while initially looks very useful, it does have a significant limitation. The query with the blue X on it is the victim. If you float your cursor above it, the query will then appear in a context pop up.
If you left click and hold one shapes you can move it around. This can be useful when there are more shapes than you see above. Now on to the limitation, you can’t zoom it. Without this, it can be difficult to see some of the details.
Here are just a few interesting deadlock graphs I have been able to capture.
While these are kind of interesting to look at, the scary part is what caused these. These were all caused by a single stored procedure. Now you have the graph. I think now the fun is just beginning trying to figure out what is causing this and a solution.
Thank you for stopping by my blog.