Short answer: A WordPress database accumulates post revisions, expired transients, spam and trashed comments, leftover tables and options from removed plugins, and oversized autoloaded options. Cleaning these up can speed up the admin area and uncached pages. The safest approach is to take a full backup, check the size of autoloaded options first, delete expired transients, trash and spam, limit post revisions, remove data left by plugins you have uninstalled, and only then optimise tables. Never delete data you do not understand.
Every WordPress site stores its content, settings and much of its plugin data in a MySQL or MariaDB database. On a new site the database is small and fast. After a few years of publishing, editing, installing and removing plugins, running a shop or collecting form submissions, it can grow many times larger than the content it actually serves. Most of that growth does not hurt; databases handle large tables well. But certain kinds of clutter are read on every request and do slow things down. Knowing which is which keeps you from risky cleanups that achieve nothing.
When database size actually affects speed
A big database is not automatically a slow one. What matters is what is read on each request and whether queries can use indexes. Problems usually show up as:
- a slow admin area, especially the post list, the dashboard and WooCommerce orders;
- slow uncached pages and a slow Time to First Byte for logged-in users, carts and checkouts;
- high memory usage per request;
- slow backups and migrations.
If your cached pages are fast and the admin feels normal, database cleanup is housekeeping, not a speed project. If uncached requests are slow, the database is a good place to look.
Step 1: Back up before anything else
Take a complete database backup, and confirm you can restore it, before running any cleanup. Download a copy off the server. Many hosts offer one-click backups and staging; use a staging copy for larger cleanups. Database changes cannot be undone with the WordPress trash, and one wrong query can remove orders, users or settings.
Step 2: Check autoloaded options
The wp_options table holds site settings and plugin data. Options marked for autoloading are loaded into memory on every single request, whether the page needs them or not. Plugins sometimes store large amounts of data there: logs, caches, statistics, license checks. Plugins you removed years ago may have left their options behind.
- Recent WordPress versions include a Site Health check that warns when autoloaded options are unusually large.
- Tools such as Query Monitor or database plugins can list the largest autoloaded options and often show which plugin created them.
- For options belonging to plugins that are no longer installed, deleting them or switching off autoload is usually safe after a backup.
- For options belonging to active plugins, check the plugin’s settings or documentation first; some can reduce what they store.
Autoloaded data is the single database issue most likely to affect every request, so it deserves attention before anything else.
Step 3: Remove expired transients
Transients are temporary cached values with an expiry time, stored in the options table unless you use an object cache. WordPress deletes expired transients during regular maintenance, but on some sites they pile up, particularly when scheduled tasks do not run reliably. Deleting expired transients is safe; plugins recreate them when needed. If you use a persistent object cache such as Redis, transients live there instead of the database.
Step 4: Limit and clean post revisions
WordPress saves a revision every time you save a post, which is valuable for undoing mistakes but adds up on sites with long, frequently edited pages or page builders that store large content.
- Set a limit in
wp-config.php, for exampledefine( 'WP_POST_REVISIONS', 10 );, so each post keeps only the most recent revisions. - Delete old revisions beyond that limit with a trusted cleanup tool.
- Revisions are stored in the posts table and rarely slow front-end queries on their own, but they bloat the table, backups and the editor.
Step 5: Empty trash, spam and orphaned data
- Delete spam and trashed comments, and trashed posts you do not need.
- Remove orphaned post meta and comment meta whose parent no longer exists.
- Check form plugin entries; some sites keep years of submissions they no longer need. Export anything you must keep for legal or business reasons first.
- Review log tables from security, redirect, e-mail and analytics plugins. These can grow very large; most plugins offer a retention setting.
Step 6: Remove leftover tables from old plugins
Many plugins create their own tables and leave them behind after uninstalling. Leftover tables do not slow down queries to other tables, but they increase backup size and clutter. Identify them by their prefix and name, confirm the plugin is truly gone and not just deactivated, and remove them only after a backup. If you are unsure what a table belongs to, leave it.
Step 7: Optimise tables and check the engine
- Make sure tables use the InnoDB storage engine; very old sites may still have MyISAM tables, which handle concurrent writes poorly.
- Running “optimize” on tables after large deletions reclaims space. The speed benefit is usually modest, so treat it as the final step, not the main one.
- Ask your host whether the database server has enough memory allocated; a well-sized buffer pool matters more than table optimisation.
What is safe to clean and what is not
| Item | Usually safe? | Notes |
|---|---|---|
| Expired transients | Yes | Recreated automatically when needed |
| Spam and trashed comments | Yes | Check nothing important was misfiled as spam |
| Old post revisions | Yes, beyond a limit | Keep recent ones for recovery |
| Options from removed plugins | Usually | Confirm the plugin is gone; back up first |
| Leftover plugin tables | Usually | Only when you know which plugin owned them |
| Orders, customers, users | No | Business and legal records; never bulk-delete |
| Unknown options or tables | No | Leave them until you know what they are |
A realistic cleanup session
For a typical company site that has been running for five years or more, a cleanup session might go like this. After a backup, Site Health reports a large amount of autoloaded data. The listing shows that most of it belongs to a statistics plugin removed two years ago and a slider plugin that is still active but stores its whole configuration in one autoloaded option. The first is deleted; for the second, the plugin’s settings allow switching off an unused feature that shrinks the stored data. Next, several thousand expired transients and a few thousand spam comments are removed. A revision limit is set, and old revisions beyond it are cleaned. Finally, a security plugin’s log table that had grown to millions of rows gets a retention period of thirty days. The whole session takes an hour, the admin post list opens noticeably faster, and uncached pages generate more quickly. None of the steps touched content, users or orders.
Keep it tidy automatically
- Set a revision limit in
wp-config.php. - Configure log retention in security, e-mail and form plugins.
- Make sure WP-Cron runs reliably, ideally triggered by a real server cron job, so scheduled cleanup happens.
- Use a persistent object cache on busy sites so transients do not live in the database.
- Uninstall plugins properly, using their own data-removal option where available, instead of just deleting files.
- Review database size and autoloaded data once or twice a year.
How Site AI Audit helps
Site AI Audit measures your site from the outside, including how quickly the server responds, and runs Google PageSpeed for mobile. A slow response on pages that should be fast is a sign to look at the server side, including the database. The report explains findings in plain words and ranks them by impact, so you know whether database work should come before images or scripts. Run a free check first.
Related reading
- How to Find Which WordPress Plugin Is Slowing Your Site
- How to Reduce Server Response Time (TTFB) for Faster Pages
- How to Speed Up a Slow WooCommerce Store Without Breaking It
- How to Fix a Slow WordPress Site: A Step-by-Step Guide
The bottom line
Database cleanup helps when uncached requests or the admin area are slow, and the biggest win is usually oversized autoloaded options rather than raw table size. Back up first, clean autoloaded data, expired transients, excess revisions, spam and leftovers from removed plugins, and set up retention limits so the clutter does not return. Leave anything you do not understand.
DUK
Does cleaning the WordPress database make the site faster?
It can speed up the admin area and uncached pages, mainly by reducing autoloaded options and clutter read on each request. Cached front-end pages usually see little difference. Measure before and after to confirm the effect on your site.
Is it safe to use a database cleanup plugin?
Reputable cleanup plugins are generally safe for standard items like expired transients, spam and revisions. Always take a full backup first and avoid options that delete data you do not understand. Test on staging for larger cleanups.
What are autoloaded options in WordPress?
They are entries in the options table that WordPress loads into memory on every request. Small amounts are normal, but plugins can store large data there, which slows every page. Site Health and profiling tools help identify the largest ones.
How many post revisions should WordPress keep?
There is no single right number, but a limit such as five to ten per post keeps useful history without unlimited growth. Set it with the WP_POST_REVISIONS constant in wp-config.php.
Should I delete tables left by old plugins?
Only if you are certain which plugin created them and that it is no longer used. Leftover tables mostly affect backup size, not speed. When in doubt, keep them.



