MySQL Blog Archive
For the latest blogs go to
Reading the log positions of a snapshot consistently

MySQL 8.0.11 introduced a new performance schema table named log_status, which provides consistent information about MySQL server instance log positions from replication and transactional storage engines.

Used in conjunction with other MySQL 8.0 feature (the backup lock), this new feature will allow backup tools to take backup with minimal impact in DML throughput, but ensuring consistent snapshot with respect to GTIDs, replication, binary logs and transactional storage engine logs.

Backup with minimal impact in DML throughput

MySQL 8.0.3 introduced a new type of backup lock that permits DML during an on-line backup while preventing operations that could result in an inconsistent snapshot:

LOCK INSTANCE FOR BACKUP prevents files from being created, renamed, or removed. REPAIR TABLE TRUNCATE TABLE, OPTIMIZE TABLE, and account management statements are blocked. … Operations that modify InnoDB files that are not recorded in the InnoDB redo log are also blocked.

When the server instance is locked for backup, no automatic purge of binary log files and relay log files takes place as it would result in files being removed. But as an exception to the rules quoted above, new binary log files and relay log files can be created when the server instance is locked for backup (or else this would block DMLs at some point in time during the backup operation).

So far, so good! Server does not remove files… I can start copying all server files to my backup… But what about consistency? How could I known that the InnoDB LSN being copied is consistent with the binary log file being copied? How could I ensure that once restored, my replica server will continue to replicate from the exact same point as it was when I backed it up?

In order to provide server instance log positions in a consistent way to backup tools MySQL 8.0.11 introduced a new performance schema table named log_status. Querying this table (which required BACKUP_ADMIN privilege) will make the server instance to “freeze” for a very short time but enough to collect a consistent view of:
– Current binary log file name and position;
– Each replication channel relay log file name and position (from receiver thread point of view);
– InnoDB LSNs.

Note: Even though server already provided all the information in the new table by other means, this table access guarantee that the generated data refer to the same snapshot.

Here is an example in a master server:

Here is an example in a multi source replica server:

After querying this table, the backup tool should know exactly up to which point to copy from the binary log files, the relay log files and the InnoDB redo logs. Restoring these infrastructures to the logged positions shall put a server instance in a consistent state according to the moment the log_status performance schema table was queried.

Once finishing copying the logs up to the specified positions, the backup tool can unlock the instance so the automatic purges of binary log files and relay log files can proceed as usual and removing other limitations of the backup lock.