Cleaning Up Left Over Plugin Database Tables

Unlike traditional website platforms which run purely on HTML, WordPress includes both files and database tables.

The core software uses some tables which are crucial for the software to work however your plugin tables aren’t.

When you install a plugin it generally adds tables to your database.

The problem is, it doesn’t delete them when you delete the plugin. It normally only deletes the plugin files.

See this screenshot as a typical example:

Delete Plugins

Its clear that this function within your dashboard only deletes the files created when you installed the plugin.

Note: Not all plugins create database tables and some plugins give you the option to uninstall the plugin tables as well.

The reason most plugins don’t include the uninstall function is because the plugin author hasn’t included it in the plugin. Simply as that.

It might not work if the plugin isn’t coded correctly and most plugins are free so why would they risk it?

Plugins can have uninstall support easily built in, via an uninstall.php file (easiest way). This file simply gets executed when you select to “delete” the plugin from the Plugin Manager. Ideally, the plugin author would use this space to remove options, tables, etc.

So what next?

How do we remove all the unwanted tables left over in your database after you tried out different plugins but decided you really don’t like or need them?

There’s 2 ways to do this:

  1. Dig into your tables and delete them manually
  2. Install some more plugins which do this job for you
Big Caution: Backup your database before deleting tables.

Plugins That Remove DB Tables

There’s several plugins which i have tested on a local installation that work well.

I’ll now give you an overview of how i used them to remove the tables left over after deleting unwanted plugins .

By the way, my DB is over 100mg and i have tested hundreds of plugins before i started using a local installation of WordPress so it’s perfect for this task.

Plugins Garbage Collector

After you install Garbage Collector, you’ll find the settings under the Tools tab in your Dashboard.

Plugins Garbage Collector

Select Search non-WP Tables and click Scan then wait.

You’ll then get a list of the non core tables still included in your database that belong to plugins which have have deactivated or deleted.

Non Core Tables

What you can do then is check them and Delete the Tables.

Another warning from the author: Operation rollback is not possible. Consider to make database backup first. Please double think before click button.

Sorry to sound like a broken record folks!

It’s not awalys crystal clear which plugins use which tables as some of the table names are weird but you can be assured they are non core.

If your server space is managed by WPEngine, then you get the awesome backup and restore tool that reverses any errors quickly and easily.

Before you nearly die of boredom, let’s check out a couple more plugins which delete options and optimize your db.

Clean Options

This plugin cleans up any options in your wp_options table which have become orphaned after you deleted the plugin which created them.

Note: This doesn’t clean up any options which are used by plugins or themes that have been deactivated. You’ll need to delete the files first in order to use this plugin for cleaning up their options.

Clean Options

Click Find Options.

You’ll then get a screen full of these.

Possibly Orphaned Options

Its clear most of these have been created by plugins so you can easily delete the one’s which are individually.

Any that you’re not clear on, follow the instructions to search for more info on them so you can check what they’re used for.

Option Search Box

Option Name Search

Pretty clear this is a tedious task however you will learn a lot of how a database works if that’s your thing!

Database Optimization Plugins

There’s a couple of plugins that i use weekly which simply remove some junk.

They are:

  1. WP Optimize and
  2. WP Clean Up

WP Cleanup

I’ve already written about how to optimize your database.

They’re very basic and easy to use and should be used before you start cleaning up your tables.

Basically they Optimize your database tables and remove:

  • Post revisions
  • Spam Comments

Result After Cleanup

Depending on how many unused tables you cleaned up, you will find that your site will run significantly faster and more efficiently.

Pingdom Tools

I know my database is now about half the size as i created a backup before and after the cleanup.

This is before i’ve even removed any options.

Databases

Feels great when you’ve optimized your db and your site loads faster!

I’ll also be writing about how to do this job manually at some stage if you’re interested.


Comments

9 responses to “Cleaning Up Left Over Plugin Database Tables”

  1. […] How to delete unused data tables in WordPress […]

  2. […] The “proper” way to remove unneeded tables scares most people and can break your site. A simpler way – Plugins Garbage Collector – does a good enough job. But you can still break your site with it. Brad Dalton over at WP Sites has a more detailed write-up on cleaning up leftover database tables. […]

  3. […] was able to find another article which articulates this point […]

  4. Brad,
    Thanks for this. Have you got a similar one for cleaning up the Media gallery – I have so many unused images, but I don’t want to trash my site in getting rid of them and find I have to put them back !

    BWs
    James

    1. Brad Dalton Avatar
      Brad Dalton

      Hi James

      Good question. I don’t think i’ve written about that before so i’ll find a solution for cleaning up unused images and write about it soon.

      1. Brad Dalton Avatar
        Brad Dalton

        Here’s the link to a simple tutorial on how to find and cleanup unused image files http://wpsites.net/media/finding-deleting-unused-images-in-your-media-library/

  5. Michael Cordova Avatar
    Michael Cordova

    Brad,
    This is on my list for multiple sites we have in development right now. Totally appreciate your thoughtful efforts here. I’ll dig into it

    1. No worries Michael. Put this one off for a long time but its really not difficult.

      The only time consuming part would be to check all the options manually to be on the safe side before removing them.

      What you could do is take a backup of your db after using garbage collector and use that as the restore point if you accidently remove an important option and break you site.

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.