- Run `SHOW ENGINE INNODB STATUS;` to get the latest deadlock information. This command returns a detailed report that includes the last detected deadlock and the transactions involved.
- Focus on the `LATEST DETECTED DEADLOCK` section to understand which queries were involved and the tables they were accessing.
- Enable the slow query log if it's not already enabled: `SET GLOBAL slowquerylog = 'ON';`.
- Set the long query time to capture slow queries: `SET GLOBAL longquerytime = 1;` (captures queries longer than 1 second, adjust as needed).
- Review the slow query log file. The location can be found by querying: `SHOW VARIABLES LIKE 'slowquerylog_file';`.
- Run `SELECT * FROM INFORMATIONSCHEMA.INNODBLOCK_WAITS;` to identify queries that are currently waiting for locks.
- Based on the information gathered from steps 1-4, specifically look to optimize the queries involved in the deadlock. This could involve indexing columns used in joins and where clauses or splitting large transactions into smaller ones.
- For ongoing monitoring, you can periodically check `SHOW FULL PROCESSLIST;` to see if there are queries that are stuck or running for a long time, which might indicate locking issues.
Let Dr. Droid create custom investigation plans for your infrastructure.
Book Demo