Cleaning up a WordPress database after years of plugins
Orphaned tables, bloated autoloaded options, accumulated revisions: what an ageing database actually contains and how to clean it up without breaking a plugin still in use.
What a database really holds after years of use
A WordPress site several years old, having gone through many plugins installed then removed, accumulates elements in its database that no one ever cleaned up. Well-built plugins delete their own tables on uninstall; many don’t, leaving orphaned tables that keep existing with no active code reading them any more. The wp_posts table also accumulates content revisions: every autosave or manual save of a post creates a new row, never purged by default. Transients, a temporary caching mechanism stored in wp_options, logically expire but often stay in the database long after expiry if nothing purges them.
Orphaned metadata follows the same pattern: when a post, product or customer is deleted, the matching rows in wp_postmeta or wp_usermeta aren’t always removed at the same time, particularly if the deletion went through a direct database query rather than the WordPress interface. These orphaned rows never show up anywhere, but they still bloat the database for no reason.
The most costly point for performance is often the least visible: options flagged autoload in wp_options. These are settings WordPress loads fully into memory on every page load, regardless of whether that page actually needs them. On an old site, this table can reach several megabytes of autoloaded options, loaded on every request even on a plain product page that needs none of them.
How I clean up an ageing WordPress database
-
Full database backup
Before any deletion, a backup of the entire database, restorable independently of the site’s files.
-
Identifying orphaned tables
I compare the full list of database tables against the prefixes of plugins actually active on the site. A table whose prefix matches no installed plugin, active or not, is a candidate for removal.
-
Purging revisions and expired transients
I remove content revisions beyond a reasonable number kept per post, and transients whose expiry date has passed.
-
Measuring autoloaded options before and after
I record the total size of options flagged autoload before the intervention, then check its reduction afterwards. It’s the most direct indicator of the cleanup’s real effect on performance.
-
Functional check
I check that every active plugin still works normally after the purge, particularly those using transients for their own caching.
Related pages
-
Slow WordPress site
The most common causes of slowness on a WordPress site or WooCommerce shop, database included.
-
Backing up a shop before an intervention
What a backup needs to cover before a database operation to stay reversible.
-
Clearing the WordPress cache
The difference between page cache, object cache and transients, and how to clear them without breaking anything.
-
Glossary: migration
The technical vocabulary used across these pages, explained simply.
Describe your need in one minute
A few targeted questions so I can reply with an estimate rather than another questionnaire.