Cleaning up and optimising the WordPress database
What bloats a WordPress database — revisions, transients, spam, orphaned plugin tables — and how to clean it safely.
On this page
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
- Back up the database first. How to export a database (backup with phpMyAdmin)
- Empty trash in Posts, Pages and Comments, and delete spam comments.
- Use a reputable database clean-up plugin to remove revisions, auto-drafts and expired transients.
- 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?
- Speed up a slow WordPress site
Advanced · 60 min
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.
- Fix a WordPress critical error without admin accessFind the plugin or theme behind ‘There has been a critical error’ using logs and the File Manager, disable it, and recover.
- Blank white page: how to find the hidden errorA completely blank page usually means a PHP error that isn’t displayed. How to reveal it with logs and fix the cause.
- “Too many redirects” and HTTPS redirect loopsFix ERR_TOO_MANY_REDIRECTS: conflicting HTTPS and www rules in .htaccess, WordPress settings, plugins and Cloudflare’s SSL mode.
- How to log in to WordPress adminWhere the WordPress login page is, what to do if you’ve forgotten the password or the password reset email never arrives.
Spotted something out of date or unclear? Tell us and we’ll fix it.