Your WordPress database quietly accumulates junk over the years: old post revisions, spam comments, expired transients and orphaned data from deleted plugins. None of it is doing you any good, and a bloated database means slower queries. Here’s how to trim it safely.
What clutters a WordPress database
The usual suspects are post revisions (WordPress keeps every draft version by default), trashed posts and comments, spam comments, and transients (temporary cached data that should expire but often lingers). On an old site, revisions alone can outnumber your actual posts many times over.
Back up before you clean
Database optimisation deletes data. Before touching anything, export a full database backup from phpMyAdmin or your backup plugin. If a cleanup goes wrong, you can restore in minutes.
Limit post revisions going forward
Stop the problem at the source. Add this to wp-config.php to cap revisions at a sensible number:
define('WP_POST_REVISIONS', 5);
Five revisions gives you a useful undo history without storing dozens of copies of every post forever.
Clean existing clutter
An optimisation plugin is the safest way to clear existing bloat — it removes old revisions, spam, trashed items and expired transients with a click, and does so without risky manual SQL. Run it, and you’ll often reclaim a surprising amount of space and shave time off queries.
Optimise the tables themselves
Beyond deleting rows, database tables benefit from an optimise operation that reclaims the physical space freed by deletions. In phpMyAdmin, select your database, tick all tables, and choose Optimize table from the dropdown. Most optimisation plugins do this too.
Watch the autoloaded options
A hidden performance drain is the wp_options table, where poorly-behaved plugins leave large autoloaded data that loads on every single page. If your site feels sluggish, checking for oversized autoloaded options is worth doing — trimming it can noticeably speed things up.
Make it routine
Do a cleanup every month or two rather than waiting years for a huge one. A tidy database keeps queries fast and pairs well with caching. If your database has grown genuinely large, we can help investigate what’s driving it — just get in touch.