New 24/7 monitoring and daily cloud backups now included in every Shield Pro plan.

Database

How to clean a WordPress database

WordPress databases grow with revisions, spam, expired transients, and abandoned plugin options. Cleaning frees space and can speed queries when done with backups and the right tools.

Time: 30-50 minutes Level: Intermediate

What this problem looks like

Database cleanup is not the same as deleting plugins. Orphan tables from removed plugins and autoloaded options often cause more bloat than post revisions.

Aggressive SQL without understanding breaks WooCommerce orders and page builder data. Prefer targeted tools with dry-run previews.

Never drop tables or bulk-delete postmeta on production without a fresh backup and a staging test.

Safe cleanup with WP-CLI

bash
wp comment delete $(wp comment list --status=spam --format=ids)
wp post delete $(wp post list --post_status=trash --format=ids) --force
wp transient delete --expired
wp cache flush

Limit post revisions going forward

Add to wp-config.php to cap future revision growth. Delete old revisions only after backup.

php
define( 'WP_POST_REVISIONS', 5 );
define( 'AUTOSAVE_INTERVAL', 120 );

Plugin-assisted cleanup

WP-Optimize and Advanced Database Cleaner show removable items with checkboxes. Review each category instead of select all blindly.

Do not use optimize plugins to drop active plugin tables. Read each line before confirming.

Find autoload bloat

Large autoloaded options slow every page. Remove only options tied to plugins you uninstalled.

bash
wp db query "SELECT option_name, LENGTH(option_value) AS size FROM wp_options WHERE autoload='yes' ORDER BY size DESC LIMIT 20;"

After cleanup

  • Test checkout, forms, and search.
  • Regenerate critical CSS if a performance plugin requests it.
  • Schedule quarterly cleanup instead of yearly panic deletes.

When to stop DIY and hire help

Shops with years of order data need surgical cleanup, not generic plugins. BugShield optimizes WordPress databases on maintenance plans with tested restore points.

FAQs

Will deleting revisions affect published posts?

No. Revisions are history copies. Keep at least one backup before mass revision deletes.

Are transients safe to delete?

Expired transients are safe. WordPress recreates active transients on demand.

Can cleanup fix a hacked database?

Cleanup removes junk, not malware users. Hacked sites need security remediation and often a clean restore.

How big is too big for wp_options?

Autoload totals over a few megabytes warrant investigation. Individual rows over 1MB are suspicious.

Rather someone else fixed it?

Request a fix at a confirmed price. Named UK developer, secure Vault, direct chat.

Request a Fix