🧹
Websites

Cleaning the WordPress Database: Revisions and Transients

06.12.2026
← All articles

A WordPress site that runs for years slowly accumulates weight in its database. Every edit of a post is stored as a separate copy, plugins leave temporary data behind, and deleted comments and drafts sit in the trash. None of this is visible until the admin dashboard starts loading slowly, backups take longer and the hosting disk quota fills up. This article covers the most common kinds of database clutter, how to remove them safely and how to stop them from piling up again.

Where revisions live and why they multiply

Each time you save a post or page, WordPress stores the previous version as a revision in the wp_posts table, with post_type set to revision and a link to the original through post_parent. Being able to roll back a bad edit is useful, but by default the number of revisions is unlimited. Edit a product description thirty times and you have thirty full copies. Page builders such as Elementor also store large JSON structures in wp_postmeta for each version, so even small sites can end up with hundreds of megabytes in these two tables.

Transients that never quite go away

Transients are WordPress's temporary cache. A plugin fetches exchange rates or update information from an API and keeps the result for a set time. Without an object cache like Redis, transients are stored in wp_options as rows prefixed with _transient_ and _transient_timeout_. An expired transient is not removed immediately; it is cleaned only when something reads it or a scheduled task runs. Transients left by removed plugins are never read again. On top of that, rows flagged with autoload are loaded into memory on every request, so oversized autoloaded data slows down every page.

Back up first and check the table prefix

Deletions in the database cannot be undone, so always start with a backup. With SSH access, WP-CLI is the most convenient tool because it reads the connection settings from wp-config.php on its own. Without SSH, an export from phpMyAdmin in the ISPmanager panel is enough.

cd ~/www/example.uz
wp db export ~/backup-$(date +%F).sql
wp db prefix

If your prefix is not wp_, adjust the SQL examples below accordingly.

Measure before you clean

wp db size --tables --human-readable

wp db query "SELECT COUNT(*) FROM wp_posts WHERE post_type = 'revision';"

wp db query "SELECT SUM(LENGTH(option_value)) FROM wp_options
  WHERE autoload IN ('yes','on','auto-on','auto');"

Since WordPress 6.6 the autoload column may contain values like on or auto-on instead of yes, which is why the query lists all of them. Autoloaded data of several megabytes deserves a closer look.

Cleaning safely with WP-CLI

Deleting revisions through WordPress's own functions also removes their related metadata, and WP-CLI does exactly that. The --expired flag removes only expired transients; --all removes every transient, which is generally safe because they are regenerated when needed.

wp post delete $(wp post list --post_type=revision --format=ids) --force
wp post delete $(wp post list --post_status=auto-draft --format=ids) --force
wp post delete $(wp post list --post_status=trash --format=ids) --force
wp transient delete --expired
wp db optimize

If a list is empty, WP-CLI just warns about missing arguments. With tens of thousands of revisions, delete them in batches or pipe the IDs through xargs. Orphaned post meta left by badly behaved plugins can be removed with SQL:

DELETE pm FROM wp_postmeta pm
LEFT JOIN wp_posts p ON p.ID = pm.post_id
WHERE p.ID IS NULL;

Keeping the database lean

Add these lines to wp-config.php above the "stop editing" comment to keep only the last few revisions, autosave less often and empty the trash sooner:

define( 'WP_POST_REVISIONS', 5 );
define( 'AUTOSAVE_INTERVAL', 120 );
define( 'EMPTY_TRASH_DAYS', 14 );

Disabling revisions entirely is not recommended, as a few copies protect you from editing mistakes. A weekly cron job running wp transient delete --expired keeps transients under control.

Example: a furniture shop in Tashkent

Imagine misol.uz, a furniture store that has run on WooCommerce for four years. Managers update descriptions often, the site is built with Elementor, and several plugins have come and gone. When the dashboard slows down, the developer finds that wp_postmeta takes up much of the database and wp_options is full of leftovers from removed plugins. After a backup, he deletes revisions, auto-drafts and expired transients, removes orphaned meta, optimizes the tables and limits revisions to five. The backup file shrinks noticeably and the dashboard becomes faster, while the live site is untouched because only unused data was removed.

If you prefer a graphical tool, plugins like WP-Optimize do the same job, but the backup rule still applies, and be careful about dropping tables that only look unused. After cleaning, test the key pages, the cart and checkout. On sayt.uz hosting, databases and phpMyAdmin are available from the ISPmanager panel, and support is available through a ticket.

Related articles

📲 Phone Number Sign-Up: Building SMS Verification Codes Properly ⬜ WordPress White Screen of Death: Causes and a Step-by-Step Fix 💳 Connecting Click and Payme to a WooCommerce store ✅ Accepting a Website: What to Get from Your Developer
🌐 Language
🇺🇿 O⁠'zbek 🇺🇿 Özbek (yangi) 🇺🇿 Ўзбек 🇷🇺 Русский 🇬🇧 English ✓