MK-PURGE-LOGS(1)

πŸ“¦
version 7540 Β· 3 versions
, in fedora 43

πŸ’– MK-PURGE-LOGS πŸ’–

okay bestie, so this whole page is from the User Contributed Perl Documentation collection, and it's all about mk-purge-logs(1). she's a Maatkit girlie whose whole personality is yeeting binary logs off your MySQL master. let's get into it πŸŽ€


✨ NAME ✨

mk-purge-logs β€” purges binary logs on a master based on purge rules. no cap, that's the entire job description. πŸ’…


🌸 SYNOPSIS 🌸

Usage: mk-purge-logs [OPTION...] DSN

mk-purge-logs purges binary logs on a MySQL server, based on purge rules.

Print and purge all unused binary logs on master:

mk-purge-logs --print --purge h=master

Silently purge oldest binary logs on master until their total size is less than 1M:

mk-purge-logs --purge-rules total_size --total-size 1M h=master

Purge oldest, unused binary logs on master until their total size is less than 500k, print information about work done:

mk-purge-logs --purge-rules unused,total_size --total-size 500k \
  --verbose h=master

😬 RISKS 😬

bestie, this section is here so you know what you're getting into β€” both the risks that come from what the tool is (like, read-only tools vs. read-write tools) and the risks that come from bugs. no hiding it, periodt.

mk-purge-logs purges (deletes) binary logs on a master based on --purge-rules when --purge is specified. Specifying the wrong --purge-rules could delete binary logs that are still needed. 🫠 that's the scary part, so pls read your rules twice.

At the time of this release, we know of no bugs that could cause serious harm to users. πŸŽ‰

The authoritative source for updated information is always the online issue tracking system. Issues that affect this tool will be marked as such. You can see a list of such issues at the following URL: <http://www.maatkit.org/bugs/mk-purge-logs>.

See also BUGS for more information on filing bugs and getting help.


πŸ’œ DESCRIPTION πŸ’œ

mk-purge-logs purges binary logs on a master based on --purge-rules by executing PURGE BINARY LOGS TO. that's the whole vibe. simple, iconic, slightly terrifying. πŸ”₯


πŸ‘‘ OPTIONS πŸ‘‘

