EmergencyEMERGENCY? Get 24/7 Help Now!

Logging Deadlock errors

 | September 19, 2012 |  Posted In: Insight for Developers, MySQL


The principal source of information for InnoDB diagnostics is the output of SHOW ENGINE INNODB STATUS but there are some sections that are not very useful. For example, LATEST DETECTED DEADLOCK only shows, as the name implies, the latest error detected. If you have 100 deadlocks per minute you will be able to see only the latest one and that is not very helpful when you are debugging your application code. Continuing my series of blog posts about Percona Toolkit, in this case I’m going to talk about pt-deadlock-logger.


The tool is very simple and useful. It monitors the output of SHOW ENGINE INNODB STATUS and log the new deadlocks to a file or to a table that we can later review. Let’s see how it works with an example.

The basic command to use is:

Without any more options the tool will start to show on STDOUT the deadlocks that are happening on our database. This tool is usually run for a long period of time that you can specify with –run-time so sometimes make sense to store the information on a file (–log) or on a table (–dest) for later review. In this example we are going to store the deadlocks information on a table.

First we have to create the destination table:

Now, we can start to log the deadlocks in our database:

After some time, we can check the deadlock information in our table:

We can see the two queries that caused the deadlock with the information like user, hostname, thread id and which one was the victim of the deadlock. You can group by server and timestamp to get all events that correspond to the same deadlock.

Another trick, with infrastructures of more than one server is possible to use the tool to have a central repository with all the deadlocks. We just need to run the tool on every node and configure it to store logs on a centralized database.

In MySQL 5.6 will be possible to log all deadlocks on error log using innodb_print_all_deadlocks parameter.

Miguel Angel Nieto

Miguel joined Percona in October 2011. He has worked as a System Administrator for a Free Software consultant and in the supporting area of the biggest hosting company in Spain. His current focus is improving MySQL and helping the community of Free Software to grow.


Leave a Reply


Percona’s widely read Percona Data Performance blog highlights our expertise in enterprise-class software, support, consulting and managed services solutions for both MySQL® and MongoDB® across traditional and cloud-based platforms. The decades of experience represented by our consultants is found daily in numerous and relevant blog posts.

Besides specific database help, the blog also provides notices on upcoming events and webinars.
Want to get weekly updates listing the latest blog posts? Subscribe to our blog now! Submit your email address below and we’ll send you an update every Friday at 1pm ET.

No, thank you. Please do not ask me again.