📝 Fix Post Revisions Bloating the Database After Autosave
WordPress autosaves the post being edited roughly every 60 seconds by default and, depending on how WP_POST_REVISIONS is configured, can keep every one of those autosaves as a separate row in wp_posts indefinitely — a long editing session on a single post can quietly generate dozens of revision rows, and across a few hundred posts that adds up to a wp_posts table that’s mostly revision history rather than actual content, slowing down any query that scans the whole table.
🔎 The Problem
SELECT post_type, COUNT(*) FROM wp_posts GROUP BY post_type; -- post_type = 'revision' : 48,212 rows -- post_type = 'post' : 312 rows -- revisions outnumber actual posts more than 150 to 1
✅ Fix: Cap Revisions Going Forward, Then Clean Up the Backlog
- Add
define('WP_POST_REVISIONS', 10);(or whatever number fits your editorial workflow) towp-config.phpso future autosaves stop accumulating without limit per post. - Run a one-time cleanup query (or a well-reviewed plugin) to delete revision rows beyond your new cap for posts that already have hundreds, rather than only fixing the setting going forward and leaving the existing bloat untouched.
- Schedule a periodic cleanup (WP-Cron or a server cron job) if the site has frequent long editing sessions, so the revision count stays bounded automatically instead of needing another manual cleanup later.
🚨 Why This Is Dangerous
- Always back up the database before running a bulk revision-delete query — a too-broad
WHEREclause onwp_postscan take real content down with the revisions if it’s not scoped carefully.
Autosave is saving your work exactly as often as you asked it to — the database bloat is a sign nothing was ever told to clean up after it.