Specify at least one of --purge or --print. (yes, at least one, she's not asking twice πŸ’…)

This tool accepts additional command-line arguments. Refer to the SYNOPSIS and usage information for details.

  • --ask-pass β€” Prompt for a password when connecting to MySQL. (group: Connection)
  • --config β€” Read this comma-separated list of config files; if specified, this must be the first option on the command line. (type: Array)
  • --defaults-file β€” Only read mysql options from the given file. You must give an absolute pathname. (short form: -F; type: string; group: Connection)
  • --dry-run β€” Print but do not execute the --purge statement (disables --purge).

Specifying this option allows you to test what mk-purge-logs would do if --purge were specified without --dry-run. The SQL statement for --purge is printed to STDOUT, like:

This is a dry-run.  The following SQL statement would be executed
by specifying --purge without --dry-run:
PURGE BINARY LOGS TO ? mysql-bin.000003

The first line lets you know that --dry-run is in effect and the line after it is the SQL statement that would be executed on the server with the ? replaced by the binary log file name that follows it.

See also --print.

  • --help β€” Show help and exit.
  • --password β€” Password to use when connecting. (short form: -p; type: string; group: Connection)
  • --port β€” Port number to use for connection. (short form: -P; type: int; group: Connection)
  • --print β€” Print which binary logs --purge will purge.

This option prints each binary log file name and its size to STDOUT that would be purged if all the --purge-rules pass and --purge is specified. Purging uses the MySQL PURGE BINARY LOGS TO command which only specifies the binary log file name to purge to, not the binary logs before it. This option will print the binary logs before the purge to binary log.

See also --dry-run.

  • --purge β€” Purge (delete) binary logs that match all --purge-rules. The server's master binary logs are purged using PURGE BINARY LOGS when this option is specified and all --purge-rules pass. Else, no binary logs are purged.

Specify --print to see which binary logs are purged and their sizes, else all binary logs are purged silently unless there is an error.

See also --dry-run.

  • --purge-rules β€” Match binary logs that pass all of the specified rules. The rules are mutually inclusive, so only binary logs that pass all rules are purged. (type: Hash; default: unused)

Some rules, like total_size, require an extra option to specify their value.

  • total_size β€” Purge oldest binary logs until the total size of all binary logs is less than --total-size. SHOW BINARY LOGS lists the size of each binary log. If the total of these sizes is greater than --total-size, then the oldest binary logs are purged until the total size is less than or equal to --total-size.
  • unused β€” Purge binary logs that are no longer being read by any slaves. When this rule is specified, mk-purge-logs will recurse to the server's first-level slaves (i.e. only direct slaves of the server) and SHOW SLAVE STATUS to find which master binary logs they are reading. Master binary logs not being read by any slaves are unused and will be purged.
  • --recursion-method β€” Preferred recursion method for discovering slaves. (type: string)

Possible methods are:

  • processlist β€” uses SHOW PROCESSLIST
  • hosts β€” uses SHOW SLAVE HOSTS

The processlist method is preferred because SHOW SLAVE HOSTS is not reliable. However, the hosts method is required if the server uses a non-standard port (not 3306). Usually mk-purge-logs does the right thing and finds the slaves, but you may give a preferred method and it will be used first. If it doesn't find any slaves, the other methods will be tried.

  • --set-vars β€” Set these MySQL variables. Immediately after connecting to MySQL, this string will be appended to SET and executed. (type: string; default: wait_timeout=10000; group: Connection)
  • --socket β€” Socket file to use for connection. (short form: -S; type: string; group: Connection)
  • --total-size β€” Purge oldest binary logs until their total size is less than this amount. (type: size)

This option specifies the value for the --purge-rules total_size value.

  • --user β€” User for login if not current user. (short form: -u; type: string; group: Connection)
  • --verbose β€” Print information about binary logs found and purged. By default mk-purge-logs operates silently, except for errors which are printed to STDERR. Specifying this option prints extra information to STDOUT about what the tool is doing. (short form: -v; default: 0)
  • --version β€” Show version and exit.

πŸ¦‹ DSN OPTIONS πŸ¦‹

These DSN options are used to create a DSN. Each option is given like option=value. The options are case-sensitive, so P and p are not the same option. There cannot be whitespace before or after the = and if the value contains whitespace it must be quoted. DSN options are comma-separated. See the maatkit manpage for full details.

  • A β€” Default character set. (dsn: charset; copy: yes)
  • D β€” Default database. (dsn: database; copy: yes)
  • F β€” Only read default options from the given file (dsn: mysql_read_default_file; copy: yes)
  • h β€” Connect to host. (dsn: host; copy: yes)
  • p β€” Password to use when connecting. (dsn: password; copy: yes)
  • P β€” Port number to use for connection. (dsn: port; copy: yes)
  • S β€” Socket file to use for connection. (dsn: mysql_socket; copy: yes)
  • u β€” User for login if not current user. (dsn: user; copy: yes)

🌈 DOWNLOADING 🌈

You can download Maatkit from Google Code at <http://code.google.com/p/maatkit/>, or you can get any of the tools easily with a command like the following:

wget http://www.maatkit.org/get/toolname
or
wget http://www.maatkit.org/trunk/toolname

Where toolname can be replaced with the name (or fragment of a name) of any of the Maatkit tools. Once downloaded, they're ready to run; no installation is needed. The first URL gets the latest released version of the tool, and the second gets the latest trunk code from Subversion. obsessed, truly zero setup 😌


🧚 ENVIRONMENT 🧚

The environment variable MKDEBUG enables verbose debugging output in all of the Maatkit tools:

MKDEBUG=1 mk-....

⭐ SYSTEM REQUIREMENTS ⭐

You need Perl, DBI, DBD::mysql, and some core packages that ought to be installed in any reasonably new version of Perl.


πŸ’€ BUGS πŸ’€

For a list of known bugs see <http://www.maatkit.org/bugs/mk-purge-logs>.

Please use Google Code Issues and Groups to report bugs or request support: <http://code.google.com/p/maatkit/>. You can also join #maatkit on Freenode to discuss Maatkit.

Please include the complete command-line used to reproduce the problem you are seeing, the version of all MySQL servers involved, the complete output of the tool when run with --version, and if possible, debugging output produced by running with the MKDEBUG=1 environment variable. (basically: give us the receipts bestie 🧾)


This program is copyright 2010-2011 Percona Inc. Feedback and improvements are welcome.

THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2; OR the Perl Artistic License. On UNIX and similar systems, you can issue man perlgpl or man perlartistic to read these licenses.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.


πŸ’œ AUTHOR πŸ’œ

Daniel Nichter, Baron Schwartz


πŸ‘‘ ABOUT MAATKIT πŸ‘‘

This tool is part of Maatkit, a toolkit for power users of MySQL. Maatkit was created by Baron Schwartz; Baron and Daniel Nichter are the primary code contributors. Both are employed by Percona. Financial support for Maatkit development is primarily provided by Percona and its clients.


πŸŽ€ VERSION πŸŽ€

This manual page documents Ver 0.9.0 Distrib 7540 $Revision: 7531 $.


and that's the whole page, bestie!! this little manual page is living its best life on perl v5.42.0, dated 2025-07-24, and yes she is still filed under MK-PURGE-LOGS(1) in the User Contributed Perl Documentation section. go purge responsibly, mwah πŸ’–βœ¨

πŸ“¦ where this page comes from