PURGE BINARY LOGS
Official PURGE BINARY LOGS syntax: delete binlogs using TO 'log_name' or BEFORE datetime_expr, replica read constraints, and SHOW BINARY LOGS commands.
Syntax
PURGE { BINARY | MASTER } LOGS
{ TO 'log_name' | BEFORE datetime_expr }Description
The PURGE BINARY LOGS statement deletes all the binary log files listed in the log index file prior to the specified log file name or date. BINARY and MASTER are synonyms. Deleted log files are also removed from the list recorded in the index file, so that the given log file becomes the first in the list.
The datetime expression is in the format YYYY-MM-DD hh:mm:ss.
If a replica is active but has yet to read from a binary log file you attempt to delete, the statement will fail with an error. However, if the replica is not connected and has yet to read from a log file you delete, the file will be deleted, but the replica will be unable to continue replicating once it connects again.
From MariaDB 11.4.3, PURGE BINARY LOGS ignores slave_connections_needed_for_purge, the minimum number of connected replicas that automatic purging requires. In MariaDB 11.4.1 and 11.4.2, PURGE BINARY LOGS BEFORE observed that limit while PURGE BINARY LOGS TO did not.
If an automatic purge has already been refused for a file because too few replicas had processed it, a manual purge of that same file is refused as well, reporting the file as the current active binary log even when it is not. This is a server bug, tracked as MDEV-41214; the misleading reason is tracked separately as MDEV-41215.
The server clears that state when a replica moves on to a new binary log file, or when slave_connections_needed_for_purge or max_binlog_total_size is assigned a value, even the value it already has. Assigning either one does not clear it while binlog_expire_logs_seconds is non-zero, because the assignment retries the automatic purge, and that retry is refused for the same file again. Set binlog_expire_logs_seconds to 0 first if you need to purge such a file manually.
This statement has no effect if the server was not started with the --log-bin option to enable binary logging.
To list the binary log files on the server, use SHOW BINARY LOGS. To see which files they are reading, use SHOW REPLICA STATUS. You can only delete the files that are older than the oldest file that is used by the slaves.
To delete all binary log files, use RESET MASTER. To move to a new log file (for example if you want to remove the current log file), use FLUSH LOGS before you execute PURGE LOGS.
If the expire_logs_days server system variable is not set to 0, the server automatically deletes binary log files after the given number of days. From MariaDB 10.6, the binlog_expire_logs_seconds variable allows more precise control over binlog deletion, and takes precedence if both are non-zero.
Requires the BINLOG ADMIN privilege.
Examples
See Also
This page is licensed: GPLv2, originally from fill_help_tables.sql
Last updated
Was this helpful?

