BACKUP LOCK
You are viewing an old version of this article. View
the current version here.
BACKUP LOCK blocks a table from DDL statements. This is mainly to be used by tools like mariabackup that needs to ensure that there are no DDL's on a table while the table files are opened. For example for an Aria table stores data in 3 files with extensions .frm, .MAI and .MAD. Normal read/write operations can continue as normal.
Syntax
To lock table:
BACKUP LOCK table_name
To unlock table:
BACKUP UNLOCK
Usage in a backup tool
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 (was created at the same time by the MariaDB server).
Privileges
BACKUP LOCK requires the RELOAD
privilege.
Notes
- The idea is that the
BACKUP LOCK
should be hold as short 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. - One should use different connections for BACKUP STAGE commands and
BACKUP LOCK
.
Implementation
- Internally BACKUP LOCK is implemented by taking a
MDLSHARED_HIGH_PRIO
MDL lock on the table object, which protects the table from any DDL operations.
See also
- BACKUP STAGE
- MDEV-17309 - BACKUP LOCK: DDL locking of tables during backup
Comments
Comments loading...
Content reproduced on this site is the property of its respective owners,
and this content is not reviewed in advance by MariaDB. The views, information and opinions
expressed by this content do not necessarily represent those of MariaDB or any other party.