Back to blog
    Header image for the article "WordPress Database Optimization: How to Speed Up Your Site"
    Website management05/06/20266 min

    WordPress Database Optimization: How to Speed Up Your Site

    Want to know how your own site is doing?

    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: Kodulehehaldus

    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

    An older WordPress site's database usually holds a lot of clutter: old revisions, binned comments and expired transients.

    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:

    define('WP_POST_REVISIONS', 5);

    Delete old ones: Using WP-CLI:

    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:

    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

    Join the newsletter

    Once a month, practical tips on making your website faster, more secure and easier to find on Google and in AI search.

    By subscribing you receive our newsletter. You can unsubscribe at any time from the end of every e-mail. Privacy policy

    Author

    Kodulehehaldus.com (Innov8it OÜ) – an Estonian web agency that builds, maintains and optimises websites.

    Related articles