Every visit to your WordPress site triggers dozens of database queries. A lean, well-tended database responds in milliseconds. A bloated one — with thousands of old revisions, expired transients, orphaned metadata and spam leftovers — drags every page load down. After a year of normal WordPress use the bloat can easily double the database size and push query times into hundreds of milliseconds. This guide covers what causes database bloat, how to prevent it, how to clean up what you already have, and the maintenance cadence that keeps a site fast over the long term.
Why a clean database matters · What causes database bloat · Limiting post revisions in wp-config.php · Cleaning expired transients · Database cleanup plugins · LiteSpeed Cache database tools · Tackling wp_options autoload bloat · Optimising and repairing database tables · Regular maintenance schedule · Advanced: phpMyAdmin in Plesk · Frequently asked questions
Every page load runs database queries — content, settings, theme options, plugin data. A bloated database means more data to filter on every query, which increases page load times and server resource usage.
Over months of normal use, a WordPress database accumulates thousands of rows that no longer serve any purpose — old post revisions, expired temporary data, spam comments, trashed items, orphaned metadata. Regular cleanup is one of the simplest and most effective performance wins.
Combined with Redis object caching and LiteSpeed Cache, a clean database ensures WordPress loads as fast as possible on smartxhosting.uk.
Every time you save or update a post or page, WordPress stores a complete revision in the wp_posts table. A post edited 50 times has 50 revisions, each containing the full post content. Over a blog's lifetime this adds up to thousands of revisions.
WordPress autosaves drafts as you write. Abandoned auto-drafts accumulate in wp_posts.
Transients are temporary cached data stored in wp_options. Plugins use them to cache API responses, feed data, complex calculations. Expired transients often linger long after they are needed.
Comments marked spam or trashed remain in wp_comments until permanently deleted.
Trash holds content for 30 days by default. WordPress deletes automatically after that, but 30 days of trash is still bytes in the database.
When posts, plugins or comments are deleted, associated metadata in wp_postmeta and wp_commentmeta is not always cleaned up. Over years of plugin churn this can accumulate to megabytes.
wp_options contains site settings. Options marked as "autoload" are loaded into memory on every page request. Plugins storing large amounts of data with autoload enabled slow every page on the site.
A WordPress site actively used for a year without cleanup can easily have tens of thousands of unnecessary revisions, hundreds of expired transients and megabytes of orphaned metadata. Cleanup can reduce database size by 50% or more.
The single most effective preventive measure: limit how many revisions WordPress keeps per post.
Open wp-config.php via Plesk File Manager. Add before the "That's all, stop editing!" comment:
define( 'WP_POST_REVISIONS', 5 ); define( 'AUTOSAVE_INTERVAL', 120 ); define( 'EMPTY_TRASH_DAYS', 7 );
Interpretation:
WP_POST_REVISIONS: keep only the five most recent revisions per post. Enough to revert a mistake without hoarding dozens of copies.AUTOSAVE_INTERVAL: change autosave from the default 60s to 120s, halving the auto-drafts created during editing.EMPTY_TRASH_DAYS: empty the trash after 7 days instead of the default 30.Warning: setting WP_POST_REVISIONS to false disables revisions entirely — eliminates bloat but means you cannot revert mistakes. 3–5 revisions is a safer choice.
If Redis object caching is enabled, transients are stored in Redis memory rather than the database — largely eliminating this problem. Without Redis, or if transients accumulated before Redis was enabled, clean them up.
LiteSpeed Cache > Database. Click Clean All Expired Transients. Done.
Plugins > Add New Plugin, search WP-Optimize, install, activate. WP-Optimize > Database. Tick Clean transient options. Click Run optimization.
From Plesk's WordPress Toolkit WP-CLI:
wp transient delete --all --expired
| Plugin | Features | Best for |
|---|---|---|
| WP-Optimize | Clean revisions, transients, drafts, spam, trash. Compress/optimise tables. Scheduled cleanups. Built-in page caching and image compression. | All-in-one cleanup — recommended for most sites |
| Advanced Database Cleaner | Detects orphaned tables from deleted plugins. Cleans standard bloat. Scheduled cleanups. | Sites with many plugin installs/removals over time |
| WP Sweep | Clean revisions, drafts, orphaned metadata, transients, duplicated metadata. Uses proper WordPress APIs rather than direct SQL. | Developers preferring a code-correct approach |
| Optimize Database after Deleting Revisions | Lightweight, focused on revisions. | Minimal footprint, only cleaning revisions |
For smartxhosting.uk users who already have LiteSpeed Cache, the built-in Database tab handles most needs without an additional plugin. WP-Optimize is the right pick if you want scheduled cleanups, table compression and a richer interface.
LiteSpeed Cache includes a dedicated Database tab with one-click cleanups.
OPTIMIZE TABLE on each table, reclaiming space from deleted rows.Most cleanups are safe to run any time. Clean All Transients (not expired ones) can force plugins to regenerate cached data next page load — brief slowdown on first regeneration.
Options in wp_options can be marked as "autoload" (loaded on every request) or "not autoload" (only loaded when needed). Plugins that store large data (backup logs, analytics data, cached feeds) with autoload enabled slow every page on the site.
Query the database via phpMyAdmin (accessible from Plesk):
SELECT option_name, ROUND(LENGTH(option_value)/1024, 2) AS size_kb FROM wp_options WHERE autoload = 'yes' ORDER BY LENGTH(option_value) DESC LIMIT 20;
Shows the 20 largest autoloaded options. Totals over a few megabytes indicate bloat.
For each problematic option, either:
Example SQL (via phpMyAdmin):
UPDATE wp_options SET autoload = 'no' WHERE option_name = 'some_option_name';
Plugins like Autoload Optimization or WP-Optimize expose autoload management through a UI for users uncomfortable with SQL.
Ideal: under 1 MB. Acceptable: under 3 MB. Problematic: over 5 MB. Each megabyte is loaded, unserialised and held in memory on every request.
MySQL's OPTIMIZE TABLE reclaims space from deleted rows and rebuilds indexes. Over time, frequent deletes leave tables fragmented; optimising compacts them.
Available from:
If a database table is corrupted (rare, usually only after a crash), REPAIR TABLE attempts to fix it. Enable via:
define( 'WP_ALLOW_REPAIR', true );
in wp-config.php, then visit /wp-admin/maint/repair.php. Remove the line from wp-config.php after repair.
A sensible cadence for most UK small business sites:
WP-Optimize can schedule automatic cleanups weekly or monthly. LiteSpeed Cache database cleanup is manual but quick. For a set-and-forget approach, WP-Optimize's schedule is the easiest.
For direct database inspection and manipulation, phpMyAdmin is available in Plesk:
From here you can run any SQL query, view table sizes, export dumps, and inspect specific rows. Useful for diagnosing specific issues or performing one-off cleanups not covered by plugins.
Always back up before making direct database changes. Plesk WordPress Toolkit can trigger an on-demand backup in one click — do this before any manual SQL.
Database size by table:
SELECT table_name, ROUND(data_length/1024/1024, 2) AS size_mb FROM information_schema.tables WHERE table_schema = DATABASE() ORDER BY data_length DESC;
Number of revisions per post:
SELECT post_parent, COUNT(*) AS revisions FROM wp_posts WHERE post_type = 'revision' GROUP BY post_parent ORDER BY revisions DESC LIMIT 20;
How often should I clean the database?
Monthly light cleanup (transients, trash, optimise tables) is plenty for most UK small business sites. Heavier cleanup (revisions, orphaned metadata, autoload review) quarterly or when you notice slowness.
Will cleaning the database break my site?
Standard cleanup (revisions, transients, trash, spam) is safe. Aggressive actions (deleting all transients, purging autoload) can briefly slow the site as caches rebuild. Always back up first before any cleanup.
Do I need to clean the database if I have Redis?
Redis caches database query results but does not reduce the database size itself. Transients shift to Redis (good), but revisions, orphaned metadata, trashed items still live in the database and still need periodic cleanup.
How do I know if my database is bloated?
Check database size in Plesk (Databases > your DB). WordPress sites without bloat typically run under 50 MB for a small site, 100–500 MB for a busy blog, 500 MB–2 GB for a mature WooCommerce shop. Larger than these suggests bloat.
Should I disable revisions entirely?
No — revisions are your safety net for reverting mistakes. Limit to 3–5 rather than disabling.
What is the difference between optimising tables and cleaning data?
Cleaning data removes unwanted rows. Optimising tables reclaims the disk space left behind and rebuilds indexes. Do both: clean first, optimise second.
How can I see which plugin is bloating the database?
Use Query Monitor plugin's database tab to see which plugins query most, and phpMyAdmin's Show Create to identify plugin-specific tables. Autoload queries identify plugins storing large data with autoload enabled.
Can I delete old plugin tables from the database?
Only if you are certain the plugin is no longer in use. Some plugins create custom tables; when deleted without their own uninstall routine, the tables linger. Advanced Database Cleaner identifies orphaned tables specifically.
Does a larger database always mean slower?
Not necessarily. A 1 GB database on fast NVMe SSD with Redis can be faster than a 50 MB database on a slow shared host. Size matters less than query efficiency, caching and server resources.
Is it safe to run database cleanups on a live site?
Yes for standard cleanups. For major operations (bulk deleting thousands of revisions, purging all transients), do during off-peak hours and have a recent backup. smartxhosting.uk's daily backup gives you a safety net.
Launch your WordPress site on smartxhosting.uk
UK hosting with the Plesk WordPress Toolkit, LiteSpeed Cache, Redis object caching, free Let’s Encrypt SSL, free CDN and daily backups — from £2/month.
View WordPress hosting plans →