As you use WordPress, your WordPress database inevitably gets bloated.
To clean your WordPress database, install a plugin like WP-Optimize and use it to remove spam comments, post revisions, auto drafts, transients, pingbacks, trackbacks, and unused tables left behind by old plugins. A cleaner database can make your website and admin significantly faster.
In this tutorial, I will be using WP-Optimize to clean the WordPress database. While some plugins like WP Rocket (and others) let you clean some of your database, they don’t always let you delete old plugin tables like WP-Optimize, WP-Sweep, or Advanced Database Cleaner.
By doing this, your database will run more efficiently and can, in turn, help you fix a slow WordPress site and make it load significantly faster. Cleaning your WordPress database is also recommended in WordPress’ optimization guide and is something you should do periodically.
How To Clean Your WordPress Database
1. Backup Your WordPress Database
Use UpdraftPlus to backup your database beforehand.
You shouldn’t have to worry about this, but just in case anything goes wrong, at least you will have a backup. Install the plugin, go to the UpdraftPlus settings, and connect a third party service to download your files to (I use Dropbox). Afterwards, you can do a 1-click backup.
2. Install WP-Optimize
Install the WP-Optimize plugin then go to WP-Optimize → Database.
3. Remove Trash From Your Database
In WP-Optimize, you will see settings for Optimizations and Tables.
In the Optimizations settings, you usually want to delete everything except for unapproved comments awpnd post revisions. If you’re fine with deleting unapproved comments (blog comments that have not yet been approved) or post revisions (previous drafts automatically taken by WordPress any time you make a revision to a page or post), you can delete these too.
Database Items (Definitions)
- Optimize database tables: similar to defragmenting a hard drive only with your WordPress database. This reclaims unused space in your database tables, reducing the amount of storage and makes accessing tables more efficient.
- Post revisions: automatically created every time your save or update a post.
- Auto draft posts: drafts WordPress automatically saves when you’re editing.
- Trashed posts: posts you have deleted.
- Spam and trashed comments: comments marked as spam or deleted.
- Unapproved comments: blog comments that you haven’t approved.
- Expired transient options: unused cache data (for example, social sharing plugin will store “share counts” on pages or posts).
- Pingbacks: a way to notify blogs you linked to them.
- Trackbacks: another way to notify blogs you linked to them.
- Post meta data: information shown to users on each post (eg. author, publish date, category). This will delete post meta data that doesn’t belong to any post.
- Comment meta data: same as post meta data only for comment information.
- Orphaned relationship data: often created by plugins when posts are deleted.
4. Delete Tables Left Behind By Old Plugins
In the WP-Optimize Tables tab, you will see your database tables.
Pay attention to tables that say “not installed” and have a Remove button next to them. These are tables left behind by old plugins that are not currently installed on your WordPress site (so you should delete them if you don’t plan on using them again). WP-Optimize also tells you the size and which plugin the table belongs to, which again, will be one you have already deleted.
5. Schedule Ongoing Database Clean Ups
I recommend scheduling an automatic database cleanup about once a week (or even more frequently for large sites with lots of plugins). You can find this under WP-Optimize → Settings.
If you’re already using a plugin like WP Rocket where database cleanup is built-in, you can use this to schedule weekly database cleanups, then only install WP-Optimize when you need to clean up database tables from deleted plugins (I always prefer having fewer plugins installed).
6. Other Plugins That Clean Your Database
Most other database cleanup plugins do the same exact thing as WP-Optimize
Advanced Database Cleaner – similar to WP-Optimize but lets you dive further into your database and lets you view cron jobs. The Premium version is primarily good for further cleaning your database of old plugins and has options for orphans, plugins, themes, and WP.
WP-Sweep – lets you clean additional options like user meta and term meta, but take a backup and only do this if you know what you’re doing (doing this will delete terms in your draft posts).
Plugins Garbage Collector – only lets you delete old plugin tables with mediocre reviews.
Breeze By Cloudways – a plugin developed by Cloudways hosting (they’re awesome). It lets you delete just a few important items in your database but does not let you optimize database tables or delete post meta data, comment meta data, or tables left behind by deleted plugins.
Frequently Asked Questions
⚙ Which plugin is best for database cleanup?
WP-Optimize lets you clean your database and leftover plugin tables while WP Rocket only lets you clean your database. For a full cleanup, I recommend using WP-Optimize.
⚙ How do you delete leftover plugin tables?
WP-Optimize has an option to delete tables left behind by old plugins you deleted. It will show you which plugin the table belongs to and include a prompt that says Not Installed with a Remove button.
⚙ What if I'm already using WP Rocket?
WP Rocket does not allow you to delete leftover plugin tables but is great for cleaning everything else in your database.
⚙ How often should you clean your database?
Once a week should be plenty for most websites. For larger websites with lots of plugins, you may want to clean it more frequently.
⚙ Will this break my website?
It shouldn't, but you should still take a backup beforehand. Plugins like WP-Optimize highlight actions with a low chance of causing errors and prompts you to take a backup.
I hope this article was helpful in cleaning your WordPress database and helped you speed up your site! If you have questions, leave a comment below and I’ll get back to you as soon as I can.
See Also: How I Got 100% GTmetrix Scores