
WordPress Database Optimization: How to Speed Up Your Site
Over time, your WordPress database can bloat to 10x its necessary size. Here is a practical guide to cleaning and optimizing it for better performance.
Author: Meiko Neuman
Founder and web strategist, Kodulehe Haldus
Why does the database bloat?
Over the years, every active WordPress website accumulates tens of thousands of unnecessary rows: - Old revision history - Spam comments - Transients (cached data) - Plugin remnants (from deleted plugins) - Expired sessions - Logged events
A WP Engine study shows that the average site older than 3 years contains 70% redundant data.
Impact on performance
- Every query becomes slower
- Backups take longer to complete
- Higher database server load
- Increased hosting costs
Step-by-step cleaning
1. Create a backup (ALWAYS do this first)
mysqldump -u user -p database > backup.sql
2. Delete revisions
By default, WordPress saves a version of every change. A site with 100 articles can easily have over 1,000 revisions.
Limit future revisions: Add this to wp-config.php:
`php
define('WP_POST_REVISIONS', 5);
`
Delete old ones: Using WP-CLI:
`bash
wp post delete $(wp post list --post_type=revision --format=ids)
`
3. Remove spam and trashed comments
wp comment delete $(wp comment list --status=spam --format=ids)
wp comment delete $(wp comment list --status=trash --format=ids)
4. Clear transients
Expired cache data builds up over time. The WP-Optimize plugin handles this with a single click.
5. Remove data from deleted plugins
Plugins often leave tables behind even after they are uninstalled. Check phpMyAdmin and remove suspicious leftover tables.
6. Optimize tables
OPTIMIZE TABLE wp_posts, wp_postmeta, wp_options;
Alternatively, use WP-Optimize → "Optimize database tables".
Automation
The WP-Optimize Premium plugin can perform weekly cleanups automatically.
The Results
A typical 3-year-old WordPress site after optimization: - Database size: 250 MB → 45 MB (-82%) - Page load time: 2.8s → 1.4s (-50%) - Backup time: 12 min → 3 min
Long-term maintenance
Cleaning is a one-time fix. To prevent future bloat: - Limit the number of revisions - Delete unused plugins (do not just deactivate them) - Use Akismet to combat spam - Schedule a monthly automatic cleanup
Relation to performance
Database optimization is just one part of a comprehensive performance strategy. See also: - Website loading speed: how to improve it - Core Web Vitals: the complete guide
Summary
Database optimization is an hour's work that provides an immediate speed boost. Our maintenance packages include automatic quarterly database optimization as standard.
Sources
Need help with your website?
Our team maintains, optimises and protects your website. Pricing is agreed based on scope.
Request a quoteAbout the author
Meiko Neuman — Founder and web strategist, Kodulehe Haldus. Meiko leads the Kodulehehaldus team and has spent over a decade helping companies maintain and optimise their websites for measurable business results. He writes about website management, SEO, AEO/GEO and the commercial side of the web.