Your WordPress database is the engine behind every page load, yet it’s the part of performance most people never touch. Over months and years it fills with post revisions, expired transients, orphaned metadata, and spam — all of which make queries slower. A periodic cleanup and a few smart indexes can make a sluggish site feel new again.
Clearing the Clutter
Revisions and Transients
WordPress stores a revision every time you save a post, and busy sites accumulate thousands. Limit revisions in wp-config.php and periodically delete old ones. Expired transients also linger in the options table — clearing them removes dead weight that every page indirectly carries.
Hunt down orphaned metadata left behind by deleted plugins and posts. These rows serve no purpose but still bloat the postmeta and options tables, the two tables queried most often on a typical page load.
Optimizing Tables and Queries
Indexes Matter
If you frequently query custom fields, an index on the relevant meta_key can turn a slow full-table scan into an instant lookup. Profile your slowest queries with a tool like Query Monitor, then add targeted indexes where the data justifies them rather than guessing.
Run OPTIMIZE TABLE periodically to defragment and reclaim space, especially after large deletions. On busy sites, schedule this during low-traffic windows since it can briefly lock tables while it runs.
Keeping It Lean
Reduce autoloaded options — data WordPress loads on every single request. A handful of plugins dump large autoloaded values into the options table, and trimming them often yields an immediate, site-wide speed improvement. Audit your autoload size and keep it well under a megabyte.
Final Thoughts
A lean database is a fast database. Clear revisions and transients, prune orphaned data, index your hot queries, and watch your autoload size — a thirty-minute cleanup each quarter keeps every page on your site responsive.
