Database cleanup

Nine bounded cleanup types, dry runs, scheduling, activity hooks, and autoloaded-options remediation.

2 min readPart of Performance Optimisation

Database cleanup removes bounded categories of stale WordPress data and audits autoloaded options. It is designed to make the possible work visible before deletion.

Cleanup types

TypeTypical target
revisionsOld post revisions, with age/latest-count policy.
auto_draftsAbandoned editor auto-drafts.
trashed_postsTrashed posts past the selected retention.
spam_commentsSpam comments and their metadata.
trashed_commentsTrashed comments and their metadata.
expired_transientsExpired transients and timeout rows.
orphan_postmetaPost meta without a parent post.
unattached_mediaMedia not attached to content, subject to the current safety policy.
oembed_cacheExpired oEmbed response cache entries.

Preview, run, and schedule

wp wppo database counts
wp wppo database cleanup --type=all --dry-run
wp wppo database cleanup --type=expired_transients
wp wppo database cleanup --type=all --yes

Cleanup runs in bounded batches. The dashboard exposes the same canonical runner, counts, confirmation flow, and scheduling choices. A schedule of none, daily, weekly, or monthly is stored under the database-cleanup settings; a lock prevents overlapping runs.

Autoloaded-options audit

The audit lists the largest autoloaded options and can show a read-only parity comparison. Remediation supports a dry run, a bounded apply, a single-option revert, and revert-all. Review every candidate: an option that appears large may still be required on every request.

Activity and integrations

After aggregate or per-type work, the plugin writes an activity entry and fires wppo_database_cleanup_completed. Consumers should use safe result counts and avoid logging deleted content or credentials.

Verify

Run counts before and after, confirm the activity log, and purge page/derived caches when cleanup changes observable content or metadata. Test on staging with a database backup.