Clean Your WordPress Database for Better Performance

Revisions, expired transients, orphaned meta and dead cron events bloat your WordPress database. How to clean each one safely and keep it lean over time.

Nobody sets out to bloat their WordPress database—it just happens. You edit a post twenty times and WordPress silently keeps twenty copies. A plugin you removed a year ago left its scheduled tasks running against nothing. Expired cache entries that were supposed to delete themselves never did. I’ve opened databases on year-old sites and found the useful content was a rounding error next to the junk. Here’s exactly what accumulates, which parts are safe to remove, and how to keep it clean without thinking about it.

The essentials

  • The usual bloat: revisions, auto-drafts, trashed/spam comments, expired transients, orphaned meta, duplicate meta, oEmbed cache, and dead cron events.
  • The Database Optimizer shows your database size and a count for every cleanable category before you touch anything—and lets you clean each one independently.
  • Revisions are kept, not wiped: you set how many to retain (5 by default), so recent editing history survives.
  • Cleanup cannot be undone, so back up first—the optimizer reminds you and offers a one-click database backup (see also the Backup & Restore module).
  • Schedule it daily, twice-daily or weekly and it runs quietly via WordPress cron; comments awaiting moderation are excluded by default so you never lose a real one.

What’s actually clogging your WordPress database?

A WordPress database fills up with nine kinds of clutter: post revisions, auto-drafts, trashed posts and comments, spam, expired transients (temporary cached values), orphaned and duplicate metadata, cached embed previews, and dead scheduled tasks left by removed plugins. None of it is your content; all of it is invisible until you go looking. Here’s what a typical site collects, and why each one exists:

  • Post revisions — WordPress stores a full copy every time you hit Update, with no limit by default. A page edited fifty times carries fifty revisions.
  • Auto-drafts — clicking Add New creates a draft row even if you never type a word. WordPress itself only deletes them after seven days, and the optimizer keeps the same rule: a younger auto-draft may be the post someone is writing right now.
  • Trashed posts and comments — deleted content stays in the database until the trash is emptied.
  • Spam comments — caught and filed away, but they pile up unless you clear them.
  • Expired transients — temporary cached values that were supposed to self-delete and didn’t.
  • Orphaned metadata — post, comment, term and user meta whose parent object no longer exists.
  • Duplicate metadata — the same meta key stored multiple times in post, comment or user meta.
  • Cached oEmbed data — embed previews WordPress caches in postmeta; clearing them is safe because WordPress rebuilds the ones still in use.
  • Dead cron events — scheduled tasks left behind by plugins you’ve since removed. The optimizer only counts a task as dead when it is more than 24 hours overdue and nothing in your site answers to it any more; WordPress’s own tasks are never touched, because an overdue core task is a symptom of a broken scheduler, not clutter.

That last pair—duplicate meta and dead cron events—is where most “cleaner” tools stop short, and they’re often the sneakiest contributors on an old site.

Here’s each category at a glance—what it is, and whether it’s safe to clear:

Data categoryWhat it isSafe to remove?
Post revisionsA full copy saved every time you hit UpdateYes—capped, not wiped (keeps 5 by default)
Auto-draftsA draft row created just by clicking Add NewYes—once older than seven days
Trashed posts & commentsDeleted content still sitting in the trashYes
Spam commentsComments caught and filed as spamYes
Expired transientsCached values that were meant to self-deleteYes
Orphaned metadataPost, comment, term or user meta whose parent is goneYes
Duplicate metadataThe same meta key stored more than onceYes
Cached oEmbed dataEmbed previews cached in postmetaYes
Dead cron eventsScheduled tasks left by plugins you’ve removedYes—only if 24 h overdue with no handler left
Comments awaiting moderationReal comments you haven’t reviewed yetNo—excluded by default

How do you clean a WordPress database, category by category?

Cleaning a WordPress database safely means clearing each type of clutter independently rather than trusting one “delete everything” button. The Database Optimizer module in Blaminhor Essentials shows your database size, then a live count for every category—revisions, drafts, spam, transients, orphaned and duplicate meta, oEmbed cache, dead cron events—each with its own Clean button.

A separate Autoload tab covers the other classic weight problem: the options WordPress loads into memory on every page. It lists them biggest first, with their size and a verdict—Safe to disable for temporary caches WordPress rebuilds on its own, Review for options that match no active plugin, theme or core setting—and a button to stop autoloading each one.

The Autoload tab of the Database Optimizer: total autoloaded size, number of options worth reviewing, and a table of autoloaded options with their size, a verdict such as "Safe to disable" or "Review", and a "Disable autoload" button on each row. The Autoload tab: every option WordPress loads on each page, sorted by size, with a verdict and a one-click “Disable autoload”.

