Every WordPress site collects junk in its database that you never see on the front end — old revisions, abandoned drafts, spam comments, leftover plugin data. None of it shows up in your admin dashboard as a problem. It just quietly makes every query a little slower, until one day your site feels sluggish and you can't figure out why. This is almost always the reason.
Here's how I clean a client's database, in the order I actually do it.
Every time someone visits a page, WordPress runs multiple database queries to pull together the content, menus, widgets and settings. A lean database answers those queries fast. A bloated one — thousands of unused revisions, years of spam comments, orphaned metadata from plugins you uninstalled two years ago — makes the same queries work harder for no benefit.
This isn't usually the first thing I check on a slow site, but on older sites (two, three, five years of posting) it's often a bigger factor than people expect, especially on budget hosting where the database server itself is under-resourced.
Post revisions. WordPress saves a new revision every time you update a post or page — by default, forever. A post you've edited 40 times has 40 saved copies sitting in your database.
Auto-drafts and trashed posts. Every time you start a new post and don't finish it, WordPress quietly saves an auto-draft. These pile up for years.
Spam and unapproved comments. If you've ever had a comment spam problem, those entries are probably still in your database even after you marked them as spam.
Transients. These are temporary cached values plugins use — think of them as sticky notes that are supposed to self-destruct. A lot of plugins never clean up after themselves, so expired transients can sit there indefinitely.
Orphaned metadata. When you delete a plugin, it often doesn't remove the data it created. Years of uninstalled plugins can leave behind thousands of orphaned rows nobody's using.
Before cleaning old ones, stop the problem from growing back. Add this line to your wp-config.php file, just above the "That's all, stop editing" comment:
define('WP_POST_REVISIONS', 5); This caps revisions at 5 per post instead of unlimited. You can set it to a number that works for you, or false to disable revisions entirely (not recommended if you ever need to roll back an edit).
In wp-config.php, add:
define('EMPTY_TRASH_DAYS', 7); This tells WordPress to permanently delete trashed posts and spam comments after 7 days instead of leaving them indefinitely.
Doing this manually through phpMyAdmin is possible but risky if you're not comfortable writing SQL. A plugin makes it safer:
Either one will scan your database, show you what it found, and let you review before deleting. Don't use the "clean everything automatically" option the first time — look at what it's proposing to remove first.
Cleaning removes rows; optimizing reclaims the disk space and rebuilds table indexes so queries run faster. Most cleanup plugins have an "optimize tables" button that does this in one click after the cleanup step. If you're doing it manually in phpMyAdmin, select all tables and run OPTIMIZE TABLE.
This is the step most cleanup plugins handle poorly. If you've uninstalled plugins over the years, search your database tables for prefixes matching old plugin names (Advanced Database Cleaner is good at surfacing these) and remove them manually once you've confirmed the plugin isn't coming back.
If you've already fixed your hosting, images and caching and the site is still dragging on an older install, this is usually the next place to look.
Need to troubleshoot other speed issues? I cover the full troubleshooting order in my guide to fixing a slow WordPress website.
Database cleanup plugins are generally safe, but "generally" isn't "always." I've seen a badly configured cleanup wipe out WooCommerce order metadata on a site that hadn't been backed up first. Take the backup seriously, test on a staging site if you have one, and review what a plugin found before clicking delete.
If you need your database cleaned, optimized, and reviewed with proper backups, I can handle this as part of a full site health check.
Contact Now Visit AjayMaanju.comWill cleaning my database break anything?
Not if you back up first and review what's being deleted. The actual risk is low, but it's not zero — always have a backup you can restore from.
Does database optimization really make a noticeable speed difference?
On a small, well-maintained site, barely. On a 5-year-old site with tens of thousands of unused revisions and orphaned plugin data, it can be significant — I've seen query times drop noticeably after a thorough cleanup.
Can I just disable post revisions completely?
You can, but I wouldn't. Revisions are genuinely useful when you need to undo a bad edit. Capping them at 5–10 gets you most of the storage savings without losing that safety net.
Cite this page: Maanju, A. (2026). WordPress Database Optimization: Complete Guide to Cleaning & Improving Performance. ajaymaanju.com. Updated October 13, 2026.
Ajay helps businesses grow online through high-performance websites, SEO strategy and mobile application development — including WordPress builds, speed and Core Web Vitals work, and site rescues. You work directly with him, not an account manager. Explore services at ajaymaanju.com →
Automated page speed optimizations for fast site performance