Editor’s Note: This article has been reviewed and updated for 2026 to reflect the latest trends and best practices.
As your WordPress site grows, its database quietly accumulates clutter — old post revisions, spam comments, expired transients, and orphaned plugin data. Over time, this bloat slows down every page load and drags down your Core Web Vitals scores. Optimising your WordPress database is one of the highest-impact, lowest-cost performance improvements available.
This guide covers every step from quick one-click wins to automated scheduled maintenance — so your database stays lean without you having to think about it.
WordPress stores nearly everything in its database: posts, settings, plugin data, user information, comments, and more. Every page load triggers multiple database queries. When your database is bloated with unnecessary data, those queries take longer — slowing your site and hurting your Google rankings.
A clean database reduces query time, improves server response, and directly improves your Time to First Byte (TTFB) — a key Core Web Vitals metric. Regular optimisation is essential maintenance, not optional.
Every time you save a WordPress post, it creates a revision. A single post with 50 edits stores 50 near-identical copies in the database. Across hundreds of posts, this adds up to thousands of redundant rows.
Limit future revisions by adding this line to wp-config.php:
define( 'WP_POST_REVISIONS', 5 );
Then delete all existing revisions using WP-CLI:
wp post delete $(wp post list --post_type='revision' --format=ids) --force
Or use the WP-Optimize plugin’s one-click revision cleanup if you prefer a GUI approach.
After deleting large amounts of data, tables become fragmented — they have gaps where data used to be. Running OPTIMIZE TABLE defragments them, reclaims wasted space, and speeds up queries.
Run this via phpMyAdmin or WP-CLI:
OPTIMIZE TABLE wp_posts, wp_comments, wp_options, wp_usermeta, wp_term_relationships, wp_term_taxonomy, wp_termmeta;
Note: Replace wp_ with your actual database prefix (found in wp-config.php as $table_prefix).
Transients are temporary cached values stored in the wp_options table by WordPress and plugins. They should expire automatically, but many linger long after they’re supposed to — especially from deactivated plugins.
Delete expired transients with this SQL query:
DELETE FROM wp_options
WHERE option_name LIKE '%_transient_%'
AND option_name NOT LIKE '%_site_transient_%';
Better yet, switch to an object cache (Redis or Memcached) on your server if your host supports it — this moves transients out of the database entirely.
Even with Akismet or similar spam filtering, caught spam comments still sit in your database. Same goes for comments moved to Trash. Clear them out with these SQL queries:
DELETE FROM wp_comments WHERE comment_approved = 'spam';
DELETE FROM wp_comments WHERE comment_approved = 'trash';
Follow up with an OPTIMIZE TABLE wp_comments; to reclaim the freed space.
The wp_options table is often the biggest source of database bloat. Every plugin that’s ever been installed may have left rows behind — even after you deleted the plugin.
Use the Advanced Database Cleaner plugin to safely identify and remove orphaned plugin options. Alternatively, run this query to see your largest option groups:
SELECT option_name, LENGTH(option_value) as size
FROM wp_options
ORDER BY size DESC
LIMIT 30;
Review the results carefully before deleting anything — some large values are legitimate (like serialised theme settings).
If you’re not comfortable with SQL or WP-CLI, these plugins handle cleanup safely with a clear interface:
Database optimisation isn’t a one-time job. Set up automation so it happens without you:
wp db optimize via crontab for zero-plugin overheadA weekly or monthly automated cleanup keeps your database lean without any manual effort on your part.
Yes — with one essential precaution: always take a full database backup first. Use your host’s backup tool or a plugin like UpdraftPlus before running any optimisation or deletion commands. Restoring from a backup takes minutes if anything goes wrong.
Monthly is sufficient for most business websites and blogs. Active WooCommerce stores benefit from weekly cleanups due to the higher volume of order data, cart sessions, and transients generated.
You’ll see improvement in admin panel response times immediately. Front-end speed gains are most noticeable on sites without page caching — always run a caching plugin alongside database optimisation for maximum effect.
Yes — just replace wp_ with your actual prefix throughout. Check your wp-config.php file for the $table_prefix variable to confirm yours. It’s commonly something like wp7x_ or wp_abc123_.
Some plugins don’t clean up their own database tables on deletion. You can safely delete tables that clearly belong to a removed plugin — but identify them carefully first. Use the Advanced Database Cleaner plugin to help you identify and safely remove orphaned tables.
Need help speeding up your WordPress website? Contact Creative Sparks for a free WordPress performance audit. We help businesses across India get faster, more reliable websites that rank better and convert more visitors.