Originally published at https://makewpfast.com/wordpress-database-bloat-cleaning-revisions-transients-and-spam/
A fresh WordPress database is a few megabytes. After a year of running, it can balloon to hundreds of megabytes — even gigabytes — of accumulated junk. Post revisions, expired transients, spam comments, and orphaned metadata silently slow down every query.
The Hidden Cost of Database Bloat
Every database query scans through or indexes this bloated data. More rows mean slower queries, larger backups, and longer migration times. A database with 200,000 post revisions does not just waste disk space — it makes your wp_posts table queries measurably slower.
Post Revisions
WordPress saves a new revision every time you hit Save or Update. A post edited 50 times has 50 revisions stored as full copies in wp_posts, each with its own set of meta data in wp_postmeta.
To see how many revisions you have:
SELECT COUNT(*) FROM wp_posts WHERE post_type = 'revision';
To clean them up (keep the 3 most recent per post):
DELETE FROM wp_posts WHERE post_type = 'revision'
AND ID NOT IN (
SELECT ID FROM (
SELECT ID FROM wp_posts WHERE post_type = 'revision'
ORDER BY post_date DESC LIMIT 3
) AS keep
);
Expired Transients
Transients are temporary cached data stored in wp_options. Expired transients should be cleaned up automatically, but WordPress only deletes them when they are accessed — orphaned transients accumulate silently.
DELETE FROM wp_options WHERE option_name LIKE '_transient_timeout_%'
AND option_value
Get WordPress Performance Tips
Join developers and agency owners who get backend optimization strategies, tool releases, and deep-dive guides.
Join Free
No spam. Unsubscribe anytime. We respect your privacy.
Top comments (0)