join the MSSQLTips community

Today's Site Sponsor


 

SQL Compare quickly and easily compares and synchronizes SQL Server database schemas
 



Ever feel like a human database, trying to remember...

Capturing SQL Server Deadlock Information in XML Format

Written By: Jeremy Kadlec -- 4/30/2007 -- read/post comments -- print -- Bookmark and Share

Rating: (not rated yet) Rate

Problem
In your recent tips on SQL Server dead locks (How To: Graphical Deadlock Chain and Deadlock Priority Configuration) I can see the value of using Profiler to capture the process related information.  Do any other options exist in Profiler to capture the information is an easier format that I can review?  If so, what is the format and how can I begin to take advantages of this configuration in Profiler?

Solution
SQL Server 2005 Profiler has the ability to capture the deadlock related information as XML files which can be analyzed to determine the overall locking and blocking issue.  Capturing this additional information can be beneficial if you experience long locking and blocking chains frequently. 

SQL Server 2005 Profiler - General Tab

Specify the name, template and save location (table or file).

 

SQL Server 2005 Profiler - Events Selection Tab

Specify the deadlock graph, Lock:Deadlock and Lock:Deadlock Chain events in addition to any other counters desired.

 

SQL Server 2005 Profiler - Events Extraction Settings Tab

Enable the 'Deadlock XML' check box and when you are prompted for the file location, browse to the needed directory and provide a file name.  Once you have verified all of the configurations from all 3 tabs,                           press the 'Run' button to start Profiler.

 

SQL Server 2005 Profiler Results

In this example, 2 processes are trying to update the same sets of data in two tables.  One becomes a deadlock and the other succeeds.  From the image below, you can see a portion of the deadlock chain.

 

XML Output

Once the Profiler session is stopped, then go and review the XML file specified on the Events Extraction Settings Tab.  If you open the file with Notepad or XML Notepad, you can review the XML corresponding to the Deadlock chain that occurred.  To download the example XML file click on DeadlockExample.xdl.

 

Deadlock - Graphical Representation

If you happen to double click on the XML file from above without reviewing it in Notepad (or XML Notepad), by default SQL Server 2005 Management Studio will load the file into a separate query window and give you a graphical representation of the deadlock similar to the Profiler representation. 

 

 

XML Deadlock File Considerations

  • The XML Deadlocks feature gives you the ability to capture the deadlock related information and review the deadlocks independent of the Profiler interface.
  • Each of the deadlock files can be analyzed in order to determine trends with the deadlocks on your SQL Server.
  • Each deadlock situation can be stored in a separate file for per deadlock analysis.
  • The XML format gives you the ability to programmatically review the deadlocks.

Next Steps

Readers Who Read This Tip Also Read Free Live Webcast Comment or Ask Questions About This Tip


Sponsor Information
Free SQL Server performance monitoring dashboard – Idera SQL check

Quickly and accurately deploy database changes with Red Gate's SQL Compare – the industry standard comparison and deployment tool.

You don't know, what you don't know about SQL Server... Customized Consulting and Training

Valuable SharePoint resources all for free – Check it out

Learn SQL Server 2008, Performance Tuning, Development, Administration, DR, Replication and more from these web casts


Get Our Tips Newsletter

We keep 50,000+ SQL Server professionals informed.

Idera - SQL diagnostic manager

Idera SQL diagnostic manager is an award-winning performance monitoring solution for SQL Server that provides agent-less, real-time monitoring, customizable alerting, and extensive historical reporting. SQL diagnostic manager also puts must-have troubleshooting information at the DBA’s fingertips such as worst-performing code, long-running or frequently run queries, and blocking or blocked sessions.

Download now!



More SQL Server Tools
SQL secure

SQL diagnostic manager

SQL Compare

SQL Data Generator

SQL safe backup




Copyright (c) 2006-2010 Edgewood Solutions, LLC All rights reserved
privacy statement | disclaimer | copyright | advertise | write for mssqltips | feedback | about
Some names and products listed are the registered trademarks of their respective owners.


CareerQandA.com | MSSharePointTips.com | MSSQLTips.com