
WordPress databases accumulate maintenance debt over time. Post revisions, transients, spam comments, orphaned meta entries, expired sessions all add up. After 2-3 years of normal use, an unmaintained database can be 5-10x larger than its essential content, and the bloat slows down every query.
The maintenance operations that matter are specific. Some commonly-recommended operations provide marginal benefit; some less-discussed operations matter more. The honest list of what to do focuses on the high-impact items.
WordPress saves a revision every time a post is updated. By default, revisions accumulate indefinitely. A post that's been edited 50 times has 50 revisions in the wp_posts table, each one a copy of the post content at that point in time.
For content-heavy sites, post revisions can make up 60-80% of the wp_posts table. Cleaning them up reduces table size dramatically.
The cleanup: limit revisions going forward by setting in wp-config.php:
define('WP_POST_REVISIONS', 10);
Then delete old revisions beyond the new limit. WP-CLI can do this:
wp post delete $(wp post list --post_type='revision' --format=ids) --force
For sites with many revisions, this can take 10-30 minutes to run. Schedule during low-traffic hours.
WordPress transients are timed cache entries stored in the wp_options table. They expire on their own when accessed after expiration, but if they're never accessed again after expiration, they sit in the database forever as dead rows.
On sites that have been running for years, the wp_options table can have tens of thousands of expired transient entries. They don't cause direct problems but they bloat the table and slow queries that scan options.
The cleanup: use a plugin like WP-Optimize or Advanced Database Cleaner to identify and delete expired transients. Or use WP-CLI:
wp transient delete --expired
Spam comments and trashed comments stay in the database until manually deleted. For sites that have run for years without cleanup, the spam comment count can be in the hundreds of thousands.
The cleanup is one-time then ongoing. Initial cleanup: delete all spam and trash comments older than 30 days. Ongoing: set comment retention so older spam/trash is auto-cleaned.
WordPress doesn't have a built-in setting for auto-deletion of old spam comments. Plugins like Akismet or comment management plugins typically include this feature. Configure it once.
When a post is deleted, the post meta entries (stored in wp_postmeta) should be deleted too. WordPress usually handles this correctly, but plugins that don't properly hook into the deletion process can leave orphans behind.
Over years, orphaned post meta can be a significant fraction of the postmeta table. Plugins like WP-Optimize identify orphaned rows and offer cleanup.
Run orphan cleanup once a year or after major plugin uninstalls. The benefit is incremental but real.
MySQL's OPTIMIZE TABLE command reclaims space from deleted rows and rebuilds indexes. On older MySQL versions (5.5 and earlier), this could provide significant performance gains. On modern MySQL/MariaDB (5.7+ which most hosts use), the InnoDB engine handles space management automatically and OPTIMIZE TABLE rarely provides measurable benefit.
If you're running on legacy MySQL versions, optimize occasionally. On current versions, skip it unless you have a specific reason.
Cleaning up "auto-draft" posts. These are temporary entries WordPress creates when starting a new post but never publishing. They're typically deleted automatically after a few hours. Manual cleanup provides minimal benefit.
Reducing the number of slugs in the database. Some optimization guides suggest deleting old slugs from the wp_postmeta table. The benefit is marginal and the risk of breaking redirects is real.
Rewriting the wp_options table to remove autoloaded options. The autoload column on wp_options determines which options load on every WordPress page load. Reducing autoload size matters, but the manual rewriting is error-prone. Plugins like Advanced Database Cleaner identify autoload bloat safely.
Monthly: clean expired transients, delete spam/trash comments older than 30 days, limit new revisions going forward.
Quarterly: clean up old post revisions beyond limit, scan for orphaned post meta, check database size growth trend.
Annually: full database optimization scan, review which options are autoloaded and whether the list is appropriate, review which plugins are creating the most database overhead.
The schedule keeps databases healthy without becoming a maintenance burden. Most sites benefit from automation: set the cleanup plugins to run on schedules and review the results monthly.
Database cleanup operations are mostly safe but can fail in unexpected ways on edge-case data. Before any meaningful cleanup, take a fresh backup. The five minutes to verify backup currency could save the day when an "optimization" operation deletes something it shouldn't have.
The recovery path: restore from the pre-cleanup backup, identify what went wrong, fix the specific issue, try again. The recovery is straightforward only if the backup actually exists.
Site
Tools
We do not sell your email. We do not spam.
© 2026 RevealTheme. All rights reserved.