Clean up a bloated WordPress database with WP-CLI
How to clean up a bloated WordPress database with WP-CLI, in a safe order: find the big tables, back up, delete transients and revisions, then check.
The WP Waterfall team · Guides

A WordPress database grows quietly. Revisions, expired transients, and leftover plugin tables pile up until backups take longer and admin pages crawl. This guide shows how to clean up a bloated WordPress database with WP-CLI, in an order that is safe: look, back up, delete, then check.
WP-CLI is the command line for WordPress. On WP Waterfall you do not need SSH to use it. Open the
site, pick the environment, choose Tools, then WP-CLI, and type a command without the wp prefix.
Each command runs as a job and shows its output and exit code. If a command is refused, the page
says why.
Look before you delete
Start with the size of each table. The Database tab has a Schema view that lists every table with
its rows and its size. On most bloated sites the top of the list is one of three things:
wp_postmeta, wp_options, or a table a plugin left behind, such as an old log of form entries or
security scans.
Then count what is easy to remove:
post list --post_type=revision --format=count
transient list --expired --format=count
option list --autoload=on --format=count
Revisions are old copies of every post edit. Transients are temporary values plugins store with an expiry date, and many plugins never clean up the expired ones. Autoloaded options are loaded on every page view, so a long list slows every request.
Take a backup
Before anything deletes a row, open the Backups tab and choose Back up now. Add a note such as "before database cleanup". A manual snapshot holds the code, the database, and the uploads, and you can restore only the database if you need to. Better still, do the whole cleanup on staging first. Staging is a copy of your site that nobody else sees, and you can reset it from live afterwards.
Delete what you do not need
Expired transients first. This is the safest command on the list, because WordPress would throw them away anyway:
transient delete --expired
Then revisions. Keep a few if your editors rely on them. List the ids with
post list --post_type=revision --format=ids, then pass them to post delete with --force, in
batches when the list is long:
post delete 1041 1042 1043 --force
Then plugin leftovers. Deactivating a plugin keeps its tables. The Schema view shows the table, and the plugin's own documentation says whether it is safe to drop. If you are not sure, leave it: a table nobody reads costs disk space and nothing else.
Autoloaded options are the slowest to fix and the most rewarding. List the largest ones:
option list --autoload=on --fields=option_name,size_bytes --orderby=size_bytes --order=desc
A large option from a plugin you removed can go with option delete NAME. One from a plugin you
still use should be changed in that plugin's settings, not deleted.
Check the result
Run the counts again, then open the site. Clear all caches on the Caching page so you see real pages. If something is wrong, restore the database from the snapshot you took. If you would rather not type at all, Nami, the assistant in the chat, can delete expired transients for you after you press a confirm button.
For heavy queries that remain after the cleanup, the APM tool lists the slowest tables and statements. See Database access for the Schema view and for running your own SQL.
What to do next
Open the Schema view and find your biggest table. If it belongs to a plugin you removed last year, you have found your afternoon.
Read next
Related articles
Guides · November 13, 2026How to get your WordPress site cited by AI assistantsHow to get your WordPress site cited by AI assistants in 8 steps: answer first, facts in text, structured data, llms.txt, crawler rules, and prompt checks.
Guides · November 11, 2026How to scan a WordPress site for malwareHow to scan a WordPress site for malware: compare files with official copies, find PHP in uploads, check admin users, run ClamAV, and what to do next.
Guides · November 10, 2026Do you need a CDN for WordPress? How Cloudflare worksDo you need a CDN for WordPress? What a CDN does, how Cloudflare caching works, when it helps, and how to read the cache headers to check it.