Each category cleans independently. You’re never forced into a “clean everything” button you don’t trust; clear spam today, leave revisions alone, come back for transients later. Two details matter:

  • Revisions are capped, not deleted. You choose how many to keep—five by default—so you clear the backlog without losing your recent editing history. To stop the pile from growing back, cap them at the source with define('WP_POST_REVISIONS', 5); in wp-config.php.
  • Comments awaiting moderation are protected. The optimizer leaves pending comments untouched by default and tells you they weren’t counted, so a legitimate comment you haven’t reviewed yet never disappears in a cleanup.

Does optimizing tables actually reclaim disk space?

Sometimes. Optimizing a WordPress table (the OPTIMIZE TABLE command) defragments it after many deletions; MariaDB recommends it after large deletions. But the “free space” a database reports is not a promise of disk you will get back, so the Database Optimizer only counts it as recoverable on MyISAM tables, and reports zero overhead for InnoDB.

The distinction matters because the two engines behave differently. On older MyISAM tables, the free space is real holes left by deleted rows, and OPTIMIZE TABLE reclaims them. On modern InnoDB tables—what WordPress uses by default now—the free space MySQL reports is largely pre-allocated and managed by the engine, so the optimizer deliberately doesn’t count it as overhead rather than announce a saving it can’t guarantee. Optimizing an InnoDB table still rebuilds and defragments it—MariaDB lists InnoDB among the engines it works for—but on an InnoDB site the win you can count on comes from removing the junk rows themselves: lighter tables and faster queries, not a megabyte counter.

Can you set it and forget it?

Yes—and that’s the point. Turn on the Database Optimizer’s scheduled cleanup and pick a cadence: daily, twice daily or weekly (weekly is the default). From then on it runs in the background via WordPress cron, clearing the categories you enabled without you lifting a finger, and comments awaiting moderation stay excluded unless you opt them in.

The Database Optimizer also surfaces a summary on your WordPress dashboard once 100 or more revisions, drafts, trashed posts or spam comments have piled up, with an Optimize DB button right there. One thing to know before you click it: that button runs your scheduled cleanup immediately, without a confirmation step and without offering a backup—unlike the module’s own page, which does both. Make your backup first, then click.

How often is often enough?

For most WordPress sites, a weekly database cleanup (the longest built-in schedule) keeps things tidy without any downside. If you run a busy multi-author blog or a WooCommerce store generating orders and revisions all day, lean toward daily or twice daily. The goal isn’t a perfectly lean database—it’s to stop bloat from ever building up in the first place. Set the schedule once and let it work.

A clean database pairs naturally with the other performance basics: once the tables are lean, caching and front-end optimization give you the visible speed win visitors actually feel.

Database Optimizer is one of the 26 modules in Blaminhor Essentials—free and open-source on WordPress.org.

Download Blaminhor Essentials

– blaminhor

FAQ

Does cleaning the WordPress database actually make it faster?

It can, in two ways: smaller tables mean lighter queries, and removing thousands of stale rows (especially in wp_postmeta and wp_options) reduces the work WordPress does on every page load. The gain is biggest on old, never-cleaned sites; on a well-maintained one it's more about keeping bloat from creeping back.

Is it safe to clean my WordPress database?

Yes, if you back up first and understand each category. Standard items like revisions, spam and expired transients are safe to remove. The one to leave alone is comments awaiting moderation, which the Database Optimizer excludes by default. Always create a backup before a cleanup, since the operation cannot be undone.

Can I clean my WordPress database without a plugin (phpMyAdmin/SQL)?

You can, using phpMyAdmin and SQL — for instance deleting rows where post_type is "revision". But raw queries are unforgiving: one wrong WHERE clause and you lose real content, with no confirmation and no undo. Back up first; for most people a tool that previews the counts before deleting anything is far safer.

How do I limit or reduce post revisions in WordPress?

Add define('WP_POST_REVISIONS', 5); to wp-config.php to cap how many copies WordPress keeps per post, or set it to false to switch revisions off entirely. That stops new ones piling up; to clear those already stored you still need a cleanup. The Database Optimizer caps revisions rather than wiping your recent history.

Why is my WordPress database so large?

It depends on the site. With a page builder, the weight is usually in wp_posts (revisions) and wp_postmeta (dozens of meta rows per page, plus duplicates and orphans). With many plugins, it is often wp_options: settings flagged "autoload" that WordPress loads on every page, sometimes long after the plugin is gone. The Database Optimizer shows both.

Will cleaning my database delete any of my posts or content?

No. A proper cleanup targets clutter — revisions, spam, expired transients, orphaned rows — never your published posts, pages or approved comments. The Database Optimizer even leaves comments awaiting moderation untouched by default. The only real safeguard, though, is a backup before you run it, because the operation can't be undone.

blaminhor Building what's missing.

Comments