Quick answer: You can optimize your WordPress database by backing it up first, then removing post revisions, spam comments, trashed items, expired transients, and unused tables, and optimizing the remaining tables. Use a trusted plugin such as WP-Optimize, limit revisions, and repeat the cleanup every one to three months.
Introduction
Every WordPress site runs on a database holding posts, pages, comments, settings, users, and plugin data. Each visit asks it for information, so a clean database answers quickly and a cluttered one slowly. Optimization is basic maintenance: back up first, clean what is safe to remove, and set limits so clutter does not return.
Why Is My WordPress Database Slow?
The most common cause is post revisions: every save creates a copy, so a post edited twenty times can have twenty revisions. Across dozens of posts, that is thousands of extra rows. Transients are another hidden source of bloat: temporary data a plugin stores to avoid fetching the same information again. When a transient expires it should be deleted, but many stay and pile up.
Spam comments, trashed posts, and tables left by deleted plugins add more weight, as does autoloaded data. WordPress loads some options from wp_options on every page, and a large value there slows every visitor. If your site feels slower than it used to, check the database, or start with our WordPress speed optimization guide.
What Does Optimizing a WordPress Database Actually Do?
Optimizing does not change your content. It removes data WordPress no longer needs, reorganizes the tables that remain, and reduces the work on each visit. A typical cleanup removes old revisions, auto-drafts, trashed items, spam comments, expired transients, orphaned metadata, and unneeded pingbacks, then optimizes each table to reclaim unused space. The result is a smaller database and faster queries, especially on shared hosting. It will not fix a slow theme or unoptimized images on its own, so treat it as one part of a full speed plan — see our complete guide to speeding up WordPress.
Before You Start: Back Up Your Site
Warning: back up your site before cleaning the database. Database cleanup deletes data permanently. A backup is your only way back if you remove the wrong table or a plugin deletes something it still needs. Make a full backup of files and database, check that the file exists with a recent timestamp, and test the cleanup on a staging site first if your host offers one. Run the cleanup when traffic is low, because optimizing a table can briefly lock it.
How to Optimize Your WordPress Database with a Plugin
For most owners, a plugin is the safest way to clean a database. It knows which tables belong to WordPress core and which rows are safe to delete. Two well-known options are WP-Optimize and Advanced Database Cleaner, both from the official WordPress plugin directory.
- Go to Plugins > Add New, search for “WP-Optimize”, install it, and activate it.
- Go to WP-Optimize > Database. You will see cleanup tasks with counts, such as “Clean all post revisions (142)”.
- Tick post revisions, auto-drafts, trashed posts, spam and trashed comments, expired transients, and orphaned post metadata.
- Click Run all selected optimizations and wait for it to finish.
WP-Optimize also has a Tables tab showing each table, its size, and its plugin. Do not delete a table unless you are sure its plugin is gone. Turn on scheduled cleanups under Settings: weekly is enough for most blogs. Use one database plugin only; two can conflict. For other speed tools, see our guide to the best plugins for WordPress performance optimization.

How to Reduce Post Revisions and Autosaves
Limit revisions in wp-config.php, above the line that says “That’s all, stop editing!”:
define('WP_POST_REVISIONS', 5);
This keeps the five most recent revisions per post and deletes older ones as new ones are created. Use 3 if you rarely need old drafts, or 10 if you work with a team. You can also autosave every five minutes instead of every 60 seconds:
define('AUTOSAVE_INTERVAL', 300);
Edit wp-config.php only after a backup, using your hosting file manager or SFTP. A single typing error in that file can lock you out of your site.
What Is Autoload Data and Why Does It Matter?
The wp_options table holds site settings. Options marked “autoload = yes” load into memory on every page request; your site title and timezone are autoloaded, and that is normal. The problem starts when a plugin stores a large log or cached response there, because that data loads even on pages that never use the plugin.
Check the size in phpMyAdmin, in your hosting panel. Select your database and run this query in the SQL tab:
SELECT SUM(LENGTH(option_value)) FROM wp_options WHERE autoload = 'yes';
If the result is over 1 MB, list the largest options:
SELECT option_name, LENGTH(option_value) AS size FROM wp_options WHERE autoload = 'yes' ORDER BY size DESC LIMIT 20;
Replace wp_ with your own table prefix if it differs. A large option from a deleted plugin can be deleted; one from an active plugin should not be. Never change an autoload value yourself unless you know exactly what it does.
How to Clean the Database Manually with phpMyAdmin
Use phpMyAdmin only after a backup, and never run a DELETE query you do not understand.
- Open phpMyAdmin in your hosting panel and select your WordPress database. If you are unsure which one it is, check DB_NAME in wp-config.php.
- Sort tables by Size. The largest are usually wp_posts, wp_postmeta, wp_options, and wp_comments.
- Look for tables you do not recognize, and confirm what each one belongs to before touching it.
- To optimize a table, tick it, choose Optimize table, and click Go. This is the same action a plugin performs.
- Delete spam from Comments > Spam in the dashboard instead of using SQL, because that is safer and easier to undo.
Do not use “Drop” unless you are certain a table is orphaned and you have a backup. Dropping deletes the table completely, with no undo.
Which Tables Grow Fastest, and How Often Should You Clean?
| Table | What it stores | When it grows fast |
|---|---|---|
| wp_posts | Posts, pages, revisions, drafts | Frequent editing |
| wp_postmeta | Custom fields and metadata | Page builders, WooCommerce |
| wp_options | Settings and autoloaded data | Plugins storing logs |
| wp_comments | Comments and metadata | Spam attacks, busy blogs |
Page builders and WooCommerce often have the largest wp_postmeta tables, because every block and variation adds rows. That is normal; do not delete postmeta by hand.
| Site type | Cleanup frequency |
|---|---|
| Personal blog | Every 2 to 3 months |
| Business site, weekly posts | Monthly |
| WooCommerce or membership site | Every 1 to 2 weeks |
| High-traffic blog | Weekly |
If your database grows by several megabytes each month, find the cause: a plugin creating a transient on every visit will keep filling it no matter how often you clean.
Common Mistakes to Avoid
- Cleaning without a backup. Always back up first.
- Deleting tables you do not recognize. Check what they belong to first.
- Deleting all revisions with no limit set. The database will fill up again within weeks.
- Installing two database cleaners. Use one tool and remove the other.
- Expecting cleanup to fix everything. It helps, but it will not fix unoptimized images or an overloaded hosting plan.
FAQ
How often should I optimize my WordPress database?
For most blogs, once a month is enough. Busy WooCommerce sites should clean up every one to two weeks.
Is it safe to delete post revisions?
Yes, once a post is published and you no longer need its earlier drafts. Keep three to five revisions per post so you can still undo recent changes.
Will optimizing the database delete my posts or images?
No. It does not delete published posts, pages, or media files — only revisions, drafts, spam, trashed items, and expired temporary data. Always back up first.
What is the best plugin to optimize a WordPress database?
WP-Optimize and Advanced Database Cleaner are both well-known options from the official WordPress plugin directory. Choose one and use it consistently.
Why is my database still large after cleaning it?
It usually means one table holds real data, such as postmeta from a page builder, WooCommerce orders, or a large autoloaded option. Check the largest tables in phpMyAdmin before deleting anything else.
