A WordPress site live for five years complains of slow admin and high database CPU. The wp_options table has crossed 2 GB. The site has 80 posts. The bloat is not content — it’s transients that never expired, share counters writing a row per URL, and a security plugin keeping timestamps autoloaded forever.
What’s happening
WordPress autoloads every option marked autoload = 'yes' on every request. On a clean install that’s about 200 KB. Several patterns push it into the gigabytes:
- Transients written with
set_transient($key, $value, 0)— zero means “no expiry.” WordPress treats it as a long-lived autoloaded option. - Expired transients nothing collected. WordPress only deletes an expired transient when something tries to read it. If the original reader never returns, the row sits indefinitely.
- Plugins writing one option per entity. Per-post share counts, per-user timestamps, per-product caches. Each row is tiny; a few hundred thousand of them is not.
- Object cache misconfiguration. With a Redis or Memcached drop-in, transients route to the cache and never hit
wp_options. Remove the drop-in (a botched plugin update is common) and every transient writes to the database again.
The cost shows up two ways: every admin page load deserializes the full autoloaded payload, and database backups balloon until nightly mysqldump runs into the morning.
How to verify
Measure autoloaded size:
SELECT ROUND(SUM(LENGTH(option_value))/1024/1024, 2) AS autoload_mb
FROM wp_options WHERE autoload = 'yes';
Anything past 3 MB is hurting every authenticated request. Then find the worst offenders:
SELECT option_name, ROUND(LENGTH(option_value)/1024, 2) AS kb
FROM wp_options WHERE autoload = 'yes'
ORDER BY LENGTH(option_value) DESC LIMIT 30;
Count transients and how many are expired:
SELECT COUNT(*) FROM wp_options WHERE option_name LIKE '\_transient\_%';
SELECT COUNT(*) FROM wp_options
WHERE option_name LIKE '\_transient\_timeout\_%'
AND option_value < UNIX_TIMESTAMP();
Hundreds of thousands of expired transients is common on a site unmaintained for years. Confirm whether an object cache is in front:
ls -la wp-content/object-cache.php
wp eval 'var_dump(wp_using_ext_object_cache());'
If the drop-in is missing, every transient write hits the database.
The fix
Clear expired transients first — WP-CLI handles it correctly across cache and database:
wp transient delete --expired
For a deeper purge (only when you know which transients are functional vs disposable):
wp transient delete --all
Flip autoload off on oversized options that aren’t actually read every request:
UPDATE wp_options SET autoload = 'no' WHERE option_name = 'oversized_option_name';
For prevention, install a real object cache drop-in backed by Redis or Memcached — transients route to memory instead of the options table, and the long-term growth pattern collapses. Set an alert on autoload_mb so the regression is caught before it hits p95.
Stack Harbor includes wp_options hygiene and object cache configuration in the enterprise WordPress hosting operating model; Monitoring and Support catches the DB-growth regression early. If a backup window has crossed midnight, we can clean it up.