Cleaning up a WordPress Database

A WordPress database will over time become more and more bloated, as it becomes filled with various information / entries.

From posts, comments, users, themes, plugins and more. Too often using a plugin and deleting it will not delete the entries it made into the database. These entries can become really big.

Here is an example from a site that used the W3Counter plugin. A stats plugin not updated for a few years. Using the plugin and then removing it a while later left some very huge entries in the database. The below example shows a scan made with the Duplicator clone and backup plugin to create a backup. The database statistics entries which are seen shows 284.91MB and 365.02MB entries. These and other statistics entries need to be removed from the database.

Duplicator plugin WordPress Scan screen showing large entries in Database
Duplicator plugin WordPress Scan screen showing large entries in the Database.

Manually deleting Database entries

To manually delete database entries one can login to the web host and go to the control panel. Locate phpMyAdmin. Click the database name and click to Export the full database.

Click the + symbol to see all the database entries and click the entries one wants to remove. Then click Delete to remove the entry.

Clean up database plugins

There are multiple plugins one can use to cleanup the database, cache etc. Such as
WP Optimize – Cache, Clean and Compress.
WP Bulk Delete – Has a more detailed approach to deleting anything.

WP Optimize and WP Bulk Delete was not able to locate the very huge entry files.
I decided to try out Advanced Database Cleaner. A plugin I have used multiple times before.

Advanced Database Cleaner

WP DB Cleaner adds a link in the left WordPress sidebar menu. The free version lets one do a general cleanup of the database to remove old revisions, spam comments, optimize database and more.

Click the Tables tab. Then click the Size column title to get the largest entries at the top.

Advanced Database Cleaner WordPress plugin Tables tab ordering by size
Advanced Database Cleaner WordPress plugin. Tables tab ordering by size.

I am able to locate the entries but I am not able to remove these in the free version of the plugin. I can decide to go back into the web host control panel and through phpMyAdmin find these entries and remove them or purchase the Pro plugin. There might be a third alternative as well, and that is to find another plugin which can cleanup the large entries. I decided to get a hold of the 2 sites Pro version.

Advanced Database Cleaner Pro plugin

The Pro plugin has a one time payment and does not require a yearly subscription.

License for 2 sites without technical support costs 39$.
License for 5 sites which also include technical support costs 59$.
Unlimited costs 149$.
Advanced Database Cleaner Pro plugin options.
Documentation.

Upon uploading and activating the Pro plugin the free version is automatically deactivated.
Going back to the Tables screen and clicking Size to get the largest entries at the top I noticed that it said Uncategorized! I needed to click the Scan tables button so the plugin would go through all the tables in the database. Instead of it now saying Uncategorized! It now said WordPress core and a percentage number beside it. The percentage gives a signal in relation to where it believes the specific entry belongs. In the statistics case it should show a plugin instead of the mention of wordpress core.

How to backup the database?

https://wordpress.org/support/article/backing-up-your-database/
There are also various plugins to backup and restore the database. I did a search and came across the WP Database Backup plugin which has really good ratings. I would also do a backup with the Duplicator plugin as it backs up the full site and Duplicator (Pro) version also contains a recovery option.

Backup the database and keep it just in case. Going back to the database entries I feel more confident in deleting entries that are old and forgotten. I can now go through the list of entries and delete the ones I am mostly sure about. If something goes wrong I can restore the database or use Duplicator to restore the site. I clicked Size and made sure the biggest where seen in the top. I selected the two statistics and the following two orphan files and in the drop down selected Delete, and clicked the Bruk (Go/Use) button. I removed 865,2MB from the database.

Advanced Database Cleaner deleting entries
Advanced Database Cleaner deleting entries
Share the article:

Leave a Reply

Your email address will not be published. Required fields are marked *

3 × two =