Key takeaways
- A WordPress database gathers revisions, spam, expired temporary data and leftovers from removed plugins over time.
- Always take a full, tested backup and ideally work on a staging copy before deleting anything from the database.
- Regular light housekeeping and sensible settings are safer than occasional aggressive clean-ups.
Every WordPress website runs on two things: the files that make up WordPress, your theme and your plugins, and a database that stores almost everything else. Your pages, posts, settings, users, comments, menus and, for WooCommerce stores, orders and customers all live in the database.
As a site ages, that database collects material it no longer needs. Old drafts, deleted comments, temporary data that was never cleared and tables left behind by plugins you removed years ago can all pile up. This guide explains what builds up, what is generally safe to remove, how to protect yourself before you start and how to keep things tidy afterwards.
What is the WordPress database?
WordPress uses a relational database, usually MySQL or MariaDB, provided by your hosting company. It is organised into tables. The core tables hold posts and pages, post metadata, comments, users, user metadata, terms such as categories and tags, and site options. Plugins often add their own tables for things like form submissions, logs or ecommerce data.
When a visitor loads a page, WordPress queries these tables to assemble the content. A cluttered database does not always cause problems, but unnecessary data can make backups larger, slow down some admin screens and occasionally affect performance on busier sites.
What builds up over time
Post revisions
Each time you save or update a post or page, WordPress can store a copy as a revision so you can roll back. This is genuinely useful, but on a site with long-lived pages edited many times, revisions can account for a large share of the posts table.
Auto-drafts and trashed content
WordPress creates auto-drafts as you work and keeps trashed posts and pages until the trash is emptied. Left alone, these accumulate quietly.
Spam and trashed comments
If your site accepts comments, spam and trashed comments remain in the database until they are permanently removed, along with their associated metadata.
Transients
Transients are temporary pieces of data that themes and plugins store to avoid repeating slow tasks. They usually have an expiry time, but expired transients are not always cleared promptly, and some are created without an expiry at all.
Orphaned metadata
Metadata is extra information attached to posts, users, comments and terms. When the parent item is deleted, its metadata can sometimes be left behind with nothing to belong to.
Leftovers from removed plugins and themes
Deactivating and deleting a plugin does not always remove the tables and options it created. Over years of trying and replacing plugins, a database can carry a surprising amount of this residue. A regular WordPress plugin audit helps you understand what was installed and why.
Autoloaded options
The options table stores site-wide settings. Some options are marked to load on every single page request. If plugins have stored large amounts of data as autoloaded options, every page has to carry that weight, whether it needs it or not.
Before you clean: protect the site
Database work is one of the few website tasks where a mistake can be hard to undo. Deleting the wrong table or option can break features, lose content or take the site offline. Before changing anything:
- Take a full backup of both the database and the files, and store it somewhere other than your hosting account.
- Check the backup can be restored. A backup you have never tested is a hope rather than a safety net.
- Work on a staging copy first where possible, so you can confirm nothing breaks before touching the live site. Our guide to website staging and testing explains the approach.
- Choose a quiet time for any changes to the live site, particularly on an online store taking orders.
- Write down what you change, so you can retrace your steps if something behaves oddly later.
What is usually safe to remove
With a backup in place, the following are generally considered low risk to clear, although you should still check each site individually:
- spam comments and comments already in the trash,
- posts and pages already in the trash that you are sure you do not need,
- old auto-drafts,
- expired transients, and
- older post revisions, keeping a few recent ones for important pages.
WordPress itself lets you empty the trash and remove spam from the admin area. Many hosting control panels include a database tool, and there are maintenance tools that can clear revisions and transients. Whichever route you take, use reputable tools, keep them updated and remove any you no longer need.
What needs more care
Some clean-up tasks look straightforward but carry more risk:
- Tables from old plugins. Confirm a table really belongs to a plugin you have removed, and that no other plugin or custom code relies on it. Table names are not always obvious.
- Orphaned metadata. Usually safe to remove, but custom code occasionally stores data in ways that look orphaned and are not.
- Autoloaded options. Switching off autoloading or deleting large options can improve performance, but removing something a plugin still expects can cause errors.
- WooCommerce data. Orders, customers and related records may be needed for accounting, tax and customer service. Do not remove order data without checking what your business needs to keep. Retention requirements can vary, so it is sensible to check with your accountant or adviser.
If you are not confident identifying what a table or option does, this is a good point to involve a developer.
Optimising tables
After deleting data, database tables may still occupy the space the data used. Optimising tables can reclaim that space and reorganise the data. Many hosting control panels offer an optimise option, and some maintenance tools include it. On large tables this can take time and briefly lock the table, so run it during a quiet period.
Preventing clutter in the first place
Limit revisions
WordPress allows you to limit how many revisions are kept per post through a setting in the site configuration file. Keeping a handful gives you a safety net without unlimited growth. Changing configuration files should be done carefully, ideally by someone comfortable with WordPress.
Control comment spam
If you do not need comments, consider switching them off. If you do, use spam filtering and moderation so spam does not build up in large volumes.
Be selective about plugins
Every plugin you add may write to the database. Install only what you need, and when removing a plugin, check whether it offers an option to delete its data on uninstall.
Watch logs and form entries
Security, form and email plugins sometimes store logs or submissions indefinitely. Check their settings for retention options. Keeping personal data no longer than necessary is also a principle of UK data protection law, so the Information Commissioner's Office guidance is worth reading if you store enquiries or customer details.
Does a database clean-up make a site faster?
Sometimes, but it is rarely the main fix. Hosting quality, caching, image sizes, theme code and the number of plugins usually have a bigger effect on speed. A tidy database is part of good housekeeping and can help with admin performance and backup sizes, but it should sit within a broader approach to website speed optimisation. Good WordPress hosting also makes a difference to how well the database performs.
Building it into maintenance
Database housekeeping works best as a routine task rather than a one-off rescue. A light, regular tidy, alongside updates, backups and security checks, keeps the database manageable and reduces the temptation to make sweeping changes all at once. Our guide to website maintenance covers how this fits with other routine work, and WordPress security explains related protective steps.
Common mistakes to avoid
- Cleaning without a recent, tested backup.
- Deleting tables because the name looks unfamiliar.
- Removing all revisions, including ones you may want for important pages.
- Deleting WooCommerce order data without checking your record-keeping needs.
- Running heavy optimisation on a busy store during trading hours.
- Leaving clean-up tools installed and unused.
How Prism Works Studio can help
Prism Works Studio builds and looks after WordPress and WooCommerce websites for UK businesses, including database housekeeping as part of careful, backed-up maintenance. Explore our website and ecommerce development service, view our pricing or get in touch to talk about your site.
FAQs
Is it safe to clean a WordPress database?
It can be, provided you take a full tested backup first and stick to well-understood tasks such as removing spam, trash and expired transients. Deleting tables or options needs more care.
Should I delete all post revisions?
Not necessarily. Revisions let you roll back changes. Many site owners keep a few recent revisions per page and remove older ones.
Do deleted plugins leave data behind?
They can. Some plugins remove their data on uninstall, while others leave tables and options in place unless you remove them separately.
Will cleaning my database improve SEO?
Not directly. It may help performance in some cases, which supports a good visitor experience, but content, structure and technical health matter far more for search.
Can I clean a WooCommerce store database?
Yes, with extra caution. Order and customer data may be needed for accounts and customer service, so check what you need to keep before removing anything.