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.



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.

Wp-optimize clean database

Definitions Of Database Items

  • 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 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: notifies blogs when you link 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

Some plugin modules create a lot of database bloat especially if they’re required to collect statistics or show information in your WordPress admin. For example, many modules in Rank Math’s SEO plugin and Yoast create database bloat, so disable them if you’re not using them.

Rank math database bloat


5. Schedule Ongoing Database Cleanups

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. Use Other Plugins To 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).

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


About Tom Dupuis

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

11 thoughts on “How To Clean Your WordPress Database (And Old Plugin Tables)

  1. Delighted in perusing the substance above, really clarifies everything in detail, the article is very intriguing and successful. Much thanks to you and best of luck with the articles.

  2. Enjoyed reading the content above, actually explains everything in detail, the article is extremely interesting and effective. Thank you and good luck with the articles.

Leave a Reply

Your email address will not be published.