How to clean and optimize a WordPress database
Back up your site first, then remove revisions, spam, expired transients and abandoned plugin data. Check autoloaded options carefully before optimising tables. For recurring cleanup, a database maintenance plugin is faster and safer than repeating manual SQL.
- 01Back up before deleting anything
- 02Measure the actual problem
- 03Clean revisions and unwanted content
- 04Remove expired transients carefully
- 05Audit autoloaded options
- 06Optimise tables and schedule maintenance
What you need
- A complete WordPress files and database backup
- Administrator or hosting control-panel access
- WP-CLI or phpMyAdmin access for deeper cleanup
- A staging site for a busy WooCommerce or membership site
Back up before deleting anything
Create and download a current database backup, and make sure you know how to restore it. A database cleanup is permanent; if a plugin stores important settings in an option or custom table, there may be no undo button.
Run the cleanup during a quiet period and pause scheduled imports, orders or bulk content edits. On a live WooCommerce site, do not take a backup snapshot and then leave it unverified: check that the backup completed and contains the database before continuing.
Measure the actual problem
Check Tools > Site Health > Info and your host’s database-size report. Look for a large wp_options table, a high volume of revisions, spam comments, expired transients, or tables belonging to plugins you no longer use.
Do not assume that the biggest database is the slowest one. Autoloaded options are loaded together on regular requests, so one oversized plugin setting can matter more than thousands of legitimate orders. WordPress flags excessive autoloaded data in Site Health, but the option owner still needs to be identified before changing it.
Clean revisions and unwanted content
Remove old post revisions, auto-drafts, items in the trash, spam comments and trashed comments from the WordPress admin or a trusted maintenance tool. Keep a sensible revision limit rather than disabling revisions completely; WordPress stores revisions in the posts table and supports a limit through WP_POST_REVISIONS in wp-config.php.
If you have shell access, WP-CLI can list revision posts and delete selected revisions with wp post list and wp post delete --force. Check the IDs first, especially on a site using page builders, custom fields or revision-dependent workflows.
Remove expired transients carefully
Delete expired transients rather than blindly deleting every transient. Transients are temporary cached values, and WordPress can store them in wp_options or, with an external object cache, outside the database. WP-CLI provides wp transient delete --expired; the WordPress API also has a function for deleting expired transients.
Do not panic if transients return after cleanup. Plugins may recreate them, and some stores or integrations depend on them. Deleting all transients can also cause a temporary increase in database queries while caches are rebuilt, so use the expired-only option unless you have a specific reason to clear everything.
Audit autoloaded options
Inspect the largest rows in the options table and identify which active plugin or theme created each one. Change autoload behaviour only for a non-essential option that you have confirmed does not need to load on every request. Never delete or disable core settings simply because their names are unfamiliar.
Do not run a generic SQL deletion against rows matching a plugin name. Plugins can use serialized data, shared settings or custom tables, and deleting one row can break the admin, permalinks, checkout or scheduled tasks. If you cannot identify an option’s owner, leave it alone and ask the plugin developer or host for advice.
Optimise tables and schedule maintenance
After deleting data, run a database check and table optimisation from your hosting panel or with wp db optimize. WP-CLI runs the host’s MySQL optimisation utility, but table optimisation can use substantial disk space and may lock writes, so avoid doing it during checkout traffic or a busy publishing window.
For the fast way, use Meow Database Cleaner Pro to schedule cleanup, review database reports and create backups before maintenance. It is a practical option for large sites that need recurring removal of revisions, spam and transients instead of repeating the manual process.
Let Meow Database Cleaner Pro do it
Scheduled database cleanup with reports and backups; ideal for removing revisions, spam, and transients on large sites.
Sources
- wordpress.org /support/topic/autoloaded-options-trigger-critical-site-heal…
- wordpress.org /documentation/article/revisions/?utm_source=openai
- developer.wordpress.org /cli/commands/transient/?utm_source=openai
- developer.wordpress.org /cli/commands/db/optimize/?utm_source=openai
Questions
- Will cleaning the WordPress database make my site faster?
- It can improve performance when revisions, expired transients or oversized autoloaded options are causing unnecessary database work. It will not fix slow hosting, unoptimised images, heavy JavaScript or poorly written plugin queries. Measure before and after, and focus on the data loaded on every request rather than deleting legitimate orders, posts or customer records.
- Is it safe to delete all WordPress revisions?
- Deleting revisions is usually safe once you have a verified backup, but it removes your ability to restore earlier content from WordPress. Keep a limited number for important posts and pages, particularly when several people edit content or page builders store large amounts of metadata in revisions. Set a revision limit so the database does not grow indefinitely.
- Can I delete all transients in WordPress?
- You can delete transients, but clearing only expired transients is the safer default. Active transients are temporary cache entries that plugins may use for API responses, calculations or store data. They can be rebuilt, but deleting them all may temporarily increase queries or API requests. Use the WordPress API, WP-CLI or a maintenance tool rather than raw SQL.
- Why did the database file not get smaller after cleanup?
- Deleting rows does not always reduce the physical database file size immediately. The freed space may be reused by MySQL, while reclaiming disk space may require table optimisation or a rebuild. Take a backup first and check whether your storage problem is actually caused by autoloaded options, plugin logs, WooCommerce data or legitimate orders before rebuilding large tables.