WordPress database cleanup: what is safe to do

A bloated database slows WordPress in a few ways. What to clean (autoloaded options, revisions, transients, trash), what to leave, and how to do it safely.

AdvancedHow-to7 min readUpdated October 30, 2026

In this guide
  1. What "a slow database" means
  2. Step 0: back up, and work on a copy
  3. Step 1: measure what is there
  4. Step 2: autoloaded options
    1. Find the largest
    2. What to do about a large one
  5. Step 3: revisions
  6. Step 4: trash, spam and drafts
  7. Step 5: transients
  8. Step 6: tables and storage
  9. Step 7: check the result
  10. Mistakes to avoid
  11. Check your own page
  12. Sources

What "a slow database" means

WordPress keeps posts, comments, users and settings in a database. Every page that is not served from a cache runs a number of queries. The WordPress Advanced Administration Handbook says WordPress repeats many queries on every request, which is why a persistent object cache and a page cache matter. See WordPress caching.

So the database matters in three situations:

A cached page for a logged-out visitor skips most of this. That is why database cleanup is not the first thing to try, and why it often disappoints when it is.

Step 0: back up, and work on a copy

Take a full backup of the files and the database, and keep it until the site has run well for a while. Do the first clean-up on a staging copy. A cleanup that removes the wrong rows can break a plugin or a page, and the damage may not show on the page you test first.

Step 1: measure what is there

Autoloaded options. Open Tools, then Site Health, then the Status tab, and look for Autoloaded options. This test was added in WordPress 6.6. According to the core source, it reports a problem when the total size of the autoloaded options reaches 800,000 bytes. The Handbook gives the same guideline: keep autoloaded options under 800 KB. The screen also shows how many there are and their total size.

Server response time on pages that are not cached. Test a page that your cache skips, such as a search result page or a page while you are logged in. If it is much slower than a cached page, the work behind it is worth a look. The server response time guide shows how to measure it.

What the queries are. WordPress can record every query when SAVEQUERIES is set to true, which the handbook's wp-config page describes. Tools can show the function behind each query. Use this on a copy, because it adds work to every request.

Step 2: autoloaded options

An option is a saved setting, stored in the wp_options table. Each option has an autoload value. When it is on, WordPress loads the option at the start of every request. The Handbook says each plugin and theme defines its own options and which ones autoload, and that too many can slow down the site.

Core already guards against the worst case. Since WordPress 6.6, an option saved without an explicit autoload value is set not to autoload if its value is larger than 150,000 bytes. A plugin that sets the value itself can still override that.

Find the largest

Run this query in your host's database tool. Your table prefix may differ from wp_:

SELECT option_name, LENGTH(option_value) AS bytes, autoload
FROM wp_options
WHERE autoload IN ('yes', 'on', 'auto', 'auto-on')
ORDER BY bytes DESC
LIMIT 20;

These four values are the ones core treats as autoloading. The names usually start with the plugin or theme that wrote them. A large entry from a plugin you removed years ago is a common find.

What to do about a large one

  1. Identify the owner. Search for the option name, or look at its prefix. Do not touch anything you cannot identify.
  2. If the plugin is gone and the option is not needed, delete it, after the backup.
  3. If the plugin is in use, ask whether the option has to load on every page. If it is only used on one screen, set it not to autoload. In code, wp_set_option_autoload( 'option_name', false ) does this. Since WordPress 6.7 the values yes and no are deprecated in favor of on and off.
  4. Check the result. Reload the Site Health screen and the pages that use the plugin. If an option that every page needs is set to not autoload, WordPress has to fetch it separately, which can be slower. Change one option at a time and test.

Step 3: revisions

Every time you save a post, WordPress can keep the earlier version. By default it keeps all of them. The core default for WP_POST_REVISIONS is true, which means no limit, and the editor also autosaves every 60 seconds by default.

The handbook shows how to limit this in wp-config.php:

define( 'WP_POST_REVISIONS', 3 );

A number keeps that many revisions for each post, and false turns revisions off. The limit applies as posts are saved. It does not by itself delete the revisions that already exist. A cleanup plugin or a developer can remove the old ones in bulk.

Revisions make the posts table larger and backups slower. They matter less for the speed of a page that is cached. Keep a few, so that editors can still go back.

Step 4: trash, spam and drafts

WordPress empties the trash after 30 days by default. The setting is EMPTY_TRASH_DAYS, and it covers posts, pages, attachments and comments. Core also has scheduled tasks that delete old automatic drafts. You can empty the trash yourself, and clear spam comments, from the admin screens.

A large number of spam comments in a busy table can slow some queries. Clearing them is safe.

Step 5: transients

A transient is a value that a plugin saves for a limited time. The handbook explains where it goes. With a persistent object cache, transients can live in the cache. Without one, WordPress writes them to the database, typically in wp_options. Heavy use of transients without a persistent cache therefore adds reads and writes and makes the options table grow.

Two details matter for cleanup:

Transients are meant to be replaceable. Deleting expired ones is safe. Deleting all of them is usually safe too, since plugins rebuild them, but a few plugins keep short-lived state in a transient, and the site may be slower for a while. Do it at a quiet hour and test.

A persistent object cache moves transients out of the database and is the better fix for a site that uses many of them.

Step 6: tables and storage

Step 7: check the result

  1. Reload the Autoloaded options test in Site Health and compare the size.
  2. Test the uncached pages again and compare the server response time with your notes.
  3. Look at the size and the time of your next backup.
  4. Use the site as a visitor and as an editor. Check forms, the cart, search and the admin.

Do not expect a change on cached pages. The gain is on uncached pages, on the admin, and on backups.

Mistakes to avoid

Check your own page

Run the free audit and look at Document request latency. If the server response line fails on a page that should be cached, fix the cache first. If cached pages are fast but the admin, the cart or search is slow, this guide is the next step.

Sources

Start here

Free website audit

Live Google data for any public page: mobile and desktop.

Mobile + desktop · Lighthouse lab test · Real-user Chrome data when Google has it

Rather have this done for you? WordPress speed · Book a call

Related guides

All guides →