TOOLGEIST ↗
213 EDITIONS

ACQUISITION & LICENSING DESK

Direct Foundry Enquiry

Specify your target edition or studio requirements. We respond within one business day with direct source archive delivery and licensing credentials.

Performance November 15, 2026 258 words · 2 min read

WordPress Database Optimization: Cleaning Transients, Revisions & Oversized wp_options

WordPress Database Optimization: Cleaning Transients, Revisions & Oversized wp_options
Safe SQL and WP-CLI maintenance routines to keep MariaDB and MySQL fast on long-running WordPress sites without breaking active plugins.

1. What Actually Slows Down a WordPress Database Over Time

After a year of active publishing and plugin experiments, WordPress databases accumulate thousands of expired transients in wp_options, unlimited post revisions in wp_posts, and orphaned metadata rows in wp_postmeta whose parent posts were permanently deleted long ago.

Before running any cleanup query, always take a snapshot dump. Then target the safe, high-impact wins: cap future revisions in wp-config.php with define( "WP_POST_REVISIONS", 5 );, purge expired transients, and convert bloated non-critical options out of autoload.

Clean open hangar space
Fig 01. Keeping database tables lean ensures cold-cache WordPress queries stay sub-50ms.
define( 'WP_POST_REVISIONS', 5 );

-- Safely inspect orphaned postmeta rows before cleanup
SELECT COUNT(*) FROM wp_postmeta pm
LEFT JOIN wp_posts p ON p.ID = pm.post_id
WHERE p.ID IS NULL;

2. Automating Safe Maintenance Without Risking Live Data

Rather than running risky third-party “one-click database cleaner” plugins that blindly truncate tables, rely on targeted WP-CLI commands during off-peak maintenance windows. Commands like wp transient delete --expired only remove already-expired entries, leaving active plugin caches untouched.

Also check database engine consistency: legacy WordPress installs migrated years ago sometimes still carry MyISAM tables alongside InnoDB. Converting all tables to InnoDB enables row-level locking instead of full-table locks, preventing admin edits from stalling concurrent front-end reads.

FAQ — How often should I run OPTIMIZE TABLE? Rarely—on modern InnoDB tables with proper indexing, quarterly or post-bulk-deletion maintenance is plenty.

wp db export pre-cleanup-backup.sql
wp transient delete --expired
wp post delete $(wp post list --post_type='revision' --format=ids) --force