How to Clean Up Your WordPress Database

This article will show you how to clean up your WordPress database, which speeds up a site that has been running for a while and shrinks your backups.
1. Understand What Accumulates
Every edit stores a revision, every plugin leaves settings behind when removed, and expired temporary data lingers. Sites running for years often carry more unused data than live content.
2. Back Up First
A database clean-up deletes data permanently. Take a backup before touching anything, and confirm you can download it.
3. Limit Post Revisions
WordPress keeps every draft of every post indefinitely. Adding a line to wp-config.php caps them at a sensible number:
define('WP_POST_REVISIONS', 5);
4. Delete Old Revisions
An optimisation plugin removes existing revisions in bulk. On a long-running site this alone can halve the database.
5. Clear Expired Transients
Transients are temporary cached values that are supposed to expire and often do not. Clearing them is safe and frees space immediately.
6. Empty Trash and Spam
Deleted posts and spam comments stay in the database until purged. Emptying both is the quickest win available.
7. Optimise the Tables
Optimising reclaims the space freed by all of the above. Without this step the database file stays the same size.
8. Do It Regularly
Once a quarter keeps things tidy. Most optimisation plugins can schedule it.
Next: Why You Should Take Regular Backups covers protecting yourself before you start.