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

Home » WordPress Speed Tips & Tricks » How To Clean Your WordPress Database (And Old Plugin Tables)

As you use WordPress, your WordPress database inevitably gets bloated.

Leftover plugin tables, expired transients, pingbacks, trackbacks, spam and trash comments, auto drafts, and potentially thousands of unused post revisions can be left in your database.

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.

 

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

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

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

Cheers,
Tom

View More Tutorials

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x