Optimize WordPress Database: The 2026 Cleanup Guide

Developer optimizing a WordPress database on a laptop — optimize WordPress database guide

If you want to optimize your WordPress database, the good news is that most of the slowdown comes from data WordPress happily keeps collecting long after you need it: post revisions, expired transients, spam comments, trashed items, and tables left behind by plugins you deleted two years ago. The bad news is that none of it deletes itself.

This guide walks you through a safe, complete database cleanup: back up first, stop the junk at the source, remove what’s already there, and set up automation so it stays clean. No command line required unless you want it.

What actually makes a WordPress database slow

WordPress stores everything in MySQL: posts, comments, settings, user data. But it also stores a surprising amount of digital leftovers:

  • Post revisions. Every time you hit save, WordPress keeps a copy. A post you edited 30 times has 30 revisions — and each one is a full row in wp_posts with its own metadata.
  • Expired transients. Transients are temporary cached values (API responses, query results) that are supposed to delete themselves when they expire. Many don’t, especially when plugins skip proper cleanup. They pile up in wp_options, and the ones marked to autoload get pulled into memory on every single page load.
  • Orphaned tables and options. Delete a plugin and its database tables usually stay behind. Over the years this adds up to dozens of tables belonging to nothing.
  • Spam, trashed, and unapproved comments. Akismet catches the spam, but the rows stay in your database until you clear them.
  • Oversized autoload data. Some plugins dump megabytes into a single wp_options row with autoload enabled. WordPress loads that row on every request, whether the plugin needs it or not.

On a fresh site, none of this matters. On a site that’s been running for years — especially a WooCommerce store with orders, sessions, and logs — it absolutely does. A slow database mostly shows up as a slow admin area and slower uncached page loads, which is exactly the kind of drag that hurts your server response time.

Step 0: Back up before you touch anything

This is non-negotiable. Database cleanup deletes rows permanently. A full backup (database and files) means any mistake is a five-minute restore instead of a disaster.

If you don’t have a backup routine yet, follow my complete WordPress backup guide first, then come back. Seriously — do this step even if you skip everything else.

Step 1: Stop the bleeding — limit post revisions

Before cleaning up, stop the main source of new bloat. Add this to your wp-config.php, above the /* That's all, stop editing! */ line:

define( 'WP_POST_REVISIONS', 5 );

This caps each post at 5 revisions instead of unlimited. You still get a safety net for undoing mistakes, but a heavily edited post no longer spawns 40 database rows.

While you’re in there, consider shortening how long trashed items stick around:

define( 'EMPTY_TRASH_DAYS', 14 );

WordPress defaults to 30 days. Two weeks is plenty for most sites.

Step 2: Clean the safe junk with WP-Optimize

For the actual cleanup, WP-Optimize is the best starting point — it’s free, beginner-friendly, and handles all the low-risk clutter in one pass:

  1. Install WP-Optimize from Plugins → Add New and activate it.
  2. Go to WP-Optimize → Database. You’ll see a list of cleanup items with counts: post revisions, auto-drafts, trashed posts, spam and trashed comments, unapproved comments, expired transients, orphaned post meta, and more.
  3. Review the list, tick the items you want to remove (the defaults are safe), and click Run all selected optimizations.
  4. After cleanup, switch to the Tables tab and run Optimize on your tables. This defragments them and reclaims unused space — the MySQL equivalent of tidying up after the purge.

WP-Optimize also reports how much space each action frees, which is satisfying. On content-heavy sites with years of revisions, the database often shrinks noticeably after this single pass — and the admin area, especially the post and page lists, usually feels snappier right away.

Step 3: Hunt orphaned tables with Advanced Database Cleaner

WP-Optimize is great at routine junk, but it won’t show you the tables left behind by deleted plugins. For that, install Advanced Database Cleaner (free version is enough for most sites):

  1. Go to WP DB Cleaner → General cleanup and run the standard cleanup — it catches expired transients, orphaned metadata, and old cron tasks.
  2. Open the Tables tab. This is the plugin’s real strength: it lists every table in your database and flags the ones that look orphaned — tables belonging to plugins you no longer have installed.
  3. Inspect before you delete. The plugin lets you view what’s inside a table. If a table clearly belongs to a long-deleted plugin and holds no content you recognize, delete it. When in doubt, leave it — an extra table costs you far less than a broken site.
  4. Check the Cron jobs tab too. Dead plugins often leave scheduled tasks behind that still fire on every load, adding pointless queries.

This is the step most cleanup guides skip, and it’s where the biggest wins hide on older sites. I’ve seen databases where orphaned tables outnumbered the live ones.

Step 4: Automate it so it stays clean

A one-time cleanup is nice; a database that never bloats again is better. Both plugins support scheduling:

  • In WP-Optimize → Settings, enable scheduled cleanups (weekly or monthly is plenty) and check “keep last 2 weeks data” so scheduled runs don’t nuke anything fresh.
  • In Advanced Database Cleaner, set a recurring schedule for the general cleanup.

Set it once, and your database maintenance runs while you sleep.

What NOT to delete

A few safety rules that will save you from the most common cleanup disasters:

  • Don’t delete tables you can’t identify. If Advanced Database Cleaner flags a table and you’re not sure what it is, Google the table name first. Some belong to your theme or to plugins you still use.
  • Don’t clean transients aggressively on a live store. Transients often hold session and cart data. Run cleanups during low-traffic hours.
  • Don’t skip the backup. Yes, again. Cleanup plugins are safe when used carefully, but “carefully” includes having a restore point.
  • Don’t expect miracles. If your homepage is slow because of 4MB images, a cheap shared host, or 30 third-party scripts, database cleanup won’t fix that. It’s one layer of a full speed strategy — pair it with caching and the other fixes in my server response time guide and my INP optimization guide.

Prefer the command line? WP-CLI does it all

If you have SSH access, WP-CLI makes the whole thing scriptable:

wp transient delete --expired
wp db optimize
wp post delete $(wp post list --post_type='revision' --format=ids) --force

The last command deletes all post revisions — combine it with the WP_POST_REVISIONS limit from Step 1 so they don’t grow back.

Wrapping up

To optimize your WordPress database properly: back up, cap revisions with WP_POST_REVISIONS, run WP-Optimize for the routine junk, use Advanced Database Cleaner to remove orphaned tables and dead cron jobs, then schedule both so it never bloats again. The whole thing takes under an hour, and on an older site the difference in admin speed alone is worth it. And once the database is lean, pair it with page caching for the full speed stack — see my roundup of the fastest WordPress cache plugins.

If your site is slow and you’re not sure whether the database, the hosting, or something else is the culprit, get in touch — diagnosing WordPress performance issues is what I do, and the first look is always honest about what’s actually worth fixing.