Tutorial: Remove leftover plugin database tables from WordPress

Most WordPress website owners will install and test a handful of plugins over time without being aware that every time they do so, they are creating new database tables that remain in place well after the plugins have been uninstalled.

Over time, this could negatively impact your website’s performance as the database beings to accumulate junk, resulting in poor database load and speed deficiencies.

However, this is not the case for all plugins; some developers add the option for you to remove all data and tables when the plugin is deactivated or removed. And some plugins do not create new tables at all.

So how do you remove unwanted database tables?

There are two ways to do this:

  1. Dig into your database tables and delete them manually via phpMyAdmin
  2. Install plugins that can do the job for you directly from inside your WordPress website
Important!: Always backup your database before attempting to make any changes.

Deleting WordPress tables manually via PHPmyAdmin

I wouldn’t recommend diving into your database using phpMyAdmin unless you have a working understanding of how the application works. There are hundreds of video tutorials on Youtube for you to learn and understand how phpMyAdmin works.

You will also need to have a basic understanding of the default WordPress database table structure and at least know what role each table plays.

Below is a list of the default database tables that come with WordPress. There are precisely 12 tables.

On the same database, I have installed the popular security plugin WordFence. You will notice that the database no longer has 12 tables, it now has 32. This is because the plugin has added an additional 20 tables.

Since I have only installed WordFence, I can instantly identify the new tables which are not required for WordPress to function. I will now uninstall the plugin (without selecting the option to remove data and tables), and I will show you what the database looks like after the plugin is removed.

WordFence is one of the many few plugins that have the option for you to remove all data and tables from your database if the plugins is removed.

OK, so I have deleted the WordFence plugin. Can you tell the difference?

If the answer to my question was no, then you are right. This is because when I removed the plugin, no database tables were deleted. 

Installing and deleting plugins over time will result in your database growing unnecessary with tables and data your website no longer needs. And this will sadly lead to your website slowing down.

As I was able to identify what tables Wordfence added to the database, I can now safely drop them, which means to delete them. I will not explain phpMyAdmin functions today, but there is a cool video put together by HostGator, where they explain how the DROP function works.

Use plugins to delete leftover database tables

Using a plugin specifically developed to clean leftover database tables may be the best and easiest option if you do not feel comfortable jumping into phpMyAdmin. Please remember, and I can’t stress this enough, DO NOT attempt to make any changes to your database without BACKING UP. There is no turning back once you have deleted a database table.

The plugin I recommend for the job is Plugins Garbage Collector. This plugin scans your WordPress database and finds database tables that are orphaned or are no longer in use.

Once you install the plugin, you will see the following options.

For this example, I am going to remain using WordFence’s database tables as a reference.

As you can see above, the scan has recognised all tables that do not belong to WordPress. It displays all database tables left behind in red. I will now check all tables highlighted in red, and then I will click on Delete Tables.

Job done. All leftover database tables have been removed.

This may seem like a straightforward process but remember that I only installed one plugin. If you have installed and removed multiple plugins over time, the list of tables will be larger, and they may be a little more challenging to identify.

Although the plugin highlights tables in red, make sure you research what plugins the tables belong to as you don’t want to delete tables that belong to plugins you currently have installed.

Additional Data

As well as junk tables, plugins and themes also leave behind a lot of junk in your wp_options table. A bloated wp_options table is the number one cause of slow WordPress websites.

Check out Clean Options; this is a great little tool that will help clean orphaned options in your wp_options table.

Another tool I use to keep databases in tip-top shape is WP Sweep. This plugin will assist in cleaning your database by deleting unused, duplicate and orphaned data and it can also help optimize your database.

Please remember, as a rule of thumb, to make sure you make a backup of your database before attempting to make any changes.