How To Reduce Database Bloat On WordPress

Trying out different plugins is a natural part of building a great WordPress website. But what you might not know is that every plugin you test leaves behind a hidden footprint – its own database tables. These unused tables pile up like a graveyard, silently bloating your website’s database and slowing it down over time.

Responsible plugin developers take the time to integrate optimisation tools that can remove all associated data and tables when you deactivate the plugin. Unfortunately, this best practice isn’t always followed, and some plugins leave their mark on your database.

Why Don’t Plugins Always Clean Up After Themselves?

The simple reason is that some plugin developers haven’t included the functionality to remove database tables upon deactivation.

How to Clean Up Unwanted Database Tables

There are two main approaches to tackle this issue:

  • Manual Removal with phpMyAdmin: This method involves directly accessing your database tables through phpMyAdmin and deleting them manually. However, this approach requires some technical knowledge and is recommended for experienced users only.
  • Cleaning Up with WordPress Plugins: Fortunately, several WordPress plugins can automate this process. These plugins scan your database for unused tables and offer options to remove them safely from within the WordPress dashboard.

Warning! Always backup your database before attempting to make any changes.

Manual Removal with phpMyAdmin

Not Recommended for Beginners.

The first approach, manually deleting tables with phpMyAdmin, is best left to experienced users. It requires a solid understanding of the default WordPress database structure. You’ll need to identify tables unrelated to WordPress core functionality and pinpoint which tables belong to specific plugins. This process can be quite complex.

A Glimpse into the WordPress Database:

To illustrate the potential challenges, let’s take a look at a clean WordPress database – one without any plugins installed. As you’ll see in the example below, a default database typically consists of around 12 tables.

Default WordPress Database Structure

Now, if we install Wordfence, the number of tables jumps to 32. This significant increase (20 additional tables) demonstrates how plugins can bloat your database. These extra tables store information specific to Wordfence’s functionality, such as security logs or firewall settings. While valuable, they contribute to the overall size of your database.

Since we’ve only installed Wordfence in this example, we can easily identify the new tables it created. These are the tables that aren’t required for WordPress to function. Let’s uninstall Wordfence and see how the database changes.

The plugin has been deleted, can you tell the difference?

No, you can’t. Uninstalling Wordfence in this example didn’t remove any database tables. Imagine the impact after months or years of installing and removing plugins! Your database becomes cluttered with junk, potentially impacting performance.

Luckily, since we only have Wordfence, identifying its tables is simple. We can now safely delete (drop) them using phpMyAdmin.

However, for today, we’ll focus on the bigger picture. But here’s a helpful video by HostGator on YouTube explaining how to drop database tables if you want to give it a go.

By default, Wordfence offers an option to delete all database tables upon deactivation. As mentioned earlier, not all plugins have this helpful feature.

Cleaning Up with WordPress Plugins

If you’re not comfortable using phpMyAdmin, a safer option is to use a plugin specifically designed to clean up leftover database tables.

One recommended plugin is Plugins Garbage Collector. This plugin scans your database and identifies unused tables left behind by uninstalled plugins.

Once the plugin is installed you will see the following options:

Garbage Collector Options

We’ll continue using Wordfence’s database tables as a reference for this example.

Garbage Collector Options Scan

Garbage Collector will scan your database and display a list of tables. In our example (using Wordfence tables for reference), you’ll see that all the tables Wordfence created are highlighted. This allows us to easily identify the unused tables.

I will now go ahead and check all the tables highlighted in red and hit Delete Tables.

Success! Leftover Tables Removed.

We’ve successfully removed the leftover tables that Wordfence left behind. While it seemed straightforward here, remember this was just one plugin.

In reality, with multiple uninstalled plugins, you’ll likely encounter many more tables. Identifying them can be tricky, especially if some plugins are still active. Thankfully, Garbage Collector helps by displaying the plugin name and its current state (active or inactive) alongside each table. This information can be crucial in differentiating between unused tables and those belonging to active plugins.

Cleaning Up Orphaned Options (Optional):

While Garbage Collector tackles leftover tables, some plugins might also store settings within your core WordPress tables (like “wp_options”). These orphaned options can remain even after plugin deletion.

Before diving into plugin deletion and table cleanup, it’s a good idea to optimise your database first. This removes any existing junk data that might be slowing down your website. You can achieve this by using the tools mentioned below.

Advanced Database Cleaner: A Targeted Tool

For this specific task, consider using a plugin called “Advanced Database Cleaner.” This tool helps optimise your database and clean up any orphaned options lingering in your “wp_options” table after plugin removal.

WP-Sweep:

A popular choice for database optimisation is WP-Sweep. This plugin tackles unused, orphaned, and duplicated data within WordPress, along with optimising your database tables for improved performance.

Remember: Always back up your database before making any changes!

If you need help optimising your database or website, contact us to see how we can help.

Article written by

Last updated