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 and 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 you 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 plugins are best for cleaning your WordPress database?
WP-Optimize and Advanced Database Cleaner are two plugins for thoroughly cleaning your database. They can optimize a lot more than automatic plugins such as WP Rocket.
How do you delete old WordPress plugin tables?
WP-Optimize and Advanced Database Cleaner have options to delete tables left behind by old plugins. They show you which plugin the table belongs to with a Not Installed prompt and a Remove button.
Does WP Rocket clean your database?
WP Rocket cleans some of your database (post revisions, auto drafts, transients, etc) but doesn't delete old plugin tables.
How often should you clean your database?
Once a week should be plenty for most sites. For larger websites with lots of plugins, you may want to clean it more frequently.
What does cleaning your database do?
Cleaning your database deletes post revisions, auto drafts, trashed posts, spam comments, trashed comments, transients, and database tables.
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: My Ultimate WordPress Speed Guide