Cleaning up and optimising the WordPress database

What bloats a WordPress database — revisions, transients, spam, orphaned plugin tables — and how to clean it safely.

Guide2 min readLast updated
On this page
  1. What builds up
  2. Safe clean-up
  3. Limit future revisions
  4. Leftover plugin tables
  5. Large autoloaded options
  6. If it doesn’t work

Over time a WordPress database collects data nothing uses. A leaner database backs up faster and can make admin screens quicker.

What builds up

  • Post revisions — every saved draft of every post
  • Auto-drafts and trash
  • Spam and trashed comments
  • Expired transients — temporary cached data plugins forgot to remove
  • Tables left by deleted plugins
  • Autoloaded options — settings loaded on every page, sometimes megabytes of them

Safe clean-up

  1. Back up the database first. How to export a database (backup with phpMyAdmin)
  2. Empty trash in Posts, Pages and Comments, and delete spam comments.
  3. Use a reputable database clean-up plugin to remove revisions, auto-drafts and expired transients.
  4. Optimise tables in phpMyAdmin. How to repair and optimise database tables

Limit future revisions

In wp-config.php:

define('WP_POST_REVISIONS', 5);

Leftover plugin tables

Tables with a prefix matching a plugin you’ve deleted can usually be dropped, but only if you’re certain which plugin created them. When in doubt, leave them.

Large autoloaded options

In phpMyAdmin, run a query on wp_options for rows with autoload set to yes, ordered by the length of option_value. Huge rows usually belong to a specific plugin; deal with them through that plugin’s settings rather than deleting rows by hand.

Prefer to follow along?

Not hosting with Traxio yet? WordPress hosting from 99p a month is £0.99 a month.

If it doesn’t work

These guides cover the most common problems, starting with what you can see. Or browse every fix for a common problem.

Spotted something out of date or unclear? Tell us and we’ll fix it.

Keep going