WordPress Database Optimisation: How to Clean Up and Speed Up Safely
What slows a WordPress database: revisions, transients, spam, leftover plugin data and autoloaded options, plus how to clean up safely with backups, the right plugins and sensible limits.

On this page
- Revisions, transients, spam, plugin leftovers and autoloaded options bloat the database.
- Back up first, then clean spam, trash, old revisions and expired transients.
- Limit revisions, be careful with leftover tables and clean up every few months.
Every WordPress site stores its content and settings in a database. Over the years it collects clutter: hundreds of post revisions, expired temporary data, spam comments and leftovers from plugins you deleted long ago. On older and busier sites, cleaning it up can make the dashboard and uncached pages noticeably quicker.
What bloats a WordPress database
- Post revisions: WordPress saves a copy every time you update a page
- Auto-drafts and trashed posts
- Spam and trashed comments
- Expired transients: temporary cached data that hasn't been cleared
- Leftover plugin data: tables and settings from removed plugins
- Autoloaded options: settings loaded on every page; too many slow every request
- Logs: some security, email and scheduling plugins keep large logs
Always back up first
Database clean-up deletes data permanently. Take a full backup and confirm you can restore it before you start; see backup and restore guide.
Safe clean-up steps
- Delete spam and trashed comments
- Empty the trash for posts and pages
- Remove old revisions, keeping a few recent ones
- Clear expired transients
- Optimise database tables
Plugins such as WP-Optimize or Advanced Database Cleaner can do this, and some caching plugins include database tools. Run the clean-up, then remove or deactivate the tool if you don't need it regularly.
Limit revisions going forward
You can limit how many revisions WordPress keeps by adding a line to wp-config.php, for example keeping the last five. Ask your developer if you're not comfortable editing this file.
Be careful with leftover tables and options
Removing data left by old plugins helps, but deleting the wrong table can break a working feature. Only remove leftovers you're sure belong to plugins you no longer use, or have a developer review them.
Autoloaded options
If a plugin stores large amounts of data as autoloaded options, every page load pays the price. Recent versions of WordPress Site Health can warn when autoloaded data is too large. Fixing it usually means removing or replacing the plugin responsible.
WooCommerce stores
Stores accumulate customer sessions, order notes and scheduled action logs. WooCommerce has built-in tools to clear some of these under WooCommerce → Status → Tools. Never delete order data without accounting approval.
How often?
For most business sites, a clean-up every few months is plenty. See the maintenance checklist.
Database work is one part of speed; also see caching explained and why your site is slow.
Need help with your website?
I'm Sameer, a freelance WordPress developer building fast, SEO-friendly websites since 2020. Tell me what you need and I'll reply with a plan and a fixed quote within 24 hours.


