The WordPress database — rarely thought about until the site slows down for no apparent reason. Yet it's often the real bottleneck, not the PHP code, the server, or the cache.
A wp_posts table with 400,000 rows, 350,000 of which are revisions. A wp_options table weighing 200 MB stuffed with expired transients. Missing indexes turning a simple menu query into a 10-second table scan. We see this every day.
This guide gives you the keys to diagnose, clean, and optimize your WordPress database in 2026 — with tools, metrics, and tested procedures.
Create a free Volade account
Unlock this article's member resources and the full Volade pack.
No credit card · Public checklists stay free.
Why the database slows down
The problem isn't WordPress itself — it's what accumulates over time.
The 5 main sources of bloat
| Cause | Affected table | Impact |
|---|---|---|
| Post revisions | wp_posts | 60-80% useless rows |
| Expired transients | wp_options | Hundreds of KB to hundreds of MB |
| Orphaned meta data | wp_postmeta, wp_usermeta | Rows without parent |
| Spam and trashed comments | wp_comments | Thousands of useless rows |
| Stale scheduled crons | wp_options | Tasks that never run |
Diagnosing your database health
Method 1 — phpMyAdmin (direct access)
- Log into phpMyAdmin (or Adminer)
- Select the WordPress database
- Check the Size column — identify the biggest tables
- Sort by Rows to see the most populated tables
Method 2 — Query Monitor
- Install Query Monitor
- Open the toolbar → Queries by Component tab
- Spot plugins making the most queries
- Filter by
SELECTto find slow queries (over 0.05 s)
Method 3 — MySQL Slow Query Log
In my.cnf or my.ini:
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow-queries.log
long_query_time = 2
Analyze slow queries with mysqldumpslow:
mysqldumpslow -t 10 /var/log/mysql/slow-queries.log
Key metrics to monitor
| Metric | Alert threshold | Action |
|---|---|---|
| Total DB size | > 200 MB | Audit needed |
| Revisions / total posts | > 40% | Revision cleanup |
| Expired transients | > 500 rows | Transient cleanup |
| Average query time | > 0.1 s | Indexing check |
| Postmeta without post parent | > 100 rows | Orphaned meta cleanup |
Cleaning up post revisions
Why it matters
Every edit of a post or page saves a revision. On a site with 10 active authors and 500 posts, you can reach 50,000 revisions in a year. These revisions are stored in wp_posts with the type revision.
Cleanup via WP-CLI (recommended)
# Count revisions
wp db query "SELECT COUNT(*) FROM wp_posts WHERE post_type = 'revision';"
# Delete all revisions
wp db query "DELETE FROM wp_posts WHERE post_type = 'revision';"
# Clean orphaned postmeta
wp db query "DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts p ON pm.post_id = p.ID WHERE p.ID IS NULL;"
Cleanup via WP-Optimize
- Install WP-Optimize
- Go to WP-Optimize → Database Cleanup
- Check Purge all revisions (or keep the last N)
- Run the optimization
- Schedule automatic weekly cleanup
Limiting revisions going forward
Add to wp-config.php:
define('WP_POST_REVISIONS', 5);
This limits revisions to 5 per post. Recommended value: between 3 and 10 depending on editorial activity.
Cleaning up transients
What is a transient
Transients are temporary cached data stored in wp_options. Problem: many expire without being deleted, especially on sites with poorly coded themes or plugins.
Cleanup via WP-CLI
# Count transients
wp transient list --expired --count
# Delete all expired transients
wp transient delete --expired
Cleanup via direct MySQL
DELETE FROM wp_options
WHERE option_name LIKE '%\_transient\_%'
AND option_name NOT LIKE '%\_transient\_timeout\_%'
AND option_value < UNIX_TIMESTAMP();
Automatic cleanup with WP-Optimize
WP-Optimize includes a Clean expired transients option — enable it and schedule it.
MySQL indexing optimization
Why indexes are critical
Without an index, MySQL scans the entire table to find a row. With an index, the search is nearly instant.
Check for missing indexes
Use this snippet in phpMyAdmin or WP-CLI:
SELECT TABLE_NAME, COLUMN_NAME, INDEX_NAME
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = 'your_wordpress_database';
Recommended indexes for WordPress
| Table | Recommended index | Accelerated query |
|---|---|---|
wp_postmeta | (post_id, meta_key) | Post-specific meta queries |
wp_postmeta | (meta_key, meta_value(100)) | Global meta queries |
wp_commentmeta | (comment_id) | Comment joins |
wp_usermeta | (user_id, meta_key) | User meta queries |
wp_options | (option_name) | Get_option — present but sometimes missing |
Adding an index via WP-CLI
wp db query "ALTER TABLE wp_postmeta ADD INDEX post_meta (post_id, meta_key);"
Before/after indexing comparison
| Query | Without index | With index |
|---|---|---|
SELECT * FROM wp_postmeta WHERE post_id = 123 | 0.450 s | 0.002 s |
SELECT * FROM wp_postmeta WHERE meta_key = 'price' | 1.200 s | 0.005 s |
| Posts + meta join | 2.100 s | 0.080 s |
Using WP-Optimize as your central tool
WP-Optimize is our recommended tool for WordPress DB cleanup in 2026.
Key features
| Feature | Description |
|---|---|
| Revision cleanup | Purge or keep last N revisions |
| Transient cleanup | Expired and orphaned transients |
| Comment cleanup | Spam and trash |
| Orphaned meta cleanup | Postmeta, usermeta, commentmeta |
| Table optimization | MySQL OPTIMIZE TABLE command |
| Automatic scheduling | Weekly, daily |
| Dashboard | Savings displayed |
Recommended cleanup schedule
- Daily: expired transients, comment spam
- Weekly: revisions (if limited upstream), table optimization
- Monthly: orphaned meta, DB size audit
WP-Optimize alternatives
| Tool | Type | Price | Specialty |
|---|---|---|---|
| WP-Optimize | Plugin | Free / Premium | Volade recommended — complete and lightweight |
| Advanced Database Cleaner | Plugin | Free / Pro | Focus on revisions and transients |
| WP-Sweep | Plugin | Free | Deep orphaned data cleanup |
| MySQL CLI + custom scripts | Manual | Free | For developers, total control |
Optimization methods comparison
| Criteria | WP-CLI | WP-Optimize | Direct MySQL | Alternative plugin |
|---|---|---|---|---|
| Skill required | Advanced | Beginner | Expert | Beginner |
| Error risk | Low (if precise) | Very low | Medium | Low |
| Automatable | Scriptable | Yes (scheduled) | Scriptable | Yes |
| Execution speed | Fast | Medium | Very fast | Medium |
| Backup before action | Manual | Automatic | Manual | Manual |
| Ideal for | Developers | All profiles | DB admins | Intermediate users |
What we take away
WordPress database optimization isn't a one-time operation — it's a maintenance routine.
Start by diagnosing: total size, number of revisions, expired transients. Query Monitor is your best friend for that.
Take action: WP-Optimize for routine cleanup, WP-CLI for heavy operations, MySQL for advanced indexing.
Automate: a scheduled weekly cleanup beats a big annual purge.
Secure: always back up the database before any cleanup or indexing operation.
:::callout-warning
Never run OPTIMIZE TABLE on an InnoDB database over 1 GB without a maintenance window. The operation locks the table for several minutes — your site will be read-only during that time.
:::
Article updated July 9, 2026. Sources: MySQL documentation, Volade field tests (200+ sites analyzed), WP-Optimize and Query Monitor feedback.
Ready to take action?
Explore the Volade catalog — no account required to get started.
Your feedback matters
Comment on “WordPress Database Optimization 2026: WP-Optimize, slow queries, indexing, revisions cleanup” or rate this article to help the community.
people shared this article