How to Optimize a WordPress Database (2026)
Speed up WordPress by optimizing your database. Clean transients, post revisions, and spam. Use WP-Optimize or WP-CLI for safe database maintenance.
How to Optimize Your WordPress Database
Over time, WordPress databases accumulate bloat: post revisions, trashed content, expired transients, spam comments, and orphaned metadata. A clean database runs faster and uses less storage.
What Causes Database Bloat?
- Post revisions: WordPress saves a revision every time you update a post. A busy blog generates thousands of revision rows.
- Transients: Temporary data cached in the database. Expired transients aren't always cleaned up automatically.
- Spam and trash: Comment spam and trashed posts/pages remain in the database until deleted.
- Orphaned metadata: Post meta rows that reference deleted posts.
- Plugin data: Deactivated plugins often leave tables and options behind.
Method 1: WP-Optimize Plugin (Recommended)
- Install WP-Optimize from the plugin directory
- Go to WP-Optimize → Database
- Review the optimizations available: Post Revisions, Trashed Posts, Spam Comments, Transients, etc.
- Check the items you want to clean, then click Run All Selected Optimizations
Always back up your database before running optimizations. SiteICO's automated daily backups provide this safety net automatically.
Method 2: WP-CLI Commands
SiteICO provides WP-CLI access for every site. From your site dashboard, open the terminal and run:
wp transient delete --expired
wp post delete $(wp post list --post_status=trash --format=ids) --force
wp comment delete $(wp comment list --status=spam --format=ids) --force
wp db optimize
Limit Post Revisions
Add this line to wp-config.php to limit revisions going forward:
define( 'WP_POST_REVISIONS', 5 );
This keeps only the 5 most recent revisions per post — enough for recovery purposes without excessive bloat.
Schedule Regular Maintenance
WP-Optimize supports scheduled automatic cleanups. Configure weekly runs to keep your database lean without manual intervention.
Ready to get started? Try SiteICO free.
Start FreeStart building with SiteICO
Deploy your WordPress site in under 1 second. Follow our guides to get the most out of the platform.
No credit card required.