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
| Source | What It Is | Safe to Clean? |
|---|---|---|
| Post revisions | Saved versions of posts and pages | Yes, keep a few recent ones if you like |
| Auto-drafts | Drafts WordPress creates automatically | Yes |
| Trashed posts and comments | Items in the trash | Yes |
| Spam comments | Comments marked as spam | Yes |
| Expired transients | Temporary cached data past its expiry | Yes |
| Orphaned post meta | Metadata for posts that no longer exist | Yes, with a trusted tool |
| Leftover plugin tables and options | Data from plugins you've deleted | Yes, if you're sure the plugin is gone for good |
| Large autoloaded options | Settings loaded on every request | Carefully; see below |
| Logs and analytics tables | Data stored by some plugins | Depends; 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.
Back up
Take a full backup.
Choose what to clean
Revisions, auto-drafts, trash, spam and expired transients are safe starting points.
Run the cleanup
Use your plugin's database tool.
Optimize tables
This reclaims space left by deleted rows.
Schedule it
Set weekly or monthly automatic cleanup so bloat doesn't return.
Step 3: Limit Revisions Going Forward
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
Check which tables are largest in your host's database tool. Common large tables include:
- Post meta: often large on stores and sites using custom fields heavily.
- Options: should usually be small; if it's large, check autoload.
- Comments and comment meta: large on sites with lots of spam history.
- Plugin-specific tables: logs, statistics, redirects or security events.
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
| Option | What It Removes | Our Suggestion |
|---|---|---|
| Revisions | Old saved versions of posts | Clean, after limiting future revisions |
| Auto-drafts | Automatic drafts never published | Clean |
| Trashed posts | Posts in the trash | Clean, after checking the trash |
| Spam comments | Comments marked as spam | Clean |
| Trashed comments | Comments in the trash | Clean |
| Transients | Expired temporary data | Clean |
| Optimize tables | Reclaims unused space | Run occasionally |
| Automatic cleanup | Runs the selected cleanups on a schedule | Weekly 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
Stores have extra database considerations:
- Order data: modern WooCommerce uses dedicated order tables (High-Performance Order Storage), which are faster than storing orders as posts. If your store still uses the older method, migrating can help large stores.
- Sessions and transients: WooCommerce creates customer sessions and many transients. Expired ones should clear regularly.
- Action Scheduler logs: completed scheduled actions can pile up. WooCommerce cleans them over time, but very large tables are worth checking.
- Product meta: stores with many variations build large post meta tables, where object caching helps.
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
| Site Type | Suggested Frequency |
|---|---|
| Small blog or brochure site | Monthly |
| Active blog with many editors | Weekly |
| WooCommerce store | Weekly, plus regular review of large tables |
| Membership or community site | Weekly |
| Any site after removing many plugins | Once, 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.