WordPress Database Optimization Guide 2026
Published April 21, 2026
WordPress Database Optimization Guide
WordPress stores everything in MySQL/MariaDB — posts, settings, user data, transients, and plugin data. Over time the database accumulates bloat that slows queries and wastes disk space. Regular optimization keeps your site responsive.
What Causes Database Bloat
- Post revisions: WordPress saves every save as a revision. A 500-post blog can have 3,000+ revisions
- Auto-drafts: Auto-saved versions of posts you never published
- Trashed content: Posts, pages, and comments in the trash
- Transients: Temporary data cached in the database — expired ones are never cleaned automatically
- Plugin data: Uninstalled plugins often leave their tables and options behind
- Spam comments: Can number in the thousands on older sites
Controlling Post Revisions
Add these constants to wp-config.php before the WordPress settings section:
define('WP_POST_REVISIONS', 5);— Keep only 5 revisions per postdefine('AUTOSAVE_INTERVAL', 120);— Autosave every 2 minutes instead of 60 seconds
To remove existing revisions: use WP-CLI (wp post delete $(wp post list --post_type=revision --format=ids)) or a plugin like WP-Sweep.
Cleaning Transients
Run this query via phpMyAdmin or WP-CLI: DELETE FROM wp_options WHERE option_name LIKE '%_transient_%';. Or use the Transients Manager plugin for a visual interface. SiteICO's WP-CLI terminal access makes this a one-command operation.
Optimizing Tables
Run OPTIMIZE TABLE on fragmented tables. WP-Sweep, WP-Optimize, and Advanced Database Cleaner automate this. Schedule monthly optimization to reclaim fragmented space after heavy delete operations.
Query Performance
Use the Query Monitor plugin to identify slow database queries. Common culprits: WP_Query without proper indexing, meta queries on large post volumes, and poorly-written plugin queries. Adding appropriate indexes to custom meta keys can reduce query time from seconds to milliseconds.
Database Backup Before Optimization
Always back up your database before running optimization or cleanup operations. SiteICO's automatic daily backups include full database snapshots, giving you a reliable restore point before any maintenance work.