WordPress database optimization-reduce size and improve speed
Optimize WordPress database: clean revisions, spam comments, autoload options, unused plugins, and run OPTIMIZE TABLE.
On this page
WordPress databases accumulate bloat: old revisions, spam, unnecessary options. A bloated database slows queries. Optimization removes junk and defrags tables for speed.
Remove post revisions
Each time you save a post, WordPress stores a revision. After 100s of revisions, the database grows large.
Limit revisions in wp-config.php:
define('WP_POST_REVISIONS', 5); // Keep only 5 recent revisions
Clean spam comments
Akismet and spam plugins catch comments but may not auto-delete. Empty trash manually:
- WordPress admin → Comments
- Click Spam tab
- Select all → Delete permanently
Reduce autoload options
WordPress loads certain options on every page load (autoload='yes'). Too many autoload options slow WordPress:
SELECT COUNT(*) FROM wp_options WHERE autoload='yes';
Disable autoload for unused plugin options via phpMyAdmin.
Run OPTIMIZE TABLE
Defragments tables and reclaims space:
OPTIMIZE TABLE wp_posts;
OPTIMIZE TABLE wp_postmeta;
OPTIMIZE TABLE wp_comments;
Use optimization plugins
- Advanced Database Cleaner: Remove revisions, spam, orphaned data
- WP-Optimize: Optimize, compress, clean all in one
- WP-Sweep: Delete unused data safely
Always backup your database before running optimization queries or plugins.
Related: WordPress troubleshooting-common issues and fixes | Slow database queries
Need managed WordPress hosting?
Run WordPress on UnderHost managed hosting with performance tuning, SSL, backups, security guidance, and expert support.





















