A WordPress database rarely gets slow because of your content. It gets slow because of everything that piles up around it: dozens of revisions per post, thousands of spam comments nobody looks at, and plugin settings that load on every page long after the plugin was removed. None of it is visible from the front end, and all of it adds up.
Before you start
- A fresh backupOf the database, before you add anything below
- A way to add PHP snippetsChild theme, must-use plugin or a snippets plugin
- Access to Site HealthTools → Site Health, to see autoload warnings
Start with autoloaded options
Every option in the wp_options table has an autoload flag. When it’s on, WordPress loads that option on every request, in one query, before your page even starts building. That’s fast when the options are small. It isn’t when a plugin stores a large cache or a log there, or when a plugin you deleted years ago left its settings behind.
Since WordPress 6.6, Tools → Site Health warns you when autoloaded options get too large. If you see that warning, find the biggest ones:
wp db query "SELECT option_name, LENGTH(option_value) AS size FROM wp_options WHERE autoload IN ('yes','on','auto-on') ORDER BY size DESC LIMIT 20"No WP-CLI? Run the same query in phpMyAdmin (without wp db query and the quotes around it). Then switch autoloading off for the large ones that only one screen or one feature needs. The option keeps working; WordPress just loads it when something asks for it:
Don’t change siteurl, home, active_plugins, cron or other WordPress options. And if an option belongs to a plugin you’ve deleted, it’s usually safer to delete the option than to change its autoload flag.
Keep revisions under control
WordPress saves a revision every time you update a post, and keeps all of them by default. A post edited 80 times has 80 copies in the database. Revisions are useful, so don’t switch them off. Cap them instead:
Capping only affects new revisions. To clean up the ones you already have, and keep cleaning up, delete revisions older than 90 days with a daily scheduled task:
The editor also autosaves every minute while you write. Every two minutes is plenty for most people, and halves the requests:
Empty spam and trash on a schedule
Spam comments stay in the database until someone empties the spam folder, which on many sites is never. This deletes spam older than 15 days, in daily batches so it never slows anything down:
Trashed posts, pages and comments stay for 30 days. A week is usually enough time to notice a mistake:
After a day or two, Comments → Spam only holds recent spam, Tools → Site Health shows a smaller autoload size, and your posts keep their recent revisions.
Find the slow queries that are left
If pages are still slow after the cleanup, the problem is usually one query, not the size of the database. Log every query that takes longer than 50 ms, with the function that ran it, so you can see which plugin or template is responsible:
Use it for a day, then remove it. Logging every slow query on a busy site writes a lot.
Things to check if something looks wrong3 common fixes
- A plugin’s settings reset. It may have expected its option to autoload. Switch the flag back on for that option.
- Autoload size grows again after an update. Some plugins turn autoloading back on when they save an option. Check Site Health after plugin updates.
- Revisions are missing. The 90-day cleanup removes old ones by design. If you need a full history for some content, exclude that post type in the snippet.
Summary
Check Site Health for an autoload warning first, because that one affects every page. Then cap revisions and clean up old ones, empty spam and trash on a schedule, and switch off autoloading for large options that don’t need it. If pages are still slow, log slow queries for a day to find the real culprit.
Check your understanding
Was this helpful?
Sorry about that. What was missing?
Thanks for your feedback!

