A WordPress database cleanup is one of the most overlooked fixes for a site that has quietly gotten slower over time. Nothing looks broken: pages still load, the dashboard still works, forms still submit. But underneath, years of post revisions, expired transients, spam comments, and leftover plugin data pile up in tables that get queried on every single page load.
The fix isn’t complicated, but it does need to be done in the right order. This guide covers what’s actually filling up a WordPress database, how to check the damage before touching anything, and how to clean it out without breaking the site.
Why Is My WordPress Database So Big?
A WordPress database gets bloated from five main sources: unlimited post revisions, expired transients that never got cleared, spam and trashed comments, orphaned metadata left behind by deleted plugins, and autoloaded options that pile up in the wp_options table. According to EasyWP, none of these show up on a normal admin screen, which is exactly why the database can grow for years without anyone noticing.
Post revisions are the biggest volume source on content-heavy sites. WordPress saves a new revision every time a draft is auto-saved or a post is updated, and by default there’s no limit, so a page edited fifty times has fifty extra rows sitting in wp_posts. Page builders and WooCommerce make this worse because they store large amounts of structured data in wp_postmeta for every product, order, and layout element.
What Autoloaded Options Are (And Why They Matter Most)
Autoloaded options are the small pieces of data WordPress pulls into memory on every single page request, whether that specific page needs them or not. A healthy WordPress site keeps total autoloaded data under roughly 800 KB, and once it climbs past a few megabytes, every page load pays the tax, according to guidance from MainWP and WP Engine.
This is why autoloaded data usually matters more for speed than the overall database size. A 2 GB database with clean autoload settings can outperform a 200 MB database that’s autoloading 5 MB of leftover plugin configuration. Deactivated plugins are a common culprit: many leave their settings behind in wp_options with autoload still set to “yes,” even after the plugin itself is long gone.
How Do You Check Your Database’s Autoload Size?
The fastest way to check autoload size is a direct database query, run through phpMyAdmin, Adminer, or WP-CLI. This returns a single number in bytes for how much data WordPress is loading into memory on every page request.
SELECT SUM(LENGTH(option_value)) AS autoload_size
FROM wp_options
WHERE autoload = 'yes';A result under 800,000 (roughly 800 KB) is healthy. Anywhere from 1 MB to 3 MB is worth investigating, and anything above 5 MB is worth fixing before doing any other performance work, since it affects literally every page on the site, not just one slow template.
What’s Safe to Remove From a WordPress Database
Most of the common bloat sources are safe to clean out, but a few need a closer look before deleting anything. The table below breaks down what each one is and how carefully it needs to be handled.
| Bloat Source | What It Is | Safe to Clean? |
|---|---|---|
| Post Revisions | Saved copies of every edit to a post or page | Yes, keep the last 3-5 per post |
| Transients | Temporary cached data with an expiration time | Yes, once expired |
| Spam / Trashed Comments | Comments flagged by Akismet or manually deleted | Yes |
| Orphaned Postmeta | Leftover metadata from deleted plugins or posts | Usually, verify the plugin is truly gone first |
| Autoloaded Options | Settings loaded into memory on every page | Only the ones tied to inactive plugins |
How to Clean Up a WordPress Database Safely
A safe WordPress database cleanup follows a fixed order: back up first, remove the low-risk bloat, then optimize the tables. Skipping the backup step or reversing the order is how a routine cleanup turns into a broken site.
- Back up the full database before changing anything. A plugin comparison like UpdraftPlus vs Duplicator is worth reading if a reliable backup isn’t already in place.
- Test the cleanup on a staging copy first, especially on a site with WooCommerce or heavy custom fields, following a process like the one in this WordPress staging site guide.
- Limit or delete excess post revisions, keeping only the most recent few per post.
- Delete expired transients; these are safe to remove in bulk since WordPress simply regenerates them when needed.
- Empty spam and trashed comments instead of letting them accumulate indefinitely.
- Remove orphaned postmeta and leftover tables from plugins that are no longer installed.
- Run a table optimization pass (OPTIMIZE TABLE, or a plugin’s built-in optimizer) to reclaim disk space and defragment indexes.
- Re-check the autoload size after cleanup to confirm the number actually dropped.
For anyone who’d rather not touch SQL directly, plugins like WP-Optimize or Advanced Database Cleaner handle most of these steps through a one-click interface, including scheduled cleanups that run automatically.
Cleaning Up With WP-CLI
WP-CLI is the fastest and most precise way to clean a WordPress database, because each command targets exactly one type of data instead of a plugin’s bulk “clean everything” button. It’s a better fit for anyone comfortable with SSH access to their hosting account.
# Delete expired transients
wp transient delete --expired
# Delete all post revisions
wp post delete $(wp post list --post_type='revision' --format=ids) --force
# Optimize every database table
wp db optimizeThese three commands cover the majority of routine bloat. Running them through a weekly cron job, as suggested in WP-CLI maintenance guides from Liquid Web, keeps the database from building the same bloat back up between manual cleanups.
How Often Should You Clean Up a WordPress Database?
A monthly cleanup is a reasonable default for an active WordPress site: clearing spam and trash, removing old revisions from frequently edited pages, and optimizing tables. Low-traffic or mostly static sites can usually stretch that to once a quarter without any noticeable slowdown in between.
Sites running WooCommerce or a page builder tend to accumulate bloat faster because of how much postmeta gets written per product or per page layout, so those sites benefit from checking autoload size more often, even if the full cleanup still happens monthly. Related work on fixing a slow Interaction to Next Paint score covers other angles on WordPress speed that a clean database alone won’t fix.
A WordPress database cleanup isn’t a one-time project, it’s routine maintenance, the same as updating plugins or checking backups. Start by checking the autoload size, back up before changing anything, and work through the cleanup in order: revisions, transients, spam, orphaned data, then optimize.
Frequently Asked Questions
WordPress database bloat mainly comes from unlimited post revisions, expired transients that never got cleared, spam and trashed comments, orphaned metadata from deleted plugins, and autoloaded options left behind in the wp_options table.
Deleting old post revisions is safe for the vast majority of sites, but it’s best to keep the last 3-5 revisions per post rather than removing all of them, in case a recent edit needs to be rolled back.
Run a query that sums the size of every option with autoload set to “yes.” Under roughly 800 KB is considered healthy, 1-3 MB is worth investigating, and anything above 5 MB is a clear performance problem.
Neither is required exclusively: plugins like WP-Optimize handle cleanup through a simple interface with scheduled runs, while WP-CLI commands give more precise, one-task-at-a-time control for anyone comfortable with SSH access.
A monthly cleanup works well for most active WordPress sites, while low-traffic or mostly static sites can typically stretch that to once a quarter without a noticeable slowdown in between.

Leave a Reply