How To Clean Your WordPress Database (And Old Plugin Tables)

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.

 

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.

UpdraftPlus-Backup-and-Restoration

 

2. Install WP-Optimize

Install the WP-Optimize plugin then go to WP-Optimize → Database.

WP-Optimize-Plugin

 

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.

WP-Optimize Clean Database

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.

WP Optimize Tables

 

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.

WP Optimizer Scheduled Database Cleanup

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).

WP Rocket Automatic Database Cleanup

 

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.

Advanced-Database-Cleaner

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).

WP Sweep Settings

Plugins Garbage Collector – only lets you delete old plugin tables with mediocre reviews.

Plugins Garbage Collector Scan

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.

Breeze Database Cleanup

 

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

Cheers,
Tom

About Tom Dupuis

Tom Dupuis 2017Tom Dupuis writes WordPress speed and SEO tutorials out of his apartment in Denver, Colorado. In his spare time, he plays Rocket League and watches murder documentaries. Read his bio to learn 50 random and disturbing things about him.

Subscribe
Notify of
guest
4 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments