Cleaning up and optimising the WordPress database

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

How-to guideIntermediate2 min readUpdated

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.

Not hosting with Traxio yet? WordPress hosting from 99p a month is free for 30 days with no card, then £0.99 a month.

Popular

Tip: press / to search from any pageSee all results