Skip to main content

How to Clean Up a WordPress Database and Find What Really Slows It Down

  • By Md Sayfur Rahman
  • 6 min read
How to Clean Up a WordPress Database and Find What Really Slows It Down

Ask anyone how to clean a WordPress database and you will hear the same three things. Delete old revisions, empty the spam folder, remove expired transients. Those steps are not wrong, but on most business sites they barely change anything. The data that really slows a database down usually sits somewhere nobody looks.

This guide uses a different order. It starts with where the weight really is on a modern WordPress site, then shows how to check your own database and clean it without breaking anything.

Where the Weight Really Sits

A WordPress database is a set of tables. Posts and pages live in one, settings in another, and plugins add their own. On a small blog, revisions and comments can be a large part of the total. On a shop or any site with many plugins, background jobs and plugin data usually grow much faster.

A real example from TurboPress, published in March, shows how big the difference can be. They cleaned a WooCommerce store that had been running for about two years with around 40 orders a day. The two tables that store WooCommerce's background jobs, called Action Scheduler, had grown to this size.

TableBefore cleanupAfter cleanup
Background jobs (actions)354,354 rows, about 230 MB12,847 rows, 4.8 MB
Job logs892,441 rows, about 141 MB31,206 rows, 6.2 MB
TotalMore than 370 MBAbout 11 MB

Almost all of those rows were jobs that had already finished, such as order emails, analytics updates and syncs with tools like Mailchimp or Klaviyo. WooCommerce is supposed to delete finished jobs after 30 days, but on busy stores the cleanup falls behind. The result was 350 MB of extra data in every backup and a Scheduled Actions screen that was very slow to open. In the same article, the author says stores running for about 18 months often have 200,000 to 500,000 rows in that table, and the worst case they saw had 1.2 million.

It can get much worse when something goes wrong. In February, a WordPress developer wrote on his blog about a site where a bug made Action Scheduler create jobs in a loop. The table reached about 26.7 million rows before the bug was fixed. No amount of revision cleanup would have helped that site.

The second hidden problem is autoloaded data. These are settings that WordPress loads on every single page view, whether the page needs them or not. Plugins often store large amounts of data here and leave it behind when you delete them. WordPress's own Site Health screen warns you when autoloaded data passes about 800 KB, because past that point it starts to slow down every request.

How to Check Your Own Database

You do not need to guess. A few minutes in your hosting panel shows you where your own weight is. Open phpMyAdmin from your hosting control panel, select your WordPress database and sort the table list by size.

  • If a table with "actionscheduler" in the name is near the top, you have the same problem as the store above.
  • If wp_options is large, autoloaded data or old plugin settings are the likely cause.
  • If you see tables with names you do not recognize, they probably belong to plugins you deleted long ago. The part of the name after wp_ usually tells you which plugin.
  • If wp_posts and wp_postmeta are the biggest, revisions, old drafts and product data are the main weight, and the classic cleanup will help.

Also open Tools and then Site Health in WordPress. If it shows a warning about autoloaded options, you can see which ones are biggest with the query below. It lists the ten largest options that load on every page, so you can see which plugin they belong to.

SELECT option_name, LENGTH(option_value) AS size
FROM wp_options
WHERE autoload IN ('yes', 'on', 'auto-on', 'auto')
ORDER BY size DESC
LIMIT 10;

Not sure what is safe to delete? Our WordPress speed optimization service checks your database table by table, cleans it on a copy first and shows you the before and after sizes.

How to Clean It Without Breaking Anything

Database cleanup is one of the few maintenance jobs where one wrong click can delete real data, such as orders or customer accounts. So the order of the steps matters. Take a full backup first, as our WordPress backup guide explains, and if the site is a shop, try the cleanup on a staging copy before the live site.

  1. Clear finished background jobs. If your host offers WP-CLI, the command below removes completed, failed and cancelled jobs older than the retention period in safe batches. Without WP-CLI, ask your host or use a cleanup plugin that supports Action Scheduler.
  2. Look at failed jobs before deleting them. Thousands of failed jobs with the same name point to a plugin that keeps failing, often a payment, email or sync tool. Fix that plugin, or the table will fill up again.
  3. Turn off autoload for big options from old plugins. If a large autoloaded option belongs to a plugin you no longer use, delete it. If it belongs to an active plugin, ask the developer before you change anything.
  4. Drop tables from deleted plugins. Only remove a table when you are sure the plugin is gone for good, and keep the backup for a few weeks.
  5. Then do the classic cleanup. Remove old revisions, spam, trashed posts and expired transients with a plugin such as WP-Optimize or Advanced Database Cleaner.
  6. Optimize the tables. After large deletions, the optimize option in phpMyAdmin or your cleanup plugin gives the free space back to the server.

For step 1, this is the WP-CLI command. It deletes finished jobs in batches of 1,000, so the server is not overloaded while it runs.

wp action-scheduler clean --batch-size=1000

Be careful with SQL queries copied from old tutorials. Many of them check for autoload values of "yes" only, but newer WordPress versions also use values like "on" and "auto". Others delete revisions but leave their extra data behind in wp_postmeta. A good cleanup plugin handles these details for you.

Keep It From Growing Back

A database fills up again if nothing changes. Limiting revisions in wp-config.php keeps posts from piling up, and checking the Action Scheduler screen once a month shows early if a plugin starts failing again. If your site does a lot of background work, an object cache such as Redis also takes pressure off the database, as our guide to WordPress caching plugins explains.

For shops, a lighter database also helps the checkout, which talks to the database more than any other page. Our guide to speeding up WooCommerce checkout covers that side. And if you would rather not watch table sizes yourself, database checks and cleanups are part of every WordPress maintenance plan we run.

Written by

Md Sayfur Rahman

A website that doesn't break, doesn't slow down, and doesn't get hacked. Sounds like a fantasy. But it's exactly what I build. After more than 14 years in the WordPress ecosystem, I've learned that a truly great website isn't just about how it looks on launch day. It's about how it performs under pressure, how easy it is to manage, and how secure it remains as time goes on.