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
- Go to Performance Toolkit → Database
- Review suggested cleanups
- Check which operations you want to run:
- ✅ Remove post revisions
- ✅ Remove auto-drafts
- ✅ Empty trash
- ✅ Delete orphaned metadata
- ✅ Optimize tables
- 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
- Go to Performance Toolkit → Database
- Review items to clean:
- Estimated revisions to remove
- Estimated orphaned meta entries
- Database fragmentation %
- Run cleanup during low-traffic time
- Monitor completion — usually takes 1-5 minutes depending on database size
- 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:
- Go to Performance Toolkit → Database
- Check Schedule auto cleanup (if available)
- 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:
- Restore from backup
- Check if backup has same slowness
- Contact hosting provider
Cleanup didn't finish
Usually due to large database:
- Increase PHP timeout in wp-config.php:
define('WP_MEMORY_LIMIT', '256M');
- Try again
- 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:
| Operation | Impact | Frequency |
|---|---|---|
| Remove revisions | 20-40% space saved | Monthly |
| Delete orphans | 2-5% space saved | Quarterly |
| Optimize tables | 5-15% faster queries | Monthly |
| Empty trash | 1-2% space saved | As 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
Related Features
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.