We are trying to diagnose a deadlock problem MySQL 5.0. Currently all the tables are MyISAM tables and so all the locks are table locks. We have a good table_locks_waited
to table_locks_immediate
ratio (lower than 1:1000), but within a couple of minutes we get a couple of deadlocks. This only happens on Amazon EC2 but not any of our other servers.
Is there a way to log all the queries that could not obtain a table lock immediately? We want to see all the queries that contributed to the table_locks_waited
number.
Try watching the queries and locks in real time using this command:
If the locking happens for any length of time, you should get a good idea of what is going on.
In the slow log, one of the fields displayed is the Lock Time
Here is a sample with two queries that were logged
Please note the Lock_time: field.
CAVEAT
In MySQL 5.1+ the field appears in the default mysql.slow_log table
Either way, you can get a hold of the lock time of any query