WordPress Database Optimization - What to Clean, What to Keep (2026)

Over time, the WordPress database fills with revisions, spam, expired transients and leftovers from old plugins. Cleaning it up won't transform a cached site, but it can make uncached pages and the admin noticeably snappier.

Why the Database Affects Speed

Every uncached page load asks the database for content, settings and metadata. The larger and messier the tables involved, the more work each query does.

Page caching hides much of this for anonymous visitors, because cached pages skip the database. But the admin area, logged-in users, carts, checkouts, searches and uncached pages all depend on it. That's where a bloated database shows up most.

What Bloats a WordPress Database

Illustration for What Bloats a WordPress Database on the WordPress Database Optimization page, showing a database diagram
Common sources of database bloat
SourceWhat It IsSafe to Clean?
Post revisionsSaved versions of posts and pagesYes, keep a few recent ones if you like
Auto-draftsDrafts WordPress creates automaticallyYes
Trashed posts and commentsItems in the trashYes
Spam commentsComments marked as spamYes
Expired transientsTemporary cached data past its expiryYes
Orphaned post metaMetadata for posts that no longer existYes, with a trusted tool
Leftover plugin tables and optionsData from plugins you've deletedYes, if you're sure the plugin is gone for good
Large autoloaded optionsSettings loaded on every requestCarefully; see below
Logs and analytics tablesData stored by some pluginsDepends; check the plugin's settings

Step 1: Back Up First

Database changes can't be undone without a backup. Before any cleanup, take a full backup through your host or a backup plugin, and make sure you know how to restore it.

Step 2: Clean the Easy Stuff

Most sites can safely remove revisions, auto-drafts, trash, spam and expired transients. A database cleanup tool handles this in a few clicks.

WP Rocket includes this in its Database tab under Backend: post cleanup (revisions, auto-drafts, trashed posts), comment cleanup (spam and trashed comments), transient cleanup, database table optimization and automatic scheduled cleanup. Other plugins like WP-Optimize offer similar options.

  1. Back up

    Take a full backup.

  2. Choose what to clean

    Revisions, auto-drafts, trash, spam and expired transients are safe starting points.

  3. Run the cleanup

    Use your plugin's database tool.

  4. Optimize tables

    This reclaims space left by deleted rows.

  5. Schedule it

    Set weekly or monthly automatic cleanup so bloat doesn't return.

Step 3: Limit Revisions Going Forward

Illustration for Step 3: Limit Revisions Going Forward on the WordPress Database Optimization page, showing a database diagram

Revisions are useful for undoing mistakes, but unlimited revisions can add thousands of rows. You can limit them by adding a line to wp-config.php that sets WP_POST_REVISIONS to a small number, such as 5 or 10. Existing revisions stay until you clean them.

Step 4: Check Autoloaded Options

The options table stores site settings. Options marked to autoload are loaded into memory on every single request, cached or not. Plugins sometimes store large amounts of data there, and deleted plugins often leave it behind.

Large autoloaded data slows every uncached request and the admin. Site Health in recent WordPress versions warns when autoloaded options are unusually large. See reducing autoloaded options for how to find and fix the biggest ones safely.

Step 5: Remove Leftovers From Old Plugins

Many plugins leave tables and options behind when deleted. If you've tried lots of plugins over the years, those leftovers add up.

Some database tools show tables and options that don't belong to active plugins. Be careful: a table's name doesn't always make its owner obvious, and some plugins share data. Only remove leftovers you're certain about, and always with a backup.

Step 6: Look at Large Tables

Illustration for Step 6: Look at Large Tables on the WordPress Database Optimization page, showing a database diagram

Check which tables are largest in your host's database tool. Common large tables include:

A large logs or statistics table is often the easiest big win: many plugins have a setting to limit how long logs are kept.

What Database Optimization Won't Fix

Cleaning the database won't fix front-end problems like render-blocking CSS, heavy JavaScript or large images. It also won't make much difference to anonymous visitors on cached pages.

If your issue is slow uncached pages, combine database cleanup with object caching, fewer heavy plugins and better hosting. If your issue is Core Web Vitals, focus on front-end optimization first.

Safe Settings for WP Rocket's Database Tab

WP Rocket database cleanup options
OptionWhat It RemovesOur Suggestion
RevisionsOld saved versions of postsClean, after limiting future revisions
Auto-draftsAutomatic drafts never publishedClean
Trashed postsPosts in the trashClean, after checking the trash
Spam commentsComments marked as spamClean
Trashed commentsComments in the trashClean
TransientsExpired temporary dataClean
Optimize tablesReclaims unused spaceRun occasionally
Automatic cleanupRuns the selected cleanups on a scheduleWeekly for busy sites, monthly for small ones

Take a backup before the first cleanup on any site. After that, scheduled cleanup only removes the same kinds of low-risk data.

Database Optimization for WooCommerce

Illustration for Database Optimization for WooCommerce on the WordPress Database Optimization page, showing a database diagram

Stores have extra database considerations:

See speeding up WooCommerce and object caching.

Signs Your Database Needs Attention

Slow admin screens

Especially the posts list, product list or settings pages.

Slow uncached pages

Search results, archives and logged-in pages feel slow while cached pages are fine.

Site Health warnings

Notices about autoloaded options or database size.

Large backups

Backups that grow much faster than your content.

Query Monitor shows slow queries

Queries that take noticeably longer than the rest.

How Often to Clean

Suggested cleanup schedule
Site TypeSuggested Frequency
Small blog or brochure siteMonthly
Active blog with many editorsWeekly
WooCommerce storeWeekly, plus regular review of large tables
Membership or community siteWeekly
Any site after removing many pluginsOnce, with a careful leftover review

A Worked Example: A Sluggish Admin

A content site with thousands of posts has a slow admin. Editing screens take several seconds to load.

The owner backs up, cleans tens of thousands of old revisions and spam comments, and limits future revisions to ten. That helps a little. The bigger fix comes from Site Health's autoload warning: a deleted analytics plugin had left a large autoloaded option. Removing it makes the admin noticeably faster, and scheduled weekly cleanup keeps things tidy.

WordPress Database Optimization FAQ

Does optimizing the database speed up WordPress?

It helps uncached pages, logged-in users and the admin. Anonymous visitors on cached pages see less difference.

Is it safe to delete post revisions?

Yes, as long as you don't need old versions. Back up first and consider keeping a few recent revisions.

How often should I optimize my database?

Monthly for small sites and weekly for busy sites or stores, ideally with automatic scheduled cleanup.

Does WP Rocket optimize the database?

Yes. Its Database tab cleans revisions, drafts, trash, spam and transients, optimizes tables and can run automatically.