Optimize WordPress database remove bloat speed up

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?

TypeDescriptionSafe to Remove?
Post RevisionsA copy saved every time you edit a post — can reach dozens per postYes (keep 3–5 latest)
Auto DraftsAuto-saved drafts WordPress creates while editingYes
Trashed Posts/PagesDeleted content still sitting in the trashYes
Spam CommentsComments marked as spamYes
Trashed CommentsDeleted comments still in trashYes
Expired TransientsTemporary plugin cache stored in wp_options that has expiredYes
Orphaned MetadataPost/user metadata linked to deleted itemsYes (verify first)
Unused Plugin TablesTables left behind by uninstalled pluginsYes (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.

  1. WordPress Admin → Plugins → Add New → search WP-Optimize
  2. Install → Activate
  3. Go to WP-Optimize → Database
  4. 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
  5. Click Run all selected optimizations
  6. 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.

  1. WordPress Admin → Plugins → Add New → search Advanced Database Cleaner
  2. Install → Activate
  3. Navigate to WP Admin → Advanced DB Cleaner
  4. Under General Clean Up, review all detected junk items
  5. Under Orphaned Tables, identify tables left by removed plugins — verify each before deleting
  6. 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

  1. DirectAdmin → Databases → phpMyAdmin → select your WordPress database
  2. Select all tables (Check All at the bottom)
  3. In the "With selected" dropdown, choose Optimize table
  4. 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

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 →