For a backup to proceed properly, certain types of server activity must be blocked, so the backup system incorporates a commit blocker and a Backup Metadata Lock.
The commit blocker has these properties:
Changes for nontransactional tables are blocked.
Changes for transactional tables are not blocked, but only changes that have been committed when the backup occurs appear in the backup. Changes that occur during the backup operation are not included in the backup image.
When a backup or restore operation is in progress, it is not allowable to modify the structure of database objects. Consequently, during the operation, the Backup Metadata Lock blocks statements that change database metadata from executing. A backup image stores metadata for the following types of objects: databases, tables, views, stored programs (functions, procedures, triggers, events), and privileges. This requires that the following metadata changes be frozen during backup operation:
Databases being backed up should not disappear or be changed.
For BACKUP DATABASE * ...
, new databases
should not appear.
The list of objects inside each database should not change.
Metadata for objects in the databases should not change.
The set of privileges for each database should not change.
User accounts for which privileges are stored should not disappear or change.
To achieve these requirements, the Backup Metadata Lock blocks the following statements:
DROP DATABASE/TABLE/VIEW/FUNCTION/PROCEDURE/EVENT/TRIGGER/INDEX/ USER/TABLESPACE CREATE DATABASE/TABLE/VIEW/FUNCTION/PROCEDURE/EVENT/TRIGGER/INDEX ALTER DATABASE/TABLE/VIEW/FUNCTION/PROCEDURE/EVENT/TABLESPACE RENAME TABLE/USER GRANT/REVOKE ANALYZE/CHECK/TRUNCATE/OPTIMIZE/REPAIR TABLE
Currently, all instances of statements that change metadata are blocked, even for database or table objects that are not included in the backup. Eventually, the goal is to block only metadata-changing statements that pertain to objects in the backup.
Blocking works in both directions. A backup or restore blocks DDL statements, but if a backup or restore operation is initiated while DDL statements are in progress, the operation waits until the statements have finished.