This post contains affiliate links. If you buy something through one of them, Veravix may earn a commission at no extra cost to you.
Checked for accuracy and updated on November 21, 2026. Before you change anything in the database, How to Restore a WordPress Backup: Pick the Right Route Before You Overwrite Anything covers how to save and restore it safely.
Most “optimize your WordPress database” guides jump straight to a plugin and a big green button. That skips the part that actually explains why a database gets slow in the first place, and it means the cleanup often misses the single biggest offender: a bloated wp_options table with too much data flagged to load on every single request.
Here’s what’s actually happening, and the order that fixes it safely.
What actually bloats a WordPress database
Four things build up over time, and only one of them behaves the way most articles imply.
Post revisions. WordPress saves a full copy of a post every time you hit save, with no limit by default. A post edited 40 times has 40 revision rows sitting in wp_posts forever.
Transients. Temporary cached data (an API response, a computed value) that plugins store with an expiration time. When that expiration isn’t cleaned up properly, expired transients pile up as dead rows.
Trashed and spam content. Deleted posts and spam comments sit in the trash tables until something empties them, which nothing does automatically on most sites.
Autoloaded options, the one that actually matters most. Every row in wp_options can be flagged autoload = yes (since WordPress 6.6 the column can also hold on, auto and auto-on, which count the same way), which means WordPress loads it into memory on every single page load, admin or frontend, cached or not, in one query at the very start of the request. Plugins are supposed to set this flag to “no” for anything that isn’t needed on every page. Most don’t bother. A single abandoned plugin that left a 4MB autoloaded option behind adds that same tax to every page on the site, permanently, until someone finds and removes it. WordPress itself now puts a number on it: since 6.6, the Site Health screen shows a critical issue, “Autoloaded options could affect performance”, once the total passes 800 KB. As a rough guide beyond that, past 3 to 5MB it’s worth investigating, and 10MB or more is a real, measurable performance problem. Core also stopped autoloading any newly saved option larger than 150,000 bytes by default, but that only protects new rows; bloat already sitting in the table stays until someone removes it.
This is the reason two sites with an identical page-builder and plugin stack can have very different admin-dashboard speeds: one has a clean options table, the other is quietly loading megabytes of dead data on every request.
Back up before touching any of this
Every step below is a database write, and revision or postmeta cleanup on a site using a page builder (Elementor, ACF-driven layouts) or SEO plugin can occasionally remove data those plugins expected to still be there. Take a real database backup, not just a file backup, before running anything. This is the one step worth never skipping, even on a small site.
The safe cleanup order
1. Delete expired transients first. These are the lowest-risk cleanup: they’re meant to be temporary, and anything expired is safe to remove. Via WP-CLI: wp transient delete --expired.
2. Clean up revisions, but don’t delete them all blind. Rather than purging every revision on every post, cap how many WordPress keeps going forward by adding define('WP_POST_REVISIONS', 5); (or a number that fits your workflow) to wp-config.php, then clean up the existing backlog: wp post delete $(wp post list --post_type='revision' --format=ids) (with a backup already taken, per above).
3. Empty trash and spam. Trashed posts and pages, and spam-flagged comments, can be cleared through wp-admin directly (Posts → Trash → Empty Trash, Comments → Spam → Empty Spam) or via WP-CLI’s comment and post delete commands.
4. Run a table optimize pass. After rows are actually deleted, the database tables themselves still reserve the old space until they’re optimized. wp db optimize runs MySQL’s table-optimize routine across the whole database in one command.
5. Audit autoloaded options last, since this is where the real win usually is. A query like wp db query "SELECT option_name, LENGTH(option_value) AS size FROM wp_options WHERE autoload IN ('yes','on','auto-on','auto') ORDER BY size DESC LIMIT 20;" shows the heaviest autoloaded rows by name. The IN list matters: a query that only checks for 'yes' misses rows stored with the newer values on a WordPress 6.6 or later site, so it can report a smaller total than Site Health does. Anything belonging to a plugin that’s no longer installed is safe to remove; anything unfamiliar is worth searching before deleting, since a handful of large autoloaded options are legitimate (a page builder’s own settings, for instance).
Plugin options, if you’d rather not use WP-CLI
WP-Optimize and Advanced Database Cleaner both cover revisions, auto drafts, trashed posts, spam and expired transients through a plugin screen, and both can run the cleanup on a schedule so it does not need repeating by hand. They differ on the autoload step. WordPress.org’s listing for Advanced Database Cleaner describes an Options view that shows each option’s size and autoload status, sorts by size, flags large autoloaded options and lets you switch an option’s autoload to yes or no, which is the same audit as the query above in a screen. WP-Optimize’s listing does not mention an autoload view, so with that plugin the manual query is still the way to do this step. WP-Optimize’s listing also says it can run a backup before clean-ups through UpdraftPlus, while a user review of Advanced Database Cleaner notes it has no built-in backup, so take your own database backup first with that one. Either way, check what the plugin shows against the Site Health total before you delete anything.
If the site is already running WP Rocket for caching, its Database tab covers the same revisions, transients and trash cleanup, plus a table optimize, and can run it daily, weekly or monthly, without adding a second plugin just for this. WP Rocket’s own documentation warns that a database optimization cannot be undone, which is one more reason to take the backup first. If you would rather have database cleanup and script control in one plugin, Perfmatters pricing and what its license includes covers one that offers both.
How often this actually needs doing
For most sites, a real cleanup pass every few months is enough, unless the site publishes very frequently or runs a plugin known to be autoload-heavy (some SEO and page-builder plugins are repeat offenders). The revision cap in wp-config.php is a one-time fix that stops the backlog from rebuilding; the autoload audit is worth repeating any time the site feels slower in wp-admin specifically, since that’s the symptom a bloated options table produces first.

Etienne Basson works with website systems, SEO-driven site architecture, and technical implementation. He writes practical guides on building, structuring, and optimizing websites for long-term growth.