Is your WordPress site getting slower over time even though you haven’t changed anything? Your database is probably the culprit. Over months and years, WordPress accumulates thousands of rows of unnecessary data — post revisions, spam comments, transients, orphaned metadata — that make every database query slower. The good news: cleaning and optimizing your database is safe, fast, and free. This guide shows you exactly how to do it.
What Causes WordPress Database Bloat?
Every time you edit a post, WordPress saves a revision. Every time a plugin stores temporary data, it creates a transient. Spam comments accumulate. Plugins get deleted but leave their data tables behind. Over time, these add up to thousands of rows of data that WordPress has to sort through on every page load.
Here’s a breakdown of the most common sources of database bloat:
| Bloat Type | Where It Comes From | Impact |
|---|---|---|
| Post revisions | Every save/update of a post or page | High — can be thousands of rows |
| Auto-drafts | WordPress auto-save feature | Medium |
| Trashed posts/pages | Deleted content not emptied from trash | Medium |
| Spam & trashed comments | Comment spam not deleted | Medium–High on busy sites |
| Expired transients | Plugin temporary data that wasn’t cleaned up | High — can be tens of thousands of rows |
| Orphaned metadata | Post/user meta from deleted plugins | Medium |
| Unused plugin tables | Plugins that don’t clean up on deletion | Low–Medium |
How to Check Your Database Size
Before optimizing, benchmark your current database size so you can measure improvement. Log into your hosting control panel and open phpMyAdmin. Select your WordPress database from the left sidebar. The bottom of the page shows the total database size. Alternatively, install WP-Optimize and check its dashboard — it shows a detailed breakdown of bloat by type.
Method 1: Use WP-Optimize Plugin (Recommended for Beginners)
WP-Optimize is a free WordPress plugin that makes database optimization point-and-click simple. It’s safe, widely used (1M+ installs), and includes scheduling so you can set and forget it.
Step 1: Install WP-Optimize
Go to Plugins → Add New, search for “WP-Optimize,” install and activate it. Find it in your WordPress admin menu under WP-Optimize.
Step 2: Review What to Clean
WP-Optimize shows you a list of optimizations with the number of rows/items that would be removed and how much space they take up. Common items include:
- Post revisions — Select “Keep last X revisions” to preserve recent history while removing old ones
- Auto drafts — Safe to clean
- Trash (posts, pages, comments) — Empty the trash
- Spam comments — Delete all spam
- Expired transients — Always safe to remove
- Orphaned post meta — Generally safe, but check the count first
Step 3: Run Optimizations and Schedule
Click Run All Selected Optimizations to clean the database. Then go to the Settings tab in WP-Optimize and set up a weekly scheduled clean to keep your database lean automatically.
Method 2: Limit Post Revisions in wp-config.php
Post revisions are the biggest source of WordPress database bloat on active sites. By default, WordPress saves unlimited revisions. You can cap this by adding a single line to your wp-config.php file:
// Keep only the last 5 revisions per post
define( 'WP_POST_REVISIONS', 5 );
To disable revisions entirely (not recommended — you lose the ability to roll back changes):
define( 'WP_POST_REVISIONS', false );
Add this line before the /* That's all, stop editing! */ line in wp-config.php. This prevents new revisions from accumulating, but you still need to clean up the existing revisions using WP-Optimize.
Method 3: Clean Up Transients via phpMyAdmin
Expired transients are stored in the wp_options table with the option name starting with _transient_ or _site_transient_. On sites with many plugins, this table can contain tens of thousands of rows. You can clean them directly in phpMyAdmin:
DELETE FROM wp_options
WHERE option_name LIKE '%_transient_%';
Method 4: Run MySQL OPTIMIZE TABLE
After deleting rows from your database, the physical disk space isn’t immediately reclaimed — the database has “gaps” where deleted rows used to be. Running OPTIMIZE TABLE reclaims this space and defragments the tables, which can further improve query speed.
WP-Optimize does this automatically as part of its optimization process. If you prefer to do it manually in phpMyAdmin, select all tables in your WordPress database, choose Optimize table from the “With selected” dropdown, and click Go.
Advanced: Add Object Caching with Redis
Even with a clean database, WordPress runs hundreds of database queries per page load. Object caching with Redis or Memcached stores the results of these queries in memory so they don’t need to re-execute on every request. This can reduce database load by 50–90% on high-traffic sites.
Redis is available on most managed WordPress hosts (Kinsta, WP Engine, Cloudways) and can be enabled with a plugin like Redis Object Cache by Till Krüss. Check if your host supports it before installing.
WordPress Database Optimization Checklist
| Task | Frequency | Tool |
|---|---|---|
| Clean post revisions | Monthly | WP-Optimize |
| Delete expired transients | Weekly | WP-Optimize (scheduled) |
| Empty trash (posts, comments) | Weekly | WP-Optimize / WordPress admin |
| Delete spam comments | Weekly | Akismet / Comments admin |
| Run OPTIMIZE TABLE | Monthly | WP-Optimize / phpMyAdmin |
| Limit post revisions in wp-config.php | One time | Manual |
| Enable object caching (Redis) | One time | Redis Object Cache plugin |
Frequently Asked Questions
Is it safe to delete all post revisions?
Yes — but it’s better practice to keep the last 3–5 revisions rather than deleting all of them. This gives you the ability to roll back to a recent version of a post if needed. Use WP-Optimize’s “Keep last X revisions” option rather than deleting all revisions.
How much of a speed improvement can I expect?
Results vary significantly depending on how bloated your database is. Sites that haven’t been cleaned in years can see database sizes drop by 50–70%, with noticeably faster admin dashboard load times and improved query performance. Combined with object caching, database optimization can be one of the most impactful speed improvements for dynamic WordPress sites.
Will optimizing the database affect my site’s content?
No — when done correctly, database optimization only removes unnecessary data like old revisions, expired transients, and spam comments. Your published posts, pages, product data, and user accounts are not affected.
Final Thoughts
Database optimization is one of those “set it and forget it” performance improvements. Install WP-Optimize, run an initial cleanup, limit future revisions in wp-config.php, set up a weekly scheduled cleanup, and consider adding Redis object caching if your host supports it. Your WordPress admin will feel snappier, and your front-end query times will improve — especially on content-heavy sites.
For a comprehensive WordPress speed audit that covers hosting, database, caching, images, and Core Web Vitals, check out our WordPress Speed & Performance Optimization service starting at $499.