Every WordPress site relies on a database that stores posts, pages, comments, users, settings and plugin data. Over time, this database accumulates clutter: hundreds of post revisions, spam comments, expired temporary data and leftover tables from deleted plugins. A bloated database can slow queries, make backups larger and contribute to slower admin performance.
This guide explains what fills up your WordPress database and how to clean and optimise it safely.
What Is Stored in the WordPress Database?
| Table (default prefix wp_) | Contents |
|---|---|
| — | — |
| wp_posts | Posts, pages, revisions, menu items, attachments |
| wp_comments | Comments, including spam |
| wp_options | Site settings, plugin settings, transients |
Plugins may add their own tables as well.
Common Sources of Database Bloat
- Post revisions: WordPress saves a revision every time you update content
- Auto-drafts: automatic drafts created while editing
- Spam and trashed comments: can number in thousands
- Expired transients: temporary cached data that sometimes remains
- Orphaned metadata: data linked to deleted posts or users
- Leftover plugin tables: data from uninstalled plugins
- Autoloaded options: settings loaded on every page, sometimes excessively
Step 1: Back Up Your Database
Always take a backup before cleaning. Mistakes in database cleanup can remove important data.
Step 2: Clean Spam and Trashed Comments
Go to Comments, review the Spam and Trash sections and empty them. Large volumes of spam can significantly increase database size.
Step 3: Manage Post Revisions
Revisions are useful for restoring earlier versions, but hundreds per post are rarely needed. You can:
- Limit the number of revisions stored per post through a setting in wp-config.php
- Delete old revisions with a trusted optimisation plugin
Step 4: Remove Expired Transients
Transients are temporary data stored by plugins and themes. Expired transients can usually be deleted safely with optimisation tools.
Step 5: Remove Leftover Plugin Data
When you delete a plugin, some leave tables or options behind. Review plugin documentation for clean uninstall options, or use database tools carefully to remove data from plugins you no longer use.
Step 6: Check Autoloaded Options
Large autoloaded options can slow every page load. Some performance tools show autoload size. Investigate unusually large entries, often created by plugins.
Step 7: Optimise Tables
Database optimisation reorganises table storage and can reclaim space after deletions. Many optimisation plugins include this feature, and phpMyAdmin offers an “Optimize table” option.
Database Optimisation Tools
| — | — |
|---|---|
| Optimisation plugins | Clean revisions, spam, transients and optimise tables |
| phpMyAdmin | Direct database management (advanced) |
How Often Should You Clean?
| — | — |
|---|---|
| Ecommerce or membership site | Monthly, carefully, with backups |
Schedule automatic cleanups for routine tasks such as spam and transients, but review major deletions manually.
What Not to Delete
- Active plugin tables
- User data and orders
- Published content and media references
- Options you do not understand
When unsure, ask a developer or your host.
Real-World Example
A long-running blog with years of content had a database several times larger than expected. A review found tens of thousands of revisions, more than 50,000 spam comments and tables from plugins removed years earlier. After a backup, the owner cleaned revisions, emptied spam, removed old plugin tables and optimised the database. The admin dashboard became faster and backups completed much more quickly.
Frequently Asked Questions
Does database optimisation improve front-end speed?
It can help, especially for admin performance and large sites, but caching and hosting usually have a bigger front-end impact.
Is it safe to delete revisions?
Generally yes, after a backup, though you lose the ability to restore those older versions.
What are transients?
Temporary cached data stored by WordPress, plugins and themes.
Can I break my site by cleaning the database?
Yes, if you delete important data. Always back up and use trusted tools.
Should I limit post revisions?
Many sites benefit from limiting revisions to a reasonable number.
How do I know if my database is bloated?
Check database size in your hosting panel or optimisation tool and look for large tables.
Conclusion
A clean WordPress database supports faster administration, smaller backups and smoother performance. Back up first, remove spam and unnecessary revisions, clear expired transients, delete leftover plugin data and optimise tables regularly. A little routine maintenance keeps your website efficient as it grows.
