DSDrillSEO
WordPress Database Optimization: How to Clean Bloat, Transients & Speed Up Queries
July 13, 2026•DrillSEO Editorial Team

WordPress Database Optimization: How to Clean Bloat, Transients & Speed Up Queries

≡Table of Contents

WordPress Database Optimization: How to Clean Bloat, Transients & Speed Up Queries

Why WordPress Databases Slow Down Over Time

As a WordPress site grows, the MySQL/MariaDB database accumulates thousands of obsolete post revisions, spam comment metadata, orphaned term relationships, and expired transients. Over time, unindexed queries take hundreds of milliseconds to execute, directly degrading your server's Time to First Byte (TTFB).

1. Cleaning Autoloaded Data in wp_options

WordPress loads all rows where autoload = 'yes' into memory on every single page request. If total autoloaded data exceeds 800KB, your server response time will suffer significantly.

SQL Query to Identify Heavy Autoloaded Options:

SELECT option_name, length(option_value) AS option_value_length 
FROM wp_options 
WHERE autoload='yes' 
ORDER BY option_value_length DESC 
LIMIT 20;

SQL Query to Disable Autoload on Non-Critical Plugin Data:

UPDATE wp_options SET autoload = 'no' WHERE option_name = 'heavy_deactivated_plugin_cache';

2. Deleting Expired Transients

Transients are temporary cache records stored in wp_options. Many plugins fail to delete expired transients, leaving millions of stale rows behind:

-- Delete expired transient timeouts
DELETE FROM wp_options WHERE option_name LIKE ('_transient_timeout_%') AND option_value < UNIX_TIMESTAMP();

-- Delete matching transient data
DELETE FROM wp_options WHERE option_name LIKE ('_transient_%') 
AND option_name NOT IN (SELECT CONCAT('_transient_', SUBSTRING(option_name, 20)) FROM (SELECT * FROM wp_options) AS temp WHERE option_name LIKE ('_transient_timeout_%'));

3. Limiting Post Revisions in wp-config.php

By default, WordPress stores an infinite number of revisions for every post edit. Limit revisions to 3 by adding this line to wp-config.php:

define('WP_POST_REVISIONS', 3);
define('EMPTY_TRASH_DAYS', 7);
D

About DrillSEO Editorial Team

Expert in SEO and digital marketing with years of experience helping businesses improve their online presence.

Newsletter

Stay Updated with SEO Tips

Subscribe to our newsletter to receive the latest SEO tips, tools, and strategies directly in your inbox

A
B
C
D
+2K
others already subscribed
4.9/5 from 2200+ reviews
We respect your privacy. Unsubscribe at any time.