A WordPress site that used to load wp-admin in 400 ms takes nine seconds. The slow query log shows SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes' returning 38 MB on every request. Nobody changed the theme, nobody added a plugin recently. Someone, two years ago, network-activated a plugin that writes a fat cache blob into wp_options with autoload = 'yes' and never cleans it up.
What’s happening
WordPress loads every row in wp_options whose autoload column is 'yes' on every single request — wp_load_alloptions() runs early in wp-settings.php, before themes, before plugins, before the router. The result is cached in the object cache when one is available, but with no persistent object cache (the default), the query runs for every uncached page view and every admin screen.
The schema is option_id, option_name, option_value, autoload. The option_value column is LONGTEXT — there is no hard ceiling other than max_allowed_packet. Plugins use it as a key-value store: cron schedules, license keys, settings arrays, and — the dangerous pattern — cached query results, image-CDN URL maps, geolocation tables. When a plugin writes one of those with autoload = 'yes' and never garbage-collects, the row grows without bound.
Three accumulation patterns we see repeatedly:
- Expired transients that were stored with
autoload = 'yes'. A transient written viaset_transient()without an expiration goes intowp_optionswithautoload = 'yes'. With expiration, it goes in withautoload = 'no'and a companion_transient_timeout_<key>row. Plenty of plugin code forgets the expiration argument. - Plugin caches stored as serialized PHP. A WP-Rocket-style URL map, an Elementor template cache, a Wordfence rule blob. Some of these legitimately need to be fast to read; others are autoloaded by accident.
- Plugin housekeeping that doesn’t run.
wp_scheduled_deleteclears auto-drafts, but plugin-specific cleanup is on the plugin’s own cron, and on a site with WP-Cron disabled in favour of a system cron that only fireswp-cron.phpon traffic, those events lag indefinitely.
A site with a single 50 MB autoload row will allocate 50 MB of PHP memory on every request just to hold the unserialized array. Anything below WP_MEMORY_LIMIT becomes survivable but expensive; once you cross the limit, fatal errors begin to appear in wp-admin only — front-end caching masks them.
How to verify
Start with the size of wp_options and the autoloaded subset:
SELECT
COUNT(*) AS rows_total,
SUM(LENGTH(option_value)) / 1024 / 1024 AS total_mb,
SUM(CASE WHEN autoload = 'yes' THEN LENGTH(option_value) ELSE 0 END) / 1024 / 1024 AS autoload_mb
FROM wp_options;
A healthy site has autoload under 1 MB. Anything over 5 MB warrants investigation; over 20 MB is an incident.
Now find the offenders:
SELECT
option_name,
ROUND(LENGTH(option_value) / 1024 / 1024, 2) AS size_mb,
autoload
FROM wp_options
WHERE autoload = 'yes'
ORDER BY LENGTH(option_value) DESC
LIMIT 20;
The top of that list is your audit target. Names tell you a lot — wf_* is Wordfence, rocket_* is WP-Rocket, elementor_* is Elementor, _site_transient_* is multisite transients, cron is the WP-Cron schedule (which can itself bloat past 1 MB on a busy site).
For transients specifically:
SELECT
COUNT(*) AS count,
SUM(LENGTH(option_value)) / 1024 / 1024 AS size_mb
FROM wp_options
WHERE option_name LIKE '\_transient\_%'
OR option_name LIKE '\_site\_transient\_%';
WP-CLI equivalents that are safer to run in production (no risk of leaving a session locked):
wp option list --autoload=on --format=csv --fields=option_name,size_bytes \
| sort -t, -k2 -n -r | head -20
wp transient list --format=count
wp option list --size reports the in-PHP-serialized size, not the disk size; the SQL above gives you the disk truth.
To confirm a row is the actual culprit, examine its value briefly — don’t SELECT option_value blindly on a 50 MB row over a slow link:
SELECT option_name, LEFT(option_value, 200), LENGTH(option_value)
FROM wp_options
WHERE option_name = 'rocket_cache_files';
If the first 200 bytes look like a serialized PHP array (a:1234:{...), the plugin is using wp_options as a key-value store and the question is whether autoload is correct for that workload.
The fix
Three operations, in order. Take a database backup first — none of these are reversible without one.
1. Demote rows from autoload = ‘yes’ that don’t need to be there.
A row should be autoload = 'yes' only if it is read on most page loads. If you read it once on a settings screen, it should be 'no':
UPDATE wp_options
SET autoload = 'no'
WHERE option_name IN (
'wf_scan_results',
'rocket_cache_files',
'elementor_remote_info_library'
);
After demoting, flush the in-process alloptions cache so PHP rebuilds it on the next request:
wp cache flush
wp option get rocket_cache_files > /dev/null # forces re-read with new autoload state
If the plugin re-sets the option with autoload = 'yes' on its next write, you’ve found a plugin bug — file it with the vendor or wrap the option write with a filter (pre_update_option_<name>) that forces autoload off.
2. Delete expired transients and the orphaned timeout rows.
WordPress core deletes expired transients on read, not on a schedule. Rows that are never read again sit in the table forever. WP-CLI handles this cleanly:
wp transient delete --expired
wp transient delete --all # if you're confident no plugin is mid-write
For a manual sweep, the SQL is:
DELETE a, b FROM wp_options a
LEFT JOIN wp_options b
ON b.option_name = CONCAT('_transient_timeout_', SUBSTRING(a.option_name, 12))
WHERE a.option_name LIKE '\_transient\_%'
AND a.option_name NOT LIKE '\_transient\_timeout\_%'
AND b.option_value < UNIX_TIMESTAMP();
On multisite, repeat with _site_transient_ prefixes against the network wp_sitemeta table.
3. Reclaim the table space.
DELETE removes rows but doesn’t shrink the InnoDB data file. After a large cleanup:
OPTIMIZE TABLE wp_options;
On InnoDB this rebuilds the table; it locks the table briefly on small databases and uses ALTER TABLE ... ENGINE=InnoDB semantics on larger ones. Schedule it in a maintenance window if wp_options is contended.
To prevent recurrence, add a weekly system cron that runs the cleanup unattended:
17 3 * * 0 cd /home/acmewp/public_html && /usr/local/bin/wp transient delete --expired --allow-root >> /var/log/wp-options-cleanup.log 2>&1
And alert on autoload size — SUM(LENGTH(option_value)) WHERE autoload='yes' over a threshold (10 MB is a reasonable starting point) is a Prometheus check that catches the next plugin doing the wrong thing within a week instead of a year.
Stack Harbor audits wp_options size, autoload composition and transient hygiene as part of enterprise WordPress hosting operations, with the cleanup automated under environment management. If your admin is slow and you suspect autoload, we can audit it.