Every WordPress site accumulates database bloat over time — post revisions for every save, expired transients from plugins, auto-drafts, trashed content, spam comments, and orphaned metadata from deleted posts. This bloat inflates table sizes unnecessarily and slows down database queries.
This guide shows you how to safely clean and optimize your WordPress database using both a plugin and phpMyAdmin, and how to prevent bloat from building up again.
Always backup first: Before optimizing your database, create a backup. While the methods below are safe, having a backup is essential insurance before any database operation.
What Database Bloat Does WordPress Accumulate?
| Type | Description | Safe to Remove? |
|---|---|---|
| Post Revisions | A copy saved every time you edit a post — can reach dozens per post | Yes (keep 3–5 latest) |
| Auto Drafts | Auto-saved drafts WordPress creates while editing | Yes |
| Trashed Posts/Pages | Deleted content still sitting in the trash | Yes |
| Spam Comments | Comments marked as spam | Yes |
| Trashed Comments | Deleted comments still in trash | Yes |
| Expired Transients | Temporary plugin cache stored in wp_options that has expired | Yes |
| Orphaned Metadata | Post/user metadata linked to deleted items | Yes (verify first) |
| Unused Plugin Tables | Tables left behind by uninstalled plugins | Yes (verify first) |
Method 1 — WP-Optimize Plugin (Recommended)
WP-Optimize is the most popular all-in-one WordPress optimization plugin with over 1 million active installations. It handles database cleanup, caching, and image optimization in one interface.
- WordPress Admin → Plugins → Add New → search WP-Optimize
- Install → Activate
- Go to WP-Optimize → Database
- Select optimizations — at minimum check:
- Clean all post revisions
- Clean all auto-draft posts
- Clean all trashed posts
- Remove spam and trashed comments
- Remove expired transient options
- Click Run all selected optimizations
- WP-Optimize displays a summary of rows removed
Automate it: WP-Optimize includes a scheduling feature. Go to WP-Optimize → Settings → Schedule and configure weekly or monthly automatic cleanup.
Alternative: Advanced Database Cleaner Plugin
For more granular control over what gets removed, Advanced Database Cleaner is an excellent complement to WP-Optimize. It excels at identifying orphaned database tables left behind by plugins that were uninstalled without proper cleanup.
- WordPress Admin → Plugins → Add New → search Advanced Database Cleaner
- Install → Activate
- Navigate to WP Admin → Advanced DB Cleaner
- Under General Clean Up, review all detected junk items
- Under Orphaned Tables, identify tables left by removed plugins — verify each before deleting
- Click Delete or Clean for each item you want to remove
| Plugin | Strengths | Best For |
|---|---|---|
| WP-Optimize | All-in-one: DB + cache + images | Most sites wanting a single solution |
| Advanced Database Cleaner | Detailed orphan table detection | Developers who need fine-grained control |
| WP-Sweep | Lightweight, no upsells | Users who prefer a minimal plugin footprint |
Method 2 — phpMyAdmin (Advanced)
For direct database control, use phpMyAdmin through DirectAdmin on AsiaGB Hosting.
Optimize Tables via phpMyAdmin
- DirectAdmin → Databases → phpMyAdmin → select your WordPress database
- Select all tables (Check All at the bottom)
- In the "With selected" dropdown, choose Optimize table
- Click Go — phpMyAdmin defragments and optimizes all tables
Remove Bloat with SQL Queries
For granular control, run these queries in phpMyAdmin (replace wp_ with your table prefix if different):
-- Remove all post revisions
DELETE FROM wp_posts WHERE post_type = 'revision';
-- Remove auto-drafts
DELETE FROM wp_posts WHERE post_status = 'auto-draft';
-- Remove trashed posts
DELETE FROM wp_posts WHERE post_status = 'trash';
-- Remove spam comments
DELETE FROM wp_comments WHERE comment_approved = 'spam';
-- Remove expired transients
DELETE FROM wp_options WHERE option_name LIKE '_transient_%'
AND option_name NOT LIKE '_transient_timeout_%';
-- Remove orphaned post metadata
DELETE pm FROM wp_postmeta pm
LEFT JOIN wp_posts wp ON wp.ID = pm.post_id
WHERE wp.ID IS NULL;
Warning: Always backup before running SQL queries manually. A wrong query can permanently delete important data with no way to recover it.
Limit Post Revisions Going Forward
After cleaning up, prevent future bloat by limiting how many revisions WordPress keeps. Add this to wp-config.php:
// Keep only the 3 most recent revisions per post
define('WP_POST_REVISIONS', 3);
// Disable revisions completely (not recommended for multi-author sites)
// define('WP_POST_REVISIONS', false);
Additional wp-config.php Settings to Reduce Long-Term Bloat
Beyond limiting post revisions, several other wp-config.php constants help keep your database lean over time:
// Keep only the 3 most recent revisions per post
define('WP_POST_REVISIONS', 3);
// Reduce auto-save frequency from 60s to 5 minutes
define('AUTOSAVE_INTERVAL', 300);
// Empty trash automatically after 14 days (default is 30)
define('EMPTY_TRASH_DAYS', 14);
Note: Increasing AUTOSAVE_INTERVAL reduces auto-draft creation but means you could lose more content if your browser crashes. Choose a value that suits your editing workflow.
Monitoring Database Size Over Time
After cleaning up, track your database size regularly to know when the next cleanup is due. There are several ways to monitor it:
Via phpMyAdmin
Open phpMyAdmin → select your WordPress database → the footer row shows the total size across Data and Index columns. Look for non-zero Overhead values in the Status column — these indicate tables that would benefit from optimization.
Via WP-Optimize Dashboard
WP-Optimize displays a running database size graph in its Dashboard tab, giving you a clear trend view without needing to open phpMyAdmin.
SQL Query to Inspect Table Sizes
SELECT table_name,
ROUND(((data_length + index_length) / 1024 / 1024), 2) AS size_mb,
ROUND((data_free / 1024 / 1024), 2) AS overhead_mb
FROM information_schema.TABLES
WHERE table_schema = 'your_database_name'
ORDER BY size_mb DESC;
Replace your_database_name with your WordPress database name. The results rank tables from largest to smallest, showing you which tables have the most overhead and would benefit most from optimization.
Expected Results
- Database size reduced by 20–60% (depending on accumulated bloat)
- Faster queries to
wp_options(expired transients are a major culprit) - Faster WordPress admin dashboard loading
- Reduced disk usage on your hosting plan
WordPress Hosting with SSD and phpMyAdmin — From 500 THB/year
AsiaGB Hosting includes phpMyAdmin, DirectAdmin, and Softaculous for 1-click WordPress installation. SSD storage and PHP 8.3 ensure fast database queries right out of the box.
View Hosting Plans →