In this guide: How to clean up a slow WordPress database: why databases get bloated, backing up first, removing revisions and spam, optimizing tables, and automating cleanup.
Every WordPress site stores its content, settings, and activity in a database. Over time, that database collects clutter: hundreds of post revisions, spam comments, expired temporary data, and leftover tables from plugins you deleted years ago. A bloated database can slow down your admin area and dynamic pages.
Here’s how to clean it safely.
Why databases get bloated
Common sources of database clutter:
- Post revisions: WordPress saves a revision every time you save a draft or update a post. A frequently edited post can have dozens.
- Auto-drafts and trashed posts.
- Spam and trashed comments.
- Expired transients: temporary cached data stored by plugins that sometimes isn’t cleaned up.
- Orphaned metadata: post meta, comment meta, or user meta left behind after content was deleted.
- Leftover plugin tables and options: many plugins don’t remove their data when uninstalled.
- Autoloaded options: data in the
wp_optionstable loaded on every page request. Too much autoloaded data slows every page. - Logs: security, email, and activity log plugins can create very large tables.
- WooCommerce sessions and action scheduler logs.
Backing up first
Always back up your database before cleaning. Deleting data is permanent.
- Use your backup plugin or hosting backup tool to create a fresh backup.
- Download a copy or ensure it’s stored off-site.
- For large or critical sites, test the cleanup on a staging copy first.
See Website Backups: The 3-2-1 Rule Explained.
Cleaning revisions and spam
The easiest method is a cleanup plugin such as WP-Optimize, Advanced Database Cleaner, or the database tools in LiteSpeed Cache or WP Rocket.
Typical cleanup tasks:
- ☐ Delete post revisions (optionally keep the last few).
- ☐ Delete auto-drafts.
- ☐ Empty trashed posts and comments.
- ☐ Delete spam comments.
- ☐ Delete expired transients.
- ☐ Remove orphaned post and comment meta.
Limit future revisions by adding this line to wp-config.php:
define( 'WP_POST_REVISIONS', 5 );
This keeps the five most recent revisions per post — enough for safety, without endless buildup.
Leftover plugin tables: tools like Advanced Database Cleaner can identify tables and options not used by active plugins. Be careful — only delete data you’re sure belongs to removed plugins.
Large log tables: configure logging plugins to keep only 30–90 days of data, or disable logs you don’t use.
Optimizing tables
After deleting data, database tables may still hold unused space. Optimizing reorganizes tables and reclaims that space.
- Most cleanup plugins include an “optimize tables” option.
- You can also use phpMyAdmin: select tables → “Optimize table.”
Check autoloaded data:
The wp_options table can slow your site if it contains too much autoloaded data. Some cleanup plugins and Site Health tools show autoloaded data size. Large autoloaded entries from deleted plugins can often be removed or set to not autoload — carefully.
Use object caching: for busy sites, Redis or Memcached reduces repeated database queries — ask your host.
Check the database engine: modern WordPress tables should use InnoDB, not the old MyISAM engine. Your host can help convert.
Automating cleanup
Set it and forget it:
- Schedule a weekly cleanup of revisions, spam, trash, and transients in your cleanup plugin.
- Keep
WP_POST_REVISIONSlimited. - Set log retention limits in security and email log plugins.
- Empty trash automatically (WordPress does this after 30 days by default; you can change it with
EMPTY_TRASH_DAYS). - Review database size monthly as part of your maintenance routine — see Monthly Website Maintenance Checklist.
What not to do:
- Don’t delete tables you don’t recognize without research.
- Don’t run aggressive cleanup on a live WooCommerce store during peak hours.
- Don’t skip backups.
Further reading: official WordPress documentation
Key Takeaways: WordPress Database
- Revisions, spam, transients, logs, and leftover plugin data bloat databases.
- Always back up before cleaning.
- Use a cleanup plugin to remove clutter and optimize tables.
- Limit revisions, control logs, and schedule weekly automatic cleanup.

