How To Clean Your WordPress Database (And Old Plugin Tables) With WP-Optimize

Clean wordpress database

Cache plugins (kind of) clean your WordPress database, but they don’t let you remove tables left behind by old plugins.

They also don’t show you whether certain plugin modules are adding database bloat. This can happen when you run plugins & modules that collect lots of data (Wordfence, SEO plugins, etc).

That’s why you should install a database cleanup plugin like WP-Optimize. By removing unused tables and disabling plugin modules that add overhead, you can reduce your database size. This can speed up both the frontend and backend of your website while reducing CPU usage as well.

In this guide, we’ll install a database cleanup plugin, remove junk (trashed comments, transients, etc), remove old plugin tables, and learn which modules add the most overhead.

 

1. Backup Your WordPress Database

Use UpdraftPlus to backup your database.

You shouldn’t have to worry about this but in case anything goes wrong, you’ll have a backup. Install the plugin, go to your UpdraftPlus settings, and connect a third party service to download your files to (I use Dropbox). Once that’s done, you can do a 1-click backup. I normally don’t do this for regular maintenance but in case you’re not comfortable, a backup is always a good idea.

Updraftplus

 

2. Install WP-Optimize

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

Wp optimize

 

3. Remove Trash From Your Database

Now you’ll see 3 tabs for optimizations, tables, and settings.

We’ll start with optimizations. This is the junk most cache plugins already delete but you can also use WP-Optimize to do it. The screenshot below shows everything I would keep or delete.

Wordpress database cleanup wp optimize settings

  • Optimize database tables: similar to defragmenting a hard drive only with your WordPress database. This reclaims unused space in your database tables which reduces the amount of storage and makes accessing your tables more efficient.
  • Post revisions: before you delete post revisions, go to WP-Optimize → Settings and make sure you keep some post revisions (5-10 is usually fine). You want to keep some backups of your posts which are saved any time you hit the “publish” button. Or you can always limit post revisions manually with code or Perfmatters.
  • Auto draft posts: if you exited your browser while editing your site, WordPress will automatically save your work as an auto draft. I wouldn’t delete these just in case.
  • Trashed posts: when you delete pages/posts, they’re moved to the trash (delete).
  • Spam and trashed comments: comments you marked as spam or trash (delete).
  • Unapproved comments: blog comments you haven’t approved. Since I have moderate comments, there are usually quite a few of these I haven’t gotten to you. I wouldn’t delete them unless they’re all spam, so make sure you double check.
  • Expired transient options: unused cache data (for example, social sharing plugin store “share counts” on pages or posts). These expired transients can be deleted.
  • Pingbacks/trackbacks: notifies blogs when you link to them, but there’s no reason to store these in your database unless you want a record of them (delete).
  • Post meta data: information shown to users on each post (author, publish date, category, etc). This will delete orphaned meta data that doesn’t belong to a post.
  • Comment meta data: same as post meta data only for comment information.
  • Orphaned relationship data: usually created by plugins when posts are deleted.

 

4. Delete Tables Left Behind By Old Plugins

Next, go to WP-Optimize → tables.

Pay attention to tables marked as “not installed” or “inactive.” You’ll also see the Remove button in the Actions tab. These are tables left behind by old plugins you deleted or they’re currently deactivated (so you should delete them if you don’t plan on using the plugin again).

Wp optimize unused database tables

 

5. Disable Plugin Features Adding Bloat

While going through your database tables, you may see plugins that add lots of overhead.

Rank Math’s analytics, Wordfence’s live traffic report, and even the link counter in SEO plugins can accumulate quite a bit of data. Click the Overhead button to filter tables by their overhead.

Rank math database bloat

Some plugins are module-based or let you disable features in their settings. If a feature is adding lots of database overhead, consider disabling it if you think you can live without it.

Plugin modules causing database bloat

 

6. Schedule Ongoing Database Cleanups

I like WP-Optimize for scheduled database cleanups because it lets you keep a certain amount of post revisions and take a backup beforehand. I don’t believe any cache plugin can do either.

Wp optimize database cleanup settings 1

 

7. Use Other Plugins To Clean Your Database

Plugins Garbage Collector – similar to WP-Optimize only lets you delete any database table.

Plugins garbage collector database cleanup

Advanced Database Cleaner – I don’t like how they make you pay for the premium version to see which plugin each table belongs too, but it does have settings for cron jobs which is a plus.

Advanced db cleaner

FlyingPress – standard database cleanup setting for cache plugins (can’t keep post revisions).

Flyingpress database settings

LiteSpeed Cache – also lets you keep post revisions in the DB Optimization settings.

Litespeed cache database settings

WP Rocket – standard database cleanup setting for cache plugins (can’t keep post revisions).

Wp rocket database cleanup settings

SiteGround Optimizer – there are literally no database settings other than ON/OFF (not good).

Siteground optimizer database optimization

 

Frequently Asked Questions

How do I clean my WordPress database?

Install WP-Optimize and use it to remove junk along with unused database tables left behind by old plugins. You also use it to take backups before scheduling cleanups.

Which plugin is best for cleaning the WordPress database?

WP-Optimize lets you do many things most other database and cache plugins can't: remove unused tables, keep a certain amount of post revisions, and take backups during scheduled cleanups.

How often should you clean your database?

Once a week is fine for most sites. If you have a larger website or constantly install/delete plugins, you can clean your database more frequently.

Does WP Rocket clean your database?

Kind of. It removes some things but can't remove unused tables, keep post revisions, or take backups like WP-Optimize can.

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

You Might Also Like:

9 Comments...

  1. Hello,

    Thank you for such a detailed guide, which helped me a lot. I have a quick question.

    We have ‘WP-ROCKET’ installed as our Cache plugin right now. Can I also install and use ‘WP-Optimize’ as well? I mean at the same time. I want to use ‘WP-ROCKET’ for Cache purposes and ‘WP-Optimize’ for Database cleaning porpuses.

    Would I have any problems?

    Kind regards,
    Keep up the great work.

    Reply
    • Yes, you can use WP-Optimize only for database cleaning – that’s also what I do with FlyingPress. I believe the out of the box WP-Optimize settings don’t interfere with WP Rocket, but you may want to double check the settings and turn everything off except database options.

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

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

    Reply

Leave a Comment