How to Clean Up Your WordPress Database Safely
Every WordPress site collects clutter in its database. Each time you save a post, WordPress stores a revision. Spam comments pile up, trashed items linger, and plugins leave behind temporary data called transients. On an older site, this junk can run to tens of thousands of rows. Learning how to clean up your WordPress database keeps the admin responsive, shrinks backups and removes leftovers from plugins you deleted long ago.
In this guide, you’ll learn what fills up your database, how to clean it safely with a plugin or WP-CLI, how to stop it growing back and what to leave alone.
What Clutters a WordPress Database?
| Type of clutter | Where it comes from | Safe to remove? |
|---|---|---|
| Post revisions | Every save of a post or page | Yes, keep a few recent ones |
| Auto-drafts | Posts started and abandoned | Yes |
| Trashed posts and comments | Items moved to Trash | Yes, after checking |
| Spam and unapproved comments | Bots and spam filters | Spam yes; review unapproved first |
| Expired transients | Temporary cached data from plugins | Yes |
| Orphaned metadata | Data left after deleting posts or plugins | Usually, with care |
Why a Clean Database Matters
- Faster admin screens: fewer rows to search through when listing posts and orders.
- Smaller backups: backups finish faster and cost less to store.
- Quicker migrations: moving hosts or creating a staging copy takes less time.
- Easier troubleshooting: less noise when you need to find a real problem.
Be realistic: a database cleanup rarely transforms front-end speed on its own. Page caching and image optimisation matter more for visitors. Cleanup’s biggest wins are in the admin, backups and overall housekeeping.
Step 1: Back Up Your Database First
Database cleanup deletes data permanently. Before you start, take a full backup with your host’s backup tool or a backup plugin, and confirm you know how to restore it. On a busy WooCommerce store, run the cleanup during a quiet period.
Step 2: Clean the Database With a Plugin
Minimal DB Optimizer from Simpli Plugin is a free, lightweight plugin that removes the most common database junk in one click: obsolete revisions, spam and unapproved comments, trashed items and expired transients. There are no complicated menus to work through.
- Download the plugin ZIP from its product page.
- Go to Plugins → Add New Plugin → Upload Plugin.
- Upload the file, click Install Now, then Activate Plugin.
- Open the plugin’s screen, review what it will remove and run the cleanup.
Afterwards, browse the site and the admin to make sure everything works as expected.
Running a large store or membership site with a slow admin? Simpli Plugin’s team builds custom performance tooling and can audit what’s really slowing your database down.
Alternative: Clean the Database With WP-CLI
If your host provides SSH access, WP-CLI offers precise control. Useful commands:
# Delete expired transients
wp transient delete --expired
# Count post revisions before deleting
wp post list --post_type=revision --format=count
# Delete all post revisions
wp post delete $(wp post list --post_type=revision --format=ids) --force
# Optimise database tables
wp db optimize
Run the count command first so you know how much will be deleted, and always back up before running delete commands.
Step 3: Stop the Clutter Coming Back
Two lines in wp-config.php, placed above the line that says “That’s all, stop editing!”, keep the database lean from now on:
define( 'WP_POST_REVISIONS', 5 );
define( 'EMPTY_TRASH_DAYS', 7 );
The first keeps only the five most recent revisions of each post. The second empties the trash automatically after seven days instead of the default thirty.
What Not to Delete
- Active transients: delete only expired ones; active transients are in use.
- WooCommerce sessions and orders: never delete order data or active customer sessions.
- Options you don’t recognise: plugin settings live in the options table. Leave unfamiliar entries alone unless you’re sure the plugin is gone.
- Unapproved comments: review them first; some may be from real customers.
How Often Should You Clean Up?
Monthly is plenty for most sites. Busy content sites with many editors may prefer every two weeks; small brochure sites can clean up every few months.
Related Guides
- How to Remove Query Strings From Static Resources in WordPress
- How to Disable Emojis in WordPress
- How to Put WordPress in Maintenance Mode (Without Hurting SEO)
Frequently Asked Questions
Is it safe to delete post revisions?
Yes, once you’re happy with the current version of your content. Keep a few recent revisions in case you need to undo a change.
Will cleaning the database speed up my site?
Mostly in the admin area and in backups. For visitor speed, caching and image optimisation usually make a bigger difference.
What are transients?
Temporary cached data that plugins and themes store in the database. Expired transients are safe to delete; WordPress recreates them when needed.
Do I need to optimise tables?
Optimising reclaims space after large deletions. It’s useful after a big cleanup, not something you need to do daily.
Keep Your Database Lean
A tidy database means faster admin screens, smaller backups and easier maintenance. Back up first, remove revisions, spam and expired transients, then limit revisions so the clutter doesn’t return.
Download Minimal DB Optimizer for free, and browse the full Simpli Plugin library. If you need a deeper performance audit, our developers can help.