Skip to main content

Database Cleanup

Database optimization removes unnecessary data and optimizes table structure, improving query performance and reducing storage requirements.

What Slows Down a Database?

Over time, WordPress databases accumulate:

  • Post revisions — every draft and auto-save creates a revision
  • Trashed items — deleted posts/comments stay in trash
  • Transient data — expired temporary data not cleaned up
  • Meta orphans — orphaned post/comment metadata
  • Table fragmentation — tables become physically fragmented

This causes:

  • Slower queries
  • Larger database backups
  • More disk space usage
  • Higher memory consumption

What Database Cleanup Does

Performance Toolkit's database cleanup:

1. Remove Post Revisions

Retains latest revision per post; removes old revisions:

  • Saves 20-40% database space for media-heavy blogs
  • Improves query performance
  • Keeps latest version safe
  • Safe to run regularly

2. Remove Post Auto-Drafts

Automatically deletes:

  • Auto-save drafts with no content
  • Temporary editor states
  • Incomplete work-in-progress posts
  • Usually 5-10 MB per site

3. Empty Trash

Permanently deletes:

  • Posts/pages in trash
  • Comments in spam folder
  • Unused attachments
  • Usually not a big impact but good hygiene

4. Delete Orphaned Metadata

Removes:

  • post_meta with no post (post deleted, meta remained)
  • comment_meta with no comment
  • user_meta with no user
  • Usually recovers 2-5 MB

5. Optimize Tables

Defragments WordPress tables:

  • Reorganizes physical table structure
  • Improves query speed
  • Reclaims fragmentation space
  • Usually recovers 5-15%

6. Optimize Table Indexes

Rebuilds table indexes:

  • Speeds up WHERE/JOIN queries
  • Reduces memory usage
  • No data loss; improves performance only

Enabling Database Cleanup

  1. Go to Performance ToolkitDatabase
  2. Review suggested cleanups
  3. Check which operations you want to run:
    • ✅ Remove post revisions
    • ✅ Remove auto-drafts
    • ✅ Empty trash
    • ✅ Delete orphaned metadata
    • ✅ Optimize tables
  4. Click Run Cleanup

The plugin runs all selected operations and shows results.

Using Database Cleanup Safely

Before First Cleanup

  • Backup your database — always have a recent backup
  • Test on staging — try on a staging/dev version first
  • Check timing — run during low-traffic hours
  • Plan for downtime — optimization locks tables (brief locks)

Running Cleanup

  1. Go to Performance ToolkitDatabase
  2. Review items to clean:
    • Estimated revisions to remove
    • Estimated orphaned meta entries
    • Database fragmentation %
  3. Run cleanup during low-traffic time
  4. Monitor completion — usually takes 1-5 minutes depending on database size
  5. Verify site works — test a few pages after completion

Results

The plugin shows:

  • ✅ How many revisions removed
  • ✅ How much space recovered
  • ✅ Query optimization improvements
  • ✅ New database size

Typical results:

  • Database size reduction: 10-30%
  • Query performance: 5-15% faster
  • Backup size: 15-25% smaller

After Cleanup

  • ✅ Site performance improved (especially queries)
  • ✅ Backups smaller and faster
  • ✅ Disk space freed
  • ✅ Database more efficient

Schedule Regular Cleanups

Clean database monthly or quarterly:

  1. Go to Performance ToolkitDatabase
  2. Check Schedule auto cleanup (if available)
  3. Set frequency (monthly recommended)

Or manually:

  • Mark calendar to clean every 1-3 months
  • Run during low-traffic window
  • Monitor performance trends

What NOT to Delete

The plugin is safe and preserves:

  • ✅ All published posts/pages
  • ✅ All comments
  • ✅ Current post metadata
  • ✅ Custom post types and data
  • ✅ Any plugins using post_meta

Troubleshooting

Site became very slow after cleanup

Unlikely, but if it happens:

  1. Restore from backup
  2. Check if backup has same slowness
  3. Contact hosting provider

Cleanup didn't finish

Usually due to large database:

  1. Increase PHP timeout in wp-config.php:
    define('WP_MEMORY_LIMIT', '256M');
  2. Try again
  3. Contact hosting provider if still failing

Can't find Database page

The Database page is in: Performance Toolkit → (Main menu) → Database

If not visible:

  • Ensure Performance Toolkit is activated
  • Verify you have admin permissions
  • Refresh admin area

Performance Impact

Typical improvements from database cleanup:

OperationImpactFrequency
Remove revisions20-40% space savedMonthly
Delete orphans2-5% space savedQuarterly
Optimize tables5-15% faster queriesMonthly
Empty trash1-2% space savedAs needed

Combined effect:

  • Monthly cleanups recover 25-50% database space
  • Query performance improves 5-20%
  • Backup time reduced proportionally

Best Practices

  • ✅ Backup before first cleanup
  • ✅ Run monthly for active blogs (frequent publishing)
  • ✅ Run quarterly for mostly-static sites
  • ✅ Run during low-traffic hours
  • ✅ Monitor database size trends
  • ✅ Combine with other optimizations

Database optimization works best with:

  • Page caching — reduces database query load
  • File optimization — focuses on asset performance
  • Media optimization — reduces image traffic
  • CDN integration — offloads content delivery

Clean database + caching = maximum performance.