A WordPress database cleaner is a sharp tool. It can clear out years of post revisions, expired transients and leftover plugin data in one click. It can also delete the settings of a plugin you only switched off for a week, and there is no undo button, which is why every review of these plugins says "take a backup first" before moving straight on to the features. This guide is about that one line: what to back up, how to prove the backup is complete, and how to roll back just the database if the cleanup goes wrong.
The short version: export the database, check that the export finished, keep a copy off the server, and only then click "clean". If anything breaks, restore the database alone, because a cleaner never touches your theme, plugin or upload files.
What a WordPress database cleaner actually removes
A standard single-site WordPress install creates 12 core tables, all sharing one prefix (usually wp_). Plugins add their own tables on top, and a cleaner works through all of them deleting rows that look like clutter. "Look like" is the key phrase here. The plugin decides what counts as junk, and most of its rules are guesses based on names and dates.
Here is what the popular cleaners, such as Advanced Database Cleaner and WP-Optimize, usually offer to remove:
- Post revisions. Every time you hit Update, WordPress saves the old version as a revision in
wp_posts. A page edited 40 times carries 40 old copies. - Auto-drafts and trashed posts. WordPress already deletes auto-drafts older than 7 days and empties the trash after 30 days by default. A cleaner just does it sooner.
- Spam and trashed comments. Akismet removes spam older than 15 days on its own; a cleaner can wipe the rest now.
- Expired transients. Transients are short-lived cache values stored in
wp_options. Expired ones should vanish but often don't. - Orphaned metadata. Rows in
wp_postmeta,wp_commentmetaorwp_termmetathat point at a post, comment or term that no longer exists. - Orphaned options and tables. Settings and whole tables left behind by plugins that are no longer active.
- Table optimisation. Not a deletion at all, but most cleaners bundle an "optimize tables" button that rebuilds each table to reclaim space.
The first five items are mostly safe, since they are leftovers WordPress itself would clear in time or rows that nothing points to any more. The last two are where cleanups go wrong.
Why "orphaned" is a guess, not a fact
WordPress has no registry that says "this table belongs to that plugin". So when a cleaner calls a table orphaned, it is matching the table name against a list of known plugins, or checking whether a plugin with a similar name is active. A table called wp_yoast_indexable is easy to match. A table called wp_actions or wp_sessions is not. Some cleaners are honest about this. According to the Advanced Database Cleaner listing on WordPress.org, its scan for which plugin owns which item is a separate feature, and it labels results so you can review them before deleting. That review step only helps if you actually read it.
The deletions you cannot undo (orphaned plugin tables, autoloaded options)
Deleting a revision is low risk, because all you lose is an old draft of a page you have already replaced. Dropping a table or an option is a different matter. These carry live configuration, and the plugin that owns them may simply be switched off rather than gone.
Deactivated is not deleted
Picture a site owner who deactivates a forms plugin while debugging a conflict. A day later they run a cleaner, which sees tables and options from a plugin that is not active and lists them as orphaned. One click later, every saved form, every stored entry and every notification setting is gone. When the plugin is switched back on, it acts like a fresh install: blank settings, empty entry list.
Nothing in that story is unusual. Plenty of plugins keep their data on deactivation on purpose, so you can switch them back on without losing anything. A cleaner treats that kept data as junk. The plugin author and the cleaner author each made a sensible choice on their own, and together those two choices wipe your data.
Autoloaded options are a performance fix with a sharp edge
The wp_options table has an autoload column. Options marked to autoload are pulled into memory on every single page load. When that set grows large, every request gets slower. Since WordPress 6.6 in 2024, Site Health flags a site when its autoloaded options pass roughly 800 KB, and the column now accepts values such as on, off and auto rather than just yes or no.
Cleaners offer to fix this by turning off autoload for large options, or by deleting options they think are unused. Both changes can break things, and the breakage is rarely obvious. A theme that expects its settings in memory may fall back to defaults. A licence key stored as an option can disappear, and the plugin then reports itself as unlicensed. These are quiet failures: the site still loads, so nobody notices until a customer does.
Table optimisation needs space and time
The "optimize" button runs MySQL's OPTIMIZE TABLE. Per the MySQL documentation, on InnoDB tables that maps to a full table rebuild. The server writes a fresh copy of the table and then swaps it in, which needs free disk space roughly the size of the table and can take minutes on a large one. On cheap shared hosting with a tight disk quota, a rebuild that runs out of space can fail halfway. Most of the time MySQL rolls that back cleanly, but "most of the time" is not a phrase you want next to your order history.
None of this means you should avoid cleaners. It means the backup before the cleanup is not a formality, because it is the only undo button you get.
Read the cleaner's own settings before you click anything
Most cleaners show a summary screen with a count next to each category, and it is tempting to tick everything and press the big button at the bottom. Slow down at this screen, because it tells you more about the risk than any review does. Open each category that offers a "view" or "details" link and look at the actual rows or table names it plans to delete, not just the count beside them.
For orphaned tables, check every name against the plugins you have installed, including the ones you have switched off for now. If a table name contains a word you recognise, such as "forms", "woocommerce", "rank" or "redirect", leave it alone until you have confirmed which plugin created it and whether you still need that data. If a cleaner can't tell you which plugin a table belongs to, treat that as a reason to skip it, not as proof that nothing owns it.
For orphaned options, the same rule applies with one extra twist: option names are often short and generic, so a name like widget_settings or license_key says almost nothing about its owner. When you are unsure, skip the option. A few kilobytes of unused settings will never slow your site down in a way anyone can notice, while a deleted licence key can take a paid plugin offline for a whole afternoon.
Take a database backup you can prove is complete
For a cleanup, you only need the database. Your themes, plugins and uploads live on disk, and a cleaner never touches them. If you are new to that split, our post on why a database backup is only half a website explains what sits where. For this job, the database half is the half at risk.
Step 1: export with WP-CLI
If your host gives you SSH access, WP-CLI is the cleanest way to do this. Per the WP-CLI db export reference, the command reads your database details from wp-config.php and calls mysqldump for you:
wp db export before-clean-2026-11-12.sql --single-transaction
The --single-transaction flag is passed straight through to mysqldump. On InnoDB tables it gives you a consistent snapshot, so a comment or order that lands mid-export doesn't leave the file half old and half new. Put the date in the filename. When you are restoring in a hurry, "before-clean-2026-11-12" is far easier to trust than "backup-final-2.sql".
No SSH? Use phpMyAdmin's Export tab with the "Custom" method, and tick "Add DROP TABLE" so a later import replaces tables cleanly. Or use a backup plugin that can export the database on its own. What matters is the next step, not the tool.
Step 2: prove the export finished
A .sql file that exists is not the same as a .sql file that is complete. Exports get cut short all the time by a PHP time limit, a dropped connection or a full disk. The file is still there and it still opens, but it stops partway through a table.
Luckily, mysqldump leaves a marker. Unless comments are switched off, the last line of a finished dump reads -- Dump completed on followed by a timestamp. Check for it:
tail -n 1 before-clean-2026-11-12.sql
If that line is missing, the export did not finish and you should run it again. Once the marker is there, do two more quick checks:
- Every table is there. Run
grep -c "CREATE TABLE" before-clean-2026-11-12.sqland compare it to the table count fromwp db tables | wc -l. The two numbers should match. - The big tables have data. Run
wp db size --tablesto see which tables are largest, then search the file for anINSERT INTOline for each one. An emptywp_postssection means a broken export, whatever the file size says.
When we built BackupYourSite, our team made that completion marker a hard rule. A database dump that doesn't end with MySQL's own "dump completed" line, or that falls below a size sanity floor, is marked failed and retried. It is never stored as a good backup. You can apply the same rule by hand in under a minute, and it is worth doing every time.
Step 3: get a copy off the server
A backup sitting in your public_html folder is a backup you can lose with the site. It is also, if the folder is web-readable, a file anyone who guesses the name can download, with every user's email address inside it. Move the file off the server before you run the cleaner, either by downloading it or by copying it to offsite storage, and then delete the server copy or at least move it above the web root.
Step 4: take a full backup too, if the cleanup is a big one
For a routine revision purge, a verified database export is enough. For a first-ever cleanup on an old site, or one that drops tables, take a full files-plus-database backup as well. Some plugins store data in both places: settings in the database, generated files in wp-content/uploads. Restoring one half without the other can leave them out of step.
This is also where a scheduled backup service earns its keep. BackupYourSite takes a verified files-and-database backup every day on a schedule you pick, checks each archive before storing it, and keeps it offsite, away from the hosting account. If last night's backup is listed as verified, you already have a restore point. Take a fresh database export on top of it anyway, because last night's copy is missing everything that changed since it ran.
Run the cleaner on staging first, if you have one
A staging site is a private copy of your live site. If your host offers one-click staging, use it: clone production, run the exact cleanup you plan to run live, and then click through the copy before touching the real site.
A good test setup checks the things a cleaner is most likely to break:
- The home page and two or three key pages load and look right.
- Forms submit, and the entries show up in the admin.
- Each premium plugin still shows as licensed.
- For a shop, a product page loads, the cart works and a test order goes through.
- The theme customiser still shows your colours, logo and menus, not the defaults.
If everything passes, write down exactly which boxes you ticked in the cleaner, and repeat the same choices on live. If something breaks, you have found the problem without any risk to real visitors, and you can either change the settings or skip that category.
One warning. Staging is a test bench, not a backup. It reflects whatever state it was cloned at, and pushing staging back to live is a common way to overwrite newer orders and comments. We cover that in detail in staging vs backup: why you need both. Test on staging, but restore from a backup.
If something breaks: restore the database only, not the whole site
Say you ran the cleaner on live and a plugin is now acting like a fresh install. Don't panic, and don't start clicking around in the plugin's settings, because every change you make now is a change you may have to redo after the restore.
Because a cleaner only touches the database, you only need to put the database back. Restoring your files as well is slower, gains nothing, and can even roll back a plugin update you made earlier in the day.
Restore with WP-CLI
Upload your verified export to the server, then run:
wp db import before-clean-2026-11-12.sql
According to the WP-CLI db import reference, this feeds the file to MySQL using the credentials in wp-config.php. If your export included DROP TABLE statements, which wp db export adds by default, each table is replaced with its saved copy.
Two things to know before you do this:
- Anything written since the export is lost. New orders, comments, form entries and user sign-ups from the gap between export and restore go away. On a busy store, run the cleaner at a quiet hour and keep that gap short.
- Dropped tables come back, extra tables stay. The import recreates every table in the file. It doesn't delete tables that were added after the export, which is usually fine.
After the import, clear any page cache and object cache, flush permalinks by saving Settings → Permalinks once, and then recheck the same list you used on staging.
Restore without SSH
In phpMyAdmin, select the database, open the Import tab and upload the file. Large files can hit the upload limit, which is often 50 MB or less on shared hosting. Compress the file to .sql.gz, which phpMyAdmin accepts, or ask your host to import it for you.
If you use BackupYourSite, a restore lets you choose files, database or both. For a cleanup gone wrong, pick database only. The archive is verified before anything on your site is touched. If the stored copy is corrupt, the restore is refused and your site is left as it was. On hosts without SSH, the free BackupYourSite WordPress plugin does the same verified backups from inside WordPress.
What a revision purge can and can't give back
One case trips people up. Suppose you deleted all revisions, then realise you needed an old version of a page. Restoring the whole database brings the revisions back, but it also rolls back everything else since the export. A better route is to restore the export to a separate, temporary database, copy out the one post you need, and leave live alone. And if revisions are your main safety net for content, read why WordPress revisions are not a backup. They live in the same database the cleaner is about to prune.
Sites that need extra care: shops, memberships and multisite
Everything above applies to every WordPress site, but some kinds of site raise the stakes because their databases hold records that people paid for or signed up for. On those sites a bad cleanup is not just an annoyance for the owner; it can mean lost orders, locked-out members or support tickets that take days to untangle.
WooCommerce stores
A WooCommerce database changes constantly. Orders, customer sessions, stock levels and scheduled actions are written all day, and newer stores keep orders in their own dedicated tables rather than in wp_posts. A generic cleaner that was written before those tables existed may not recognise them, and some will happily list WooCommerce's scheduled-action logs or session tables as clutter. Session rows are disposable, and WooCommerce clears expired ones on its own schedule. Order tables are not disposable under any circumstances, so never drop a table with "wc_" or "woocommerce" in its name from a cleaner screen.
Timing matters even more on a store. The gap between your export and your restore is the window in which a real order could be lost if you have to roll back, so pick the quietest hour your analytics show, keep the cleanup short, and consider putting the shop into maintenance mode for the few minutes it takes.
Membership and learning sites
Membership plugins and course platforms often store progress, subscriptions and access rules in custom tables or in user meta. A cleaner's "orphaned user meta" category can remove rows that belong to a member whose account is managed by an outside payment system, and that member then loses access without anyone noticing until they complain. On these sites, skip the user meta category entirely unless the plugin vendor's documentation says it is safe.
Multisite networks
A multisite network keeps a separate set of tables for each subsite, with prefixes like wp_2_ and wp_3_, plus shared network tables. Some cleaners only scan the main site, and some scan the whole network at once, which means one wrong click can affect every subsite in a single pass. Check which mode your cleaner runs in, and export the full database rather than a single subsite before you start, because a restore of only one subsite's tables is much harder to get right.
How often cleaning is worth the risk
Less often than the plugin dashboards suggest. A cleaner's "you can save 40 MB" banner is designed to make you click, but saved space alone rarely makes a site faster. What slows a WordPress site down is usually a few specific problems, not general clutter.
In our own view, these are the problems worth fixing, roughly in order:
- Large autoloaded options. If Site Health warns about them, find the specific large options with
wp option list --autoload=on --fields=option_name,size_bytesand deal with those by name. Don't bulk-change autoload across the table. - A runaway table. Some plugins log every event and never prune. A statistics or security log table that keeps growing is worth trimming, ideally through that plugin's own retention setting.
- Expired transients piling up.
wp transient delete --expiredclears them safely, per the Transients API docs on how WordPress treats them as disposable. - Unbounded revisions. Rather than purging over and over, cap them going forward with
define( 'WP_POST_REVISIONS', 10 );inwp-config.php. Pick a number that suits how you edit.
For most small business sites, a careful cleanup a few times a year is plenty. Run it after a big round of plugin removals, after a redesign, or when Site Health raises a flag. Weekly scheduled cleanups that drop orphaned tables automatically are hard to justify. The gain is small, while the risk repeats every single week.
If you do schedule automatic cleaning, limit it to the safe categories: revisions beyond your cap, expired transients, spam and trash. Leave tables, options and autoload changes for manual runs, with a fresh verified backup each time.
There is also a simple test for whether a cleanup is worth doing at all. Before you start, write down the one problem you expect it to fix, such as a Site Health warning, a slow admin screen or a database that is close to your host's size limit. After the cleanup, check whether that problem actually went away. If you can't name the problem beforehand, the cleanup is probably housekeeping for its own sake, and housekeeping that can delete live settings is a poor trade on a site that is already working well.
A pre-flight checklist you can copy
- Export the database with
--single-transaction, with the date in the filename. - Confirm the last line reads
-- Dump completed on. - Match the table count in the file to the live table count.
- Move the file off the server.
- For big or first-time cleanups, take a full files-plus-database backup as well.
- Run the exact cleanup on staging and click through the test list.
- Run it on live at a quiet hour, choosing only the categories you tested.
- Recheck the test list on live. If anything fails, run
wp db importon the export.
That's eight steps, and steps 1 to 4 take a couple of minutes on most sites. The rest depends on how much you are deleting.
Frequently Asked Questions
Is it safe to use a WordPress database cleaner?
Yes, for the routine categories: revisions, expired transients, spam, trash and auto-drafts. The risky options are deleting "orphaned" tables and options and changing autoload settings, because the cleaner is guessing which plugin owns them. Take a verified database backup first, and review each item before you delete it.
What does a database cleaner delete?
Typically post revisions, auto-drafts, trashed posts, spam and trashed comments, expired transients, orphaned metadata, and options or tables left by inactive plugins. Many also run OPTIMIZE TABLE to rebuild tables and reclaim disk space. It doesn't touch your theme, plugin or upload files.
Do I need a full-site backup or just a database backup before cleaning?
A verified database backup covers a cleanup, because the cleaner only changes the database. For a first-ever cleanup on an older site, or one that drops whole tables, take a full files-plus-database backup as well. Some plugins keep related data in both places.
Can I undo a database cleanup without a backup?
Generally, no. Deleted rows and dropped tables are gone once MySQL commits the change. There is no recycle bin. Your host may keep its own snapshots, so ask them quickly, but don't count on it. That's why the backup has to come before the cleanup, not after.
How do I know my database backup is complete?
Check that the last line of the .sql file reads -- Dump completed on with a timestamp. Compare the number of CREATE TABLE lines with your live table count. Confirm your largest tables have INSERT INTO data in the file. If any check fails, export again.