Bug #27850 | mysqldump --single-transaction does not work if TRUNCATE/DROP/RENAME/ALTER | ||
---|---|---|---|
Submitted: | 16 Apr 2007 13:05 | Modified: | 10 Sep 2007 17:39 |
Reporter: | Guilhem Bichot | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Documentation | Severity: | S3 (Non-critical) |
Version: | all | OS: | Any |
Assigned to: | Paul DuBois | CPU Architecture: | Any |
[16 Apr 2007 13:05]
Guilhem Bichot
[10 Sep 2007 17:39]
Paul DuBois
Thank you for your bug report. This issue has been addressed in the documentation. The updated documentation will appear on our website shortly, and will be included in the next release of the relevant products. The --single-transaction description now includes this paragraph: While a --single-transaction dump is in process, to ensure a valid dump file (correct table contents and binary log position), no other connection should use the following statements: ALTER TABLE, DROP TABLE, RENAME TABLE, TRUNCATE TABLE. A consistent read is not isolated from those statements, so use of them on a table to be dumped can cause the SELECT performed by mysqldump to retrieve the table contents to obtain incorrect contents or fail.
[20 Nov 2007 9:25]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/38115 ChangeSet@1.2561, 2007-11-20 10:25:07+01:00, guilhem@gbichot4.local +1 -0 BUG#27850 "mysqldump --single-transaction does not work if TRUNCATE/DROP/RENAME/ALTER": this has already been closed by a note in the manual, now we complete this by a note in "mysqldump --help"
[7 Dec 2007 23:07]
Bugs System
Pushed into 6.0.5-alpha
[7 Dec 2007 23:09]
Bugs System
Pushed into 5.1.23-rc
[7 Dec 2007 23:10]
Bugs System
Pushed into 5.0.54
[23 Jan 2009 21:43]
Bill Karwin
It seems that FLUSH TABLES WITH READ LOCK causes concurrent ALTER, DROP, RENAME, and TRUNCATE commands to hang, waiting for the lock to release. That FLUSH command is documented that it acquires a "global read lock." This phrase is also used in the mysqldump --lock-all-tables option. Can you confirm that using mysqldump --lock-all-tables does the same thing as FLUSH TABLES WITH READ LOCK? If so, it would be effective at blocking concurrent clients from performing ALTER, DROP, RENAME, or TRUNCATE. This would seem to be a good solution to ensure consistent backups.
[26 Jan 2009 10:06]
Guilhem Bichot
Hi. --lock-all-tables calls FLUSH TABLES WITH READ LOCK. Thus it is expected to block ALTER, DROP, RENAME, or TRUNCATE (unless there is a bug or I'm wrong). However, --lock-all-tables --single-transaction cannot work (mysqldump throws an error message): because lock-all-tables locks all tables of the server against writes for the duration of the backup, whereas single-transaction is intended to let writes happen during the backup (by using a consistent-read SELECT in a transaction), they are incompatible in nature.
[23 Dec 2010 14:23]
Mubashar Ahmad
@Guilhem Bichot you said: Hi. --lock-all-tables calls FLUSH TABLES WITH READ LOCK. Thus it is expected to block ALTER, DROP, RENAME, or TRUNCATE (unless there is a bug or I'm wrong). ---------------------------- Can you please tell us how it can be confirmed; I am new to mysql so i dont know exactly how can i confirm it without knowing it i may taking inconsistent backups. Thanks
[3 Jan 2011 10:15]
Guilhem Bichot
To Mubashar Ahmad: http://dev.mysql.com/doc/refman/5.5/en/mysqldump.html says "--lock-all-tables, -x Lock all tables across all databases. This is achieved by acquiring a global read lock for the duration of the whole dump. This option automatically turns off --single-transaction and --lock-tables. " This global read lock blocks any modification to tables, using command "FLUSH TABLES WITH READ LOCK". FLUSH TABLES WITH READ LOCK is documented in http://dev.mysql.com/doc/refman/5.5/en/flush.html "Closes all open tables and locks all tables for all databases with a global read lock until you explicitly release the lock by executing UNLOCK TABLES. This is a very convenient way to get backups if you have a file system such as Veritas or ZFS that can take snapshots in time. " So in theory it should work as I wrote earlier. For additional safety, you can surely try a backup and verify: create a large table so that mysqldump takes several seconds to dump it; while mysqldump is running, issue another statement (INSERT, TRUNCATE etc) on the table and verify that it blocks until mysqldump ends.