Over time, your WordPress database silently fills with data you no longer need — post revisions, expired transients, spam comments, plugin leftovers, abandoned sessions, and auto-drafts. None of it serves any purpose. All of it slows down your site.
A WordPress database that started at 5MB can grow to 500MB or more over a few years of normal operation — even on a modest blog. For WooCommerce stores and membership sites, multi-gigabyte databases are common.
Cleaning up that database reduces query execution time, improves page load speed, and makes your backups faster and smaller. This guide covers exactly what to clean, how to clean it safely, and how to prevent bloat from accumulating again.
WP-Optimize is the most comprehensive free WordPress database optimisation plugin. It cleans all common sources of database bloat through a straightforward interface.
Plugins → Add NewGo to WP-Optimize → Database — you'll see a list of optimisable items with current counts and sizes. Work through each category:
After cleaning, click Run optimization for the Optimize database tables option. This defragments tables and rebuilds indices — similar to defragmenting a hard drive. Can be slow on large databases but improves query performance.
For sites where you want precise control, phpMyAdmin allows direct database manipulation.
Log in to cPanel → Databases → phpMyAdmin → select your WordPress database.
DELETE FROM wp_posts WHERE post_type = 'revision';
To keep the most recent revision of each post:
DELETE FROM wp_posts
WHERE post_type = 'revision'
AND ID NOT IN (
SELECT MAX(ID)
FROM wp_posts
WHERE post_type = 'revision'
GROUP BY post_parent
);
DELETE FROM wp_posts WHERE post_status = 'auto-draft';
DELETE FROM wp_options
WHERE option_name LIKE '_transient_%'
AND option_name NOT LIKE '_transient_timeout_%';
DELETE FROM wp_options
WHERE option_name LIKE '_transient_timeout_%'
AND option_value < UNIX_TIMESTAMP();
DELETE FROM wp_comments WHERE comment_approved = 'spam';
DELETE FROM wp_commentmeta WHERE comment_id NOT IN (
SELECT comment_ID FROM wp_comments
);
In phpMyAdmin, select your database, check all tables, and from the "With selected" dropdown at the bottom, choose Optimize table.
wp_ while others use a custom prefix. Running queries with the wrong prefix will fail silently or target wrong tables.If you have SSH access to your server, WP-CLI provides fast, scriptable database cleanup.
# Delete all post revisions
wp post delete $(wp post list --post_type='revision' --format=ids) --force
# Clean expired transients
wp transient delete --expired
# Optimize all database tables
wp db optimize
wp-config.php to cap revisions at 5 per post:
define( 'WP_POST_REVISIONS', 5 );
define( 'EMPTY_TRASH_DAYS', 7 );
Not everything in the database should be cleaned — some "bloat-looking" data is actually important:
A clean WordPress database is a faster WordPress database. The cleanup process — especially clearing revisions and expired transients on an older site — often produces more speed improvement per hour of work than any other optimisation task.
Add monthly database cleanup to your WordPress maintenance routine. It takes 5 minutes with WP-Optimize and contributes meaningfully to your site's performance over the long term.
Contact us to discuss professional WordPress performance optimisation