WordPress Database Cleanup: What to Clean, What to Leave, and Which Plugin

Over years, a WordPress database collects clutter: thousands of post revisions, expired transients, spam comments, and tables and settings left behind by plugins you deleted long ago. Cleaning it up can speed up uncached pages and the admin dashboard, but it's also the speed task most likely to cause damage if done carelessly.

Here's what's worth cleaning, what to leave alone, and how to do it safely.

First, set expectations

On most sites, database cleanup is a small speed win. Page caching, images and scripts matter far more for what visitors see. Cleanup pays off most when:

  • the site is several years old and has had lots of plugins come and go,
  • the admin dashboard is slow,
  • autoloaded options have grown large (more on that below),
  • or you run WooCommerce with lots of orders, sessions and logs.

Step 0: Back up

Every cleanup deletes data. Take a full backup (files and database) before you start, and make sure you know how to restore it.

What to clean

Item What it is Safe to clean?
Post revisions Saved copies of every edit Yes. Keep the last few per post if you like
Auto-drafts and trashed posts Unsaved drafts and items in the trash Yes
Spam and trashed comments Yes
Expired transients Temporary cached data past its expiry Yes
Orphaned post meta / comment meta Data pointing at posts or comments that no longer exist Usually yes
Orphaned tables and options from removed plugins Leftovers from uninstalled plugins Yes, if you're sure the plugin is gone for good
Table optimization (defragmenting) Reclaims space after deletions Yes, though modern storage engines need it less

What to be careful with

  • Options and tables from plugins you still use. Cleanup plugins sometimes can't tell whether a plugin is active, inactive or truly gone.
  • WooCommerce data: orders, customer sessions and action scheduler logs. Clear old completed scheduled actions and expired sessions, never orders.
  • Anything you don't recognize. If you're not sure, leave it.

The hidden one: autoloaded options

WordPress loads every option marked "autoload" on every single request, cached or not. Badly behaved plugins store large chunks of data as autoloaded options, and abandoned plugins leave them behind. If the total grows into the megabytes, every uncached page and admin screen slows down.

  • Check it: WordPress's Tools → Site Health flags a large autoloaded options size in its performance checks.
  • Fix it: use Advanced Database Cleaner (Pro can identify which plugin created each option) to find large or orphaned autoloaded options, and remove the ones from plugins you no longer use.

The best cleanup plugins

Plugin Price Best for
WP-Optimize Free; Premium from ~$49/yr Easy one-click cleanup and scheduling
Advanced Database Cleaner Free; Pro $39/yr or $78 lifetime Finding orphaned tables, options and cron jobs
Query Monitor Free Finding which plugin's queries are slow

WP-Optimize is the easiest place to start: it handles revisions, transients, spam and table optimization in a few clicks. If you already use a caching plugin, leave WP-Optimize's caching turned off and use it only for the database.

Advanced Database Cleaner goes deeper on the leftovers other cleaners miss.

Many caching plugins, including WP Rocket and LiteSpeed Cache, also include basic database cleanup.

Stop the clutter coming back

  • Limit revisions by adding define( 'WP_POST_REVISIONS', 5 ); to wp-config.php.
  • Schedule cleanups monthly with WP-Optimize or Advanced Database Cleaner.
  • Uninstall plugins properly (some have a "delete data on uninstall" setting), and don't leave unused plugins installed.

Cleanup vs object caching

Cleanup makes each query a little cheaper. Object caching (Redis) stops many queries from hitting the database at all, which is usually a much bigger win for WooCommerce, memberships and the admin. If your host offers Redis, install Redis Object Cache. If it doesn't, that's often a sign the plan is holding you back. Run our 5-minute host test.

See every tool in database & object caching.

Some links in this article are affiliate links. See our disclosure.

Enjoyed this article?

Share it with your network