WordPress stores almost everything in its database: posts and revisions, user data, comments, plugin settings, transients, and metadata of every kind. Over months and years, that database accumulates substantial waste. Post revisions pile up, expired transient values sit uncleaned, spam comments fill tables, and orphaned metadata from deleted plugins remains long after the plugin is gone. Each of these slows down database queries, which slows down every page load on uncached requests.
Database optimisation is not glamorous, but on an established WordPress site it is one of the most reliable ways to reduce server response time without changing your hosting plan.
What Accumulates in a WordPress Database
| Data type | How it accumulates | Impact |
| Post revisions | Every save creates a new revision | Bloats wp_posts table |
| Transients | Plugins store temporary data; expired entries persist | Bloats wp_options table |
| Spam and trash comments | Accumulates without regular cleanup | Bloats wp_comments table |
| Orphaned post meta | Deleted posts leave metadata behind | Bloats wp_postmeta table |
| Orphaned plugin data | Deleted plugins often leave their data in wp_options | Increases options table size |
| WooCommerce sessions | Abandoned shopping sessions accumulate in wp_woocommerce_sessions | Significant table growth on busy stores |
Post Revisions: The Biggest Culprit on Content-Heavy Sites
By default, WordPress saves an unlimited number of revisions for every post every time you save it. A frequently edited post might have 50 or more revisions stored in the database, most of which serve no practical purpose after a few days.
To limit revisions going forward, add this line to your wp-config.php file:
define( 'WP_POST_REVISIONS', 5 );
This keeps the five most recent revisions and discards the rest automatically. To clean up existing revisions already in the database, use a plugin like WP-Optimize. On a site with years of content and unlimited revisions enabled, cleaning these out can reduce database size by 30% to 50%.
Transients: Invisible Bloat in wp_options
WordPress transients are a caching mechanism that plugins use to store temporary data with an expiry time. The problem is that when a transient expires, WordPress does not delete it immediately. It stays in the database until something requests it and finds it expired. On busy sites with many active plugins, the wp_options table can accumulate thousands of expired transients that are never automatically removed.
This matters because WordPress loads a significant portion of the wp_options table into memory on every page request. A bloated options table with thousands of expired transients increases that memory load and slows the process down.
Expired transients can be cleared safely at any time. WP-Optimize handles this, or you can use a dedicated plugin like Delete Expired Transients.
How to Run a Database Cleanup Safely
Always take a backup before running any database cleanup operation. Even non-destructive cleanup operations occasionally have unintended effects on specific plugin configurations. A fresh backup before you start means you can roll back if something breaks.
WP Engine provides on-demand backups from the dashboard. Take a checkpoint backup, then run the cleanup on the production site. On standard hosts, use your host’s backup tool or a plugin like UpdraftPlus before proceeding.
Run the cleanup on a staging site first if possible. This lets you verify that nothing breaks before touching production. WP Engine includes a staging environment on all plans, making this straightforward. For the cleanup itself, WP-Optimize is the most reliable all-in-one option: it handles revisions, transients, spam comments, orphaned metadata, and database table optimisation in a single interface.
For more on how server-level performance connects to database speed, see What Is TTFB and Why Your Hosting Determines It and WordPress Caching Explained.
How Often Should You Optimise the Database?
For most WordPress sites, running a database cleanup every one to three months is sufficient. High-volume WooCommerce stores that generate thousands of orders and sessions monthly benefit from monthly cleanup of session data and transients.
After an initial cleanup on an older site, subsequent cleanups produce far less waste because the major accumulation has been cleared. Set a recurring reminder or schedule the cleanup with WP-Optimize’s automated scheduling feature.
Frequently Asked Questions
Will database optimisation break my WordPress site?
If done correctly — with a backup taken first — database optimisation is safe. The operations involved (removing post revisions, expired transients, spam comments, and orphaned metadata) do not touch active content. The main risk is if a plugin stores data in transients that it expects to retrieve, but well-coded plugins regenerate that data automatically when a transient is missing.
Does WP Engine handle database optimisation automatically?
WP Engine does not automatically clean post revisions or transients from your database — that is your responsibility. However, WP Engine’s server infrastructure includes object caching and query optimisation at the infrastructure level, which reduces the performance impact of a larger-than-ideal database. Manual cleanup is still worthwhile but less urgent on managed hosting than on shared hosting.
How do I know if my database is causing slow load times?
Install the Query Monitor plugin and load a few pages on your site. Query Monitor shows every database query that runs on each page load, how long each one takes, and which plugin or theme triggers it. If you see dozens of slow queries or a high total query time, the database is contributing to your TTFB. WP Engine speed benchmarks give you a baseline for what healthy query performance looks like.




