The BACKUP LOCK command was introduced in MariaDB 10.4.2.
BACKUP LOCK blocks a table from DDL statements. This is mainly intended to be used by tools like mariabackup that need to ensure there are no DDLs on a table while the table files are opened. For example, for an Aria table that stores data in 3 files with extensions .frm, .MAI and .MAD. Normal read/write operations can continue as normal.
To lock a table:
BACKUP LOCK table_name
To unlock a table:
BACKUP UNLOCK
BACKUP LOCK [database.]table_name; - Open all files related to a table (for example, t.frm, t.MAI and t.MYD) BACKUP UNLOCK; - Copy data - Close files
This ensures that all files are from the same generation, that is created at the same time by the MariaDB server.
BACKUP LOCK requires the RELOAD
privilege.
BACKUP LOCK
should be held for as short a time as possible by the backup tool. The time to take an uncontested lock is very short! One can easily do 50,000 locks/unlocks per second on low end hardware. BACKUP LOCK
. MDLSHARED_HIGH_PRIO
MDL lock on the table object, which protects the table from any DDL operations.
© 2019 MariaDB
Licensed under the Creative Commons Attribution 3.0 Unported License and the GNU Free Documentation License.
https://mariadb.com/kb/en/backup-lock/