How can I check if a MySQL Table is already locked?
Posted on 2008-11-16
I'm having an issue with locked tables and blocking I/O.
Is there a way to query the MySQL server first, asking if a particular table is locked, before trying to query the locked table?
I have a few TCL apps, that are time sensitive, and I would rather be able to set a timer callback to retry the SQL command, than to wait in blocking I/O while the table is locked.
The tables that I'm checking are, in the millions of rows per table, and so while backups run, the table can be locked for up to 6-7 minutes. But I can't have blocking I/O for that long, same as on a webpage, a user isn't going to wait that long for the page to load, but they would most likely be satisfied with a message that says the server is busy and to try again in a few moments.
I'm using MySQLtcl under TCL, but I would like a solution for PHP as well.
I've read a few cases where you can use a GET_LOCK(), but that isn't feasible in my case, as I don't need to create a lock, I just want to check to see if it's locked before querying.