Enable innodb_print_all_deadlocks ParameterAt Percona Managed Services, sometimes clients’ applications face deadlock situations and need all historic deadlock information for application tuning.

We could get the LATEST DETECTED DEADLOCK from SHOW ENGINE INNODB STATUSG:

But how could we view all past deadlock information?

We could enable innodb_print_all_deadlocks,  and all deadlocks in InnoDB user transactions will be recorded in the MySQL error log.

Let‘s start the test.

Create the test database and insert some test data

 

Deadlock simulation on record 1 of table t  (i=1)

This is expected.

Enable innodb_print_all_deadlocks  dynamic parameter

 

If we run the deadlock simulation on record 1 of table t  ( i=1),  we‘ll get the deadlock error both in show engine InnoDB status G  and MySQL error log.

The deadlock information in MySQL error log is similar to show engine InnoDB status G, like below:

 

Let‘s simulate another deadlock by dealing with record 2 (i=2)

Deadlock simulation on record 2 of table t (i=2):

SHOW ENGINE INNODB STATUS would just keep the last detected deadlock information.

 

We could get all history deadlock information from the MySQL error log.

 

Notes: on MySQL 8 (especially in >8.0.4), it’s better to set log_error_verbosity = 3  (default  log_error_verbosity = 2) as well, otherwise, you will get partial deadlock outputs in the error log, which are not really usable.

Please see details in this bug report https://bugs.mysql.com/bug.php?id=108891 that Agustín G  filed.

Conclusion

Innodb_print_all_deadlocks dynamic parameter has been available since MySQL 5.6, and we can enable it to get all the deadlock information in the MySQL error log file.

Hope this is helpful for your application tuning.

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments