PT-FIND(1)
πΈ NAME πΈ β pt-find(1)
Okay bestie, this is pt-find(1) from the User Contributed Perl Documentation, and it's literally the βfind MySQL tables and execute actions, like GNU findβ tool. π«Ά No cap: pt-find finds MySQL tables and executes actions, like GNU find.
β¨ SYNOPSIS β¨
Usage: pt-find [OPTIONS] [DATABASES]
pt-find searches for MySQL tables and executes actions, like GNU find. The default action is to print the database and table name.
Find all tables created more than a day ago, which use the MyISAM engine, and print their names:
pt-find --ctime +1 --engine MyISAM
Find MyISAM tables and convert them to InnoDB:
pt-find --engine MyISAM --exec "ALTER TABLE %D.%N ENGINE=InnoDB"
Find tables created by a process that no longer exists, following the name_sid_pid naming convention, and remove them:
pt-find --connection-id '\D_\d+_(\d+)$' --server-id '\D_(\d+)_\d+$' --exec-plus "DROP TABLE %s"
Find empty tables in the test and junk databases, and delete them:
pt-find --empty junk test --exec-plus "DROP TABLE %s"
Find tables more than five gigabytes in total size:
pt-find --tablesize +5G
Find all tables and print their total data and index size, and sort largest tables first (sort is a different program, by the way).
pt-find --printf "%T\t%D.%N\n" | sort -rn
As above, but this time, insert the data back into the database for posterity:
pt-find --noquote --exec "INSERT INTO sysdata.tblsize(db, tbl, size) VALUES('%D', '%N', %T)"
π¨ RISKS π¨
Percona Toolkit is mature, proven in the real world, and well tested, but all database tools can pose a risk to the system and the database server. Before using this tool, please:
- Read the tool's documentation
- Review the tool's known "BUGS"
- Test the tool on a non-production server
- Backup your production server and verify the backups
Real talk: this is the vibe-check-before-you-wreck-check part. Do the four things. Your future self will thank you. π
π« DESCRIPTION π«
pt-find looks for MySQL tables that pass the tests you specify, and executes the actions you specify. The default action is to print the database and table name to STDOUT.
pt-find is simpler than GNU find. It doesn't allow you to specify complicated expressions on the command line.
pt-find uses SHOW TABLES when possible, and SHOW TABLE STATUS when needed.
π§ OPTION TYPES π§
There are three types of options: normal options, which determine some behavior or setting; tests, which determine whether a table should be included in the list of tables found; and actions, which do something to the tables pt-find finds.
pt-find uses standard Getopt::Long option parsing, so you should use double dashes in front of long option names, unlike GNU find.
π OPTIONS π
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.--[no]buffer-stdoutβ default: yes β Enables STDOUT buffering. Disable this option if you want to see live progress when using output post-processing tools such asteeorkubectl logs.--case-insensitiveβ Specifies that all regular expression searches are case-insensitive.--charsetβ short form:-A; type: string β Default character set. If the value isutf8, sets Perl'sbinmodeon STDOUT to utf8, passes themysql_enable_utf8option toDBD::mysql, and runsSET NAMES UTF8after connecting to MySQL. Any other value setsbinmodeon STDOUT without the utf8 layer, and runsSET NAMESafter connecting to MySQL.--configβ type: Array β Read this comma-separated list of config files; if specified, this must be the first option on the command line.--databaseβ short form:-D; type: string β Connect to this database.--day-startβ Measure times (for--mmin, etc) from the beginning of today rather than from the current time.--defaults-fileβ short form:-F; type: string β Only read mysql options from the given file. You must give an absolute pathname.--helpβ Show help and exit.--hostβ short form:-h; type: string β Connect to host.--mysql_sslβ short form:-s; type: int β Create SSL MySQL connection.--orβ Combine tests with OR, not AND.
By default, tests are evaluated as though there were an AND between them. This option switches it to OR.
Option parsing is not implemented by pt-find itself, so you cannot specify complicated expressions with parentheses and mixtures of OR and AND.
--passwordβ short form:-p; type: string β Password to use when connecting. If password contains commas they must be escaped with a backslash:exam\,ple.--pidβ type: string β Create the given PID file. The tool won't start if the PID file already exists and the PID it contains is different than the current PID. However, if the PID file exists and the PID it contains is no longer running, the tool will overwrite the PID file with the current PID. The PID file is removed automatically when the tool exits.--portβ short form:-P; type: int β Port number to use for connection.--[no]quoteβ default: yes β Quotes MySQL identifier names with MySQL's standard backtick character.
Quoting happens after tests are run, and before actions are run.
--set-varsβ type: Array β Set the MySQL variables in this comma-separated list of"variable=value"pairs.
By default, the tool sets:
wait_timeout=10000
Variables specified on the command line override these defaults. For example, specifying --set-vars wait_timeout=500 overrides the default value of 10000.
The tool prints a warning and continues if a variable cannot be set.
--socketβ short form:-S; type: string β Socket file to use for connection.--userβ short form:-u; type: string β User for login if not current user.--versionβ Show version and exit.--[no]version-checkβ default: yes β Check for the latest version of Percona Toolkit, MySQL, and other programs.
This is a standard "check for updates automatically" feature, with two additional features. First, the tool checks its own version and also the versions of the following software: operating system, Percona Monitoring and Management (PMM), MySQL, Perl, MySQL driver for Perl (DBD::mysql), and Percona Toolkit. Second, it checks for and warns about versions with known problems. For example, MySQL 5.5.25 had a critical bug and was re-released as 5.5.25a.
A secure connection to Perconaβs Version Check database server is done to perform these checks. Each request is logged by the server, including software version numbers and unique ID of the checked system. The ID is generated by the Percona Toolkit installation script or when the Version Check database call is done for the first time.
Any updates or known problems are printed to STDOUT before the tool's normal output. This feature should never interfere with the normal operation of the tool.
For more information, visit https://www.percona.com/doc/percona-toolkit/LATEST/version-check.html.
π§ͺ TESTS π§ͺ
Most tests check some criterion against a column of SHOW TABLE STATUS output. Numeric arguments can be specified as +n for greater than n, -n for less than n, and n for exactly n. All numeric options can take an optional suffix multiplier of k, M or G (1_024, 1_048_576, and 1_073_741_824 respectively). All patterns are Perl regular expressions (see man perlre) unless specified as SQL LIKE patterns.
Dates and times are all measured relative to the same instant, when pt-find first asks the database server what time it is. All date and time manipulation is done in SQL, so if you say to find tables modified 5 days ago, that translates to SELECT DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 5 DAY). If you specify --day-start, of course it's relative to CURRENT_DATE instead.
However, table sizes and other metrics are not consistent at an instant in time. It can take some time for MySQL to process all the SHOW queries, and pt-find can't do anything about that. These measurements are as of the time they're taken.
If you need some test that's not in this list, file a feature request at https://jira.percona.com/projects/PT.
--autoincβ type: string; group: Tests β Table's nextAUTO_INCREMENTisn. This tests theAuto_incrementcolumn.--avgrowlenβ type: size; group: Tests β Table avg row len isnbytes. This tests theAvg_row_lengthcolumn. The specified size can be"NULL"to test whereAvg_row_length IS NULL.--checksumβ type: string; group: Tests β Table checksum isn. This tests theChecksumcolumn.--cminβ type: size; group: Tests β Table was creatednminutes ago. This tests theCreate_timecolumn.--collationβ type: string; group: Tests β Table collation matches pattern. This tests theCollationcolumn.--column-nameβ type: string; group: Tests β A column name in the table matches pattern.--column-typeβ type: string; group: Tests β A column in the table matches this type (case-insensitive).
Examples of types are: varchar, char, int, smallint, bigint, decimal, year, timestamp, text, enum.
--commentβ type: string; group: Tests β Table comment matches pattern. This tests theCommentcolumn.--connection-idβ type: string; group: Tests β Table name has nonexistent MySQL connection ID. This tests the table name for a pattern. The argument to this test must be a Perl regular expression that captures digits like this:(\d+). If the table name matches the pattern, these captured digits are taken to be the MySQL connection ID of some process. If the connection doesn't exist according toSHOW FULL PROCESSLIST, the test returns true. If the connection ID is greater thanpt-find's own connection ID, the test returns false for safety.
Why would you want to do this? If you use MySQL statement-based replication, you probably know the trouble temporary tables can cause. You might choose to work around this by creating real tables with unique names, instead of temporary tables. One way to do this is to append your connection ID to the end of the table, thusly: scratch_table_12345. This assures the table name is unique and lets you have a way to find which connection it was associated with. And perhaps most importantly, if the connection no longer exists, you can assume the connection died without cleaning up its tables, and this table is a candidate for removal.
okay so the argument you'd hand to --connection-id is literally "\D_(\d+)$". What that does: it finds tables that end in a run of digits, and right before those digits there's an underscore preceded by some non-number character. That last bit matters, bestie β it's the thing that stops you from looking at tables with a date slapped on the end, which people love to do. Like baron_scratch_2007_05_07, for example. Keep your scratch tables separate, it's cleaner π
If you go this route, make sure the user pt-find runs as has the PROCESS privilege! Otherwise it'll only see connections belonging to the same user, and it might think some tables are ready to yeet when they're still in use. For safety, pt-find checks this for you π«Ά
See also --server-id.
--createoptsβ type: string; group: Tests
Matches a table create option against a pattern. This tests the Create_options column.
--ctimeβ type: size; group: Tests
Table was created n days ago. This tests the Create_time column.
--datafreeβ type: size; group: Tests
Table has n bytes of free space. This tests the Data_free column. The size you give can be NULL to test where Data_free IS NULL.
--datasizeβ type: size; group: Tests
Table data uses n bytes of space. This tests the Data_length column. The size you give can be NULL to test where Data_length IS NULL.
heads up π¨ Note: Starting from MySQL 8.0, empty tables return0instead ofNULL.
--dblikeβ type: string; group: Tests
Database name matches a SQL LIKE pattern.
--dbregexβ type: string; group: Tests
Database name matches this pattern.
--emptyβ group: Tests
Table has no rows. This tests the Rows column.
--engineβ type: string; group: Tests
Table storage engine matches this pattern. This tests the Engine column, or in earlier versions of MySQL, the Type column.
--functionβ type: string; group: Tests
Function definition matches pattern.
--indexsizeβ type: size; group: Tests
Table indexes use n bytes of space. This tests the Index_length column. The size you give can be NULL to test where Index_length IS NULL.
--kminβ type: size; group: Tests
Table was checked n minutes ago. This tests the Check_time column.
--ktimeβ type: size; group: Tests
Table was checked n days ago. This tests the Check_time column.
--mminβ type: size; group: Tests
Table was last modified n minutes ago. This tests the Update_time column.
--mtimeβ type: size; group: Tests
Table was last modified n days ago. This tests the Update_time column.
--procedureβ type: string; group: Tests
Procedure definition matches pattern.
--rowformatβ type: string; group: Tests
Table row format matches pattern. This tests the Row_format column.
--rowsβ type: size; group: Tests
Table has n rows. This tests the Rows column. The size you give can be NULL to test where Rows IS NULL.
--server-idβ type: string; group: Tests
Table name contains the server ID. Okay so picture this: you're making temporary tables using the naming convention explained up in --connection-id, but you also tack on the server ID of the server where those tables get created. Now you can use this pattern match to guarantee tables only get dropped on the server they were created on. Which means a table can't get accidentally dropped on a replica while it's still in use β provided all your server IDs are unique, which they lowkey have to be for replication to work anyway β¨
Example time: on the replication source (server ID 22) you create a table called scratch_table_22_12345. Now if you spot that same table on the replica (server ID 23), you might be like "oh, connection 12345 doesn't exist, guess I can drop it safely." But if you also force the name to match the server ID with --server-id '\D_(\d+)_\d+$', that table will not be dropped on the replica. Iconic behaviour, honestly π
--tablesizeβ type: size; group: Tests
Table uses n bytes of space. This tests the sum of the Data_length and Index_length columns.
--tbllikeβ type: string; group: Tests
Table name matches a SQL LIKE pattern.
--tblregexβ type: string; group: Tests
Table name matches this pattern.
--tblversionβ type: size; group: Tests
Table version is n. This tests the Version column.
--triggerβ type: string; group: Tests
Trigger action statement matches pattern.
--trigger-tableβ type: string; group: Tests
--trigger is defined on a table matching pattern.
--viewβ type: string; group: Tests
CREATE VIEW matches this pattern.
π¬ ACTIONS π¬
Real talk: the --exec-plus action happens after everything else, but other than that, actions happen in an indeterminate order π no ordering guarantees, bestie. If you genuinely need determinism, file a feature request at <https://jira.percona.com/projects/PT>.
--execβ type: string; group: Actions
Execute this SQL with each item found. The SQL can contain escapes and formatting directives (peep --printf for those).
--exec-dsnβ type: string; group: Actions
Specify a DSN in key-value format to use when executing SQL with --exec and --exec-plus. Any values you don't specify get inherited from the command-line arguments.
--exec-plusβ type: string; group: Actions
Execute this SQL with all items at once. This option is not like --exec. There are no escaping or formatting directives here β the only special placeholder is %s, and it stands in for the list of database and table names. The list of tables found gets joined together with commas and substituted wherever you put %s.
You might use this, for example, to drop every table you found:
DROP TABLE %s
It's sort of like GNU find's -exec command {} + syntax, iykyk.
--printβ group: Actions
Print the database and table name, followed by a newline. This is the default action if you don't specify any other action. π
--printfβ type: string; group: Actions
Print format on the standard output, interpreting '\' escapes and '%' directives. Escapes are backslashed characters, like \n and \t. Perl interprets these, so you can use any escapes Perl knows about. Directives get replaced by %s, and as of this writing you can't add any special formatting instructions, like field widths or alignment. Sorry bestie π
Here's the directive list. Note that most of them simply come from columns of SHOW TABLE STATUS. If the column is NULL or doesn't exist, you get an empty string in the output. And a % character followed by anything not in this list gets discarded (but the other character still gets printed).
aβ Auto_incrementAβ Avg_row_lengthcβ ChecksumCβ Create_timeDβ Database β the database name in which the table livesdβ Data_lengthEβ Engine β in older versions of MySQL, this is TypeFβ Data_freefβ Innodb_free β parsed from the Comment fieldIβ Index_lengthKβ Check_timeLβ CollationMβ Max_data_lengthNβ NameOβ CommentPβ Create_optionsRβ Row_formatSβ RowsTβ Table_length βData_length+Index_lengthUβ Update_timeVβ Version
πΈ DSN OPTIONS πΈ
These DSN options get used to create a DSN. You give each one like "option=value". The options are case-sensitive, so P and p are absolutely not the same option, don't do that to me. 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 percona-toolkit manpage for full details π«Ά
Aβ dsn: charset; copy: yes
Default character set.
Dβ dsn: database; copy: yes
Default database.
Fβ dsn: mysql_read_default_file; copy: yes
Only read default options from the given file.
hβ dsn: host; copy: yes
Connect to host.
pβ dsn: password; copy: yes
Password to use when connecting. If the password contains commas they must be escaped with a backslash: "exam\,ple"
Pβ dsn: port; copy: yes
Port number to use for connection.
Sβ dsn: mysql_socket; copy: yes
Socket file to use for connection.
uβ dsn: user; copy: yes
User for login if not the current user.
sβ dsn: mysql_ssl; copy: yes
Create SSL connection.
π ENVIRONMENT π
The environment variable PTDEBUG enables verbose debugging output to STDERR. Wanna enable debugging and capture all of it into a file? Run the tool like this:
PTDEBUG=1 pt-find ... > FILE 2>&1
β οΈ Be careful: debugging output is voluminous and can generate several megabytes of output. Like, several. Megabytes. π
π¨ ATTENTION π¨
Using PTDEBUG might expose passwords. When debug is enabled, all command line parameters are shown in the output. So uh, vibe check your terminal before you paste that anywhere π
π§ SYSTEM REQUIREMENTS π§
You need Perl, DBI, DBD::mysql, and some core packages that ought to be installed in any reasonably new version of Perl. That's it, that's the list β¨
π BUGS π
For a list of known bugs, see <https://jira.percona.com/projects/PT/issues>.
Please report bugs at <https://jira.percona.com/projects/PT>. Include the following info in your bug report, bestie, or they literally cannot help you:
- Complete command-line used to run the tool
- Tool
--version - MySQL version of all servers involved
- Output from the tool including STDERR
- Input files (log/dump/config files, etc.)
If possible, include debugging output by running the tool with PTDEBUG; see ENVIRONMENT.
π DOWNLOADING π
Visit <http://www.percona.com/software/percona-toolkit/> to download the latest release of Percona Toolkit. Or, get the latest release straight from the command line:
wget percona.com/get/percona-toolkit.tar.gz
wget percona.com/get/percona-toolkit.rpm
wget percona.com/get/percona-toolkit.deb
You can also grab individual tools from the latest release:
wget percona.com/get/TOOL
Replace "TOOL" with the name of any tool. Slay π
π AUTHORS π
Baron Schwartz
π ABOUT PERCONA TOOLKIT π
Okay so context bestie, bc you deserve to know: this tool is part of Percona Toolkit, which is literally a whole collection of advanced command-line tools for MySQL, all cooked up by Percona. π
The lore is kinda iconic ngl β Percona Toolkit was forked from two projects back in June, 2011: Maatkit and Aspersa. Those two were created by Baron Schwartz, and they were primarily developed by him and Daniel Nichter. King behavior, fr fr. π
Wanna see what else Percona's got cooking? The free, open-source software lives at http://www.percona.com/software/ β go peek, it's giving generous. β¨
π COPYRIGHT, LICENSE, AND WARRANTY π
Real talk, here's the legal bits β and yes, you actually have to read them because they're the whole vibe check for what you're allowed to do:
This program is copyright 2011-2026 Percona LLC and/or its affiliates, and 2007-2011 Baron Schwartz.
This is the part where the manpage yells in all caps, and honestly? Respect:
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.
Translation: no promises, no safety net, no cap. π You're on your own if it goes sideways.
Now the fun part β it's 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. Both! Your choice! Choose your fighter! π
On UNIX and similar systems, you can read these licenses yourself by running man perlgpl or man perlartistic. Very demure, very mindful, very documented.
You should have received a copy of the GNU General Public License, version 2 along with this program; if not, check https://www.gnu.org/licenses/. π«Ά
β VERSION β
pt-find 3.7.1-4
That's her. That's the version. Slay. πΈ
π POD ERRORS π
Not me having to tell you this, but: hey! The above document had some coding errors, which are explained below. Not the manpage's finest moment, but we move. π
Around line 4715:
Non-ASCII character seen before =encoding in 'Perconaβs'. Assuming UTF-8
Yeah, a curly apostrophe in Perconaβs snuck past the encoding declaration and Perl just shrugged and assumed UTF-8. Honestly? Relatable. The apostrophe had main character energy and the parser simply let it through. β¨
And that's the whole page, bestie β every last crumb of it. π§ Run pt-find responsibly, read your licenses, and remember: no warranty, but all the vibes. π
This fine document is perl v5.42.2, 2026-09-01. Signing off β mwah! π
π¦ where this page comes from
- arch rolling: percona-toolkit 3.7.1_4-1 Β· GPL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms