To optimise a WordPress database, back it up, then remove post revisions, auto-drafts, spam and trashed comments, expired transients and leftover tables from deleted plugins, and clean up autoloaded options. Limit future revisions in wp-config.php and schedule a monthly cleanup. On busy sites, add object caching so the database is asked fewer questions in the first place.
- Never optimise a database without a fresh backup.
- Large autoloaded options slow every single page load, including the dashboard.
- Revisions are useful, but a few per post is enough.
- Deleted plugins often leave tables and options behind.
- A clean database helps, but hosting and caching usually matter more for speed.
Why does a WordPress database get slow?
Think of a news blog that has published every weekday for six years. Each article was saved 40 times while editing, a dozen plugins were tried and deleted, and spam comments piled up in the thousands. The database is now several times larger than the actual content, and the dashboard takes seconds to open.
WordPress stores posts, pages, settings, users, comments, WooCommerce orders and plugin data in MySQL or MariaDB tables. Over time it collects clutter that the site never uses but still has to work around.
What can you safely clean from the WordPress database?
| Item | Safe to remove? | Note |
|---|---|---|
| Old post revisions | Yes | Keep a few recent ones per post |
| Auto-drafts and trashed posts | Yes | Check the trash first in case something is needed |
| Spam and trashed comments | Yes | Akismet or a similar filter keeps new spam down |
| Expired transients | Yes | Temporary cache data that should have been deleted |
| Orphaned post meta | Usually | Meta rows whose post no longer exists |
| Tables from deleted plugins | Carefully | Confirm the table prefix belongs to a plugin you removed |
| Large autoloaded options | Review first | Set to not autoload or delete only if the plugin is gone |
How do you optimise the database step by step?
- Back up. Export the database from phpMyAdmin or your host’s backup tool and keep it safe.
- Install a cleanup plugin such as WP-Optimize, or use the database tools built into WP Rocket or LiteSpeed Cache.
- Clean revisions, drafts, spam and transients. These are the safe, quick wins.
- Check autoloaded options. Site Health in WordPress flags when autoloaded options are too large. Find big rows left by old plugins.
- Remove orphaned tables only when you are sure which plugin created them.
- Optimise tables to reclaim space after large deletions.
- Limit revisions by adding
define('WP_POST_REVISIONS', 5);to wp-config.php. - Schedule a monthly cleanup so the clutter never builds up again.
Core Web Vitals fixes, caching, image and database tuning on a staging copy first. Free speed check and a fixed quote.
What else makes database queries faster?
- Object caching with Redis or Memcached keeps the results of common queries in memory. It is the biggest win for WooCommerce and membership sites.
- Find slow queries with Query Monitor. One badly written plugin can run hundreds of queries per page.
- Use a modern database engine. InnoDB tables and an up-to-date MySQL or MariaDB version handle load much better.
- WooCommerce: enable High-Performance Order Storage on stores that support it, so orders live in dedicated tables.
A clean database is one piece of a fast site. The full picture is in how to speed up your WordPress website.
Frequently asked questions
Is it safe to optimise the WordPress database?
Yes, if you take a backup first and stick to safe items such as revisions, spam, drafts and expired transients.
How often should I clean the WordPress database?
Monthly for active sites, and after removing plugins or importing large amounts of content.
Will database optimisation speed up my site?
It helps, especially the dashboard and uncached pages. Hosting, caching and images usually have a bigger effect on front-end speed.
What are autoloaded options?
Settings WordPress loads on every page. If old plugins leave large autoloaded data behind, every request becomes slower.
Should I delete all post revisions?
You can, but keeping a few recent revisions per post is a safer balance between recovery and database size.
Sources
Core Web Vitals fixes, caching, image and database tuning on a staging copy first. Free speed check and a fixed quote.
More WordPress guides
Guide, 4 min readHow to Speed Up Your WordPress Website: Advanced Tips (2026 Guide)
Guide, 3 min readHow to Price Your WordPress Services for Clients (2026 Guide)
Guide, 4 min readHow to Recover a Hacked WordPress Website (2026 Guide)
Guide, 4 min readHow to Secure a WordPress Website from Hackers (2026 Checklist)Rather have an expert run your WordPress site?
Tanvir H is a Bangladesh-based WordPress and Elementor web designer with 7+ years of experience, 650+ projects and a 4.9 client rating. New websites, redesigns, fixes, speed, security and SEO, handled by one expert who explains everything in plain English and works with clients worldwide.



