Cleaning a Bloated WordPress Database: Revisions, Transients and Autoload
Short answer: A large WordPress database usually comes from four sources: post revisions, expired transients, options that load on every page, and tables left behind by removed plugins. Only the first two are routine to clean. Options and leftover tables need a plugin-by-plugin check. Back up the database first, make a copy on a test site, record the size before and after, and change one category at a time. Measure the autoloaded options, because those slow every page load even when the total database size looks ordinary.
Four sources of bloat, with risk ratings
| Source | What it is | Risk of cleaning | Typical action |
|---|---|---|---|
| Post revisions | Saved drafts of each post or page | Low | Limit how many are kept |
| Expired transients | Temporary cached values with an expiry time | Low | Delete the expired ones |
| Autoloaded options | Settings that load on every request | Medium to high | Find the heavy ones, then decide |
| Leftover tables | Data from plugins that were deleted | Medium to high | Confirm the plugin is gone for good |
Revisions are useful for undo, but a page edited 300 times keeps 300 copies. Transients are temporary by design, so expired rows can be removed without harm. Options are different: a single setting may hold a large serialized array that a plugin reads on every page, and deleting it can switch that plugin off. Leftover tables need the most care because another plugin may still read them.
Step 1: Back up and copy
Export the database from your host's control panel or a backup plugin, and download the file to a place outside the server. Then restore that file onto a staging copy and confirm that the site loads there. A backup you have never restored is only a hope. If you cannot create a staging copy, at least keep the backup until the cleanup has run for a week without complaints.
Step 2: Measure before you change anything
Record the size of the database and the size of autoloaded data. You can check the autoloaded total with a read-only query in your database tool, using your own table prefix in place of wp_:
SELECT SUM(LENGTH(option_value)) AS autoload_bytes
FROM wp_options
WHERE autoload = 'yes';
Write down the number, then list the largest autoloaded rows:
SELECT option_name, LENGTH(option_value) AS bytes
FROM wp_options
WHERE autoload = 'yes'
ORDER BY bytes DESC
LIMIT 20;
A total of a few hundred kilobytes is normal for a small site. If the total is several megabytes, one or two plugins are usually responsible, and those are the rows to investigate.
Step 3: Limit revisions
Revisions are safe to trim. Add a line to wp-config.php, above the line that says to stop editing, to keep a fixed number:
define( 'WP_POST_REVISIONS', 5 );
This limits future revisions. It does not remove the old ones, so delete those with a cleanup plugin or a query that you have tested on the staging copy. Keep the number small enough to save space and large enough to undo a bad edit.
Step 4: Remove expired transients
Expired transients are safe to delete, because WordPress recreates whatever it needs. Use a maintenance tool that deletes only expired rows. Avoid deleting every transient at once, since a few active ones may be holding a current login or a cached search result. Clear the site cache afterwards.
Step 5: Review the autoloaded options
Look at the largest options from Step 2. For each one, find the plugin that created it by its name prefix, then read the plugin's documentation or settings page. Three answers are common. The plugin is still used and the option is correct, so leave it. The plugin is removed and the option is a leftover, so delete it. The plugin keeps a log or cache that can be set to not autoload, so change that setting. Never delete an option you cannot identify without testing it first on staging.
Step 6: Find tables left by removed plugins
Compare the table names in your database with the plugins installed. A table whose prefix matches a plugin you deleted years ago is a candidate. Before dropping it, confirm that no other plugin or theme uses it, and keep a copy of the table export. Dropping a table cannot be undone without the backup.
Plugins that leave data behind
Some plugins are tidy when they are removed and some are not. Settings, logs, scheduled jobs and custom tables can all remain after deletion. Check for these patterns after you remove a plugin:
- Log tables that grow with every form submission, page view or email sent. These are often the largest tables in an otherwise small site.
- Scheduled events that still run for a plugin that no longer exists, which you can see in a cron management plugin or in your host's tools.
- Custom post types whose posts stayed in the database after the plugin was deleted. These show up as posts with no matching editor screen.
- Cached previews and thumbnails stored as options or in uploads, which a cleanup tool may not detect on its own.
Write the plugin name next to each leftover, so you can explain later why the item was removed. A short written list is also useful if you hand the site to someone else.
Step 7: Check the result
After each category, run the same size queries again and note the difference. Load the home page, a product or article page, the login screen, and any forms or search features. Check the error log for new messages. If something breaks, restore the backup, identify the option or table that caused it, and leave it alone.
FAQ
Is it safe to clean the database on a live site?
It can be, when you back up first and change one category at a time. Staging is safer because you can test every page before the live site is touched.
Will a smaller database make my site faster?
Sometimes. Removing heavy autoloaded options often has the biggest effect, while removing revisions mostly saves storage. Measure page load before and after to see whether the change matters for your site.
Should I use a plugin for cleanup?
A plugin can save time, but read what it deletes and turn off any setting that removes data you have not reviewed. Use the plugin to perform the routine deletions, and do the autoload and table review by hand.
How often should I clean up?
Once a quarter is enough for most sites. Check the autoload size after installing or removing a major plugin, because that is when new heavy options usually appear.
If the database keeps growing after cleanup, tell us what plugins you run and our studio can trace which ones write the data and suggest a lighter setup.