Speed
Optimising the WordPress database for better performance
15 March 2025 · 6 min read
Over time, your WordPress database accumulates more and more data. Revisions, spam comments, temporary files and deleted content cause queries to become slower. Especially with WooCommerce webshops and blogs with a lot of content, a bloated database can seriously hinder performance.
At WP Maintainer we perform monthly database optimisation for all our clients. In this article we share our approach.
Why does the database grow?
WordPress stores a lot of data by default that is not always needed: - **Post revisions:** Every time you "save", a revision is created. After months this can be hundreds of revisions per page. - **Spam comments:** Stored even after deletion, until the trash is emptied. - **Transaction logs:** Especially with WooCommerce and form plugins. - **Temporary data:** Transients that are not cleaned up. - **Orphaned metadata:** Metadata without associated posts.
Step 1: Remove revisions
Limit the number of revisions WordPress stores. Add to wp-config.php: define('WP_POST_REVISIONS', 5); To remove existing revisions, use WP-Optimize or run an SQL query. Note: always make a backup first.
Step 2: Empty the trash
Deleted posts, pages and comments remain in the trash. Configure WordPress to empty it automatically: define('EMPTY_TRASH_DAYS', 7);
Step 3: Optimise tables
MySQL tables develop overhead after many changes. Optimise them regularly via phpMyAdmin or with a plugin. In phpMyAdmin: select all tables > choose "Optimize table" in the dropdown menu.
Step 4: Remove spam and pending comments
Spam comments take up unnecessary space. Remove them all at once: Go to Comments > Spam > Click "Empty Spam" Go to Comments > Trash > Click "Empty Trash"
Step 5: Clean up transients
Transients are temporary data that is sometimes not cleaned up. Use the Transients Manager plugin to view and remove them.
Automatic optimisation
The easiest way is a plugin such as WP-Optimize. It can: - Remove revisions - Delete spam - Empty trash - Optimise tables - Clean up transients - Do all this automatically on a schedule
WP Maintainer service
At WP Maintainer, database optimisation is standard in every maintenance plan. We monitor the database size, perform monthly maintenance and warn on abnormal growth. This is how we keep your website fast and efficient.