Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
30 Million+
Websites using our plugins
20+
Years of WordPress experience
3000+
WordPress tutorials
by experts

WordPress Database Maintenance: How to Optimize Your Database

Here at WPBeginner, we regularly optimize our database to make sure our site runs at peak speed. A cluttered database can drag down your performance, and a slow site can hurt your search rankings.

When spam comments and old post revisions pile up, your pages take much longer to load. Fortunately, you don’t need to be a technical expert to fix this.

We will show you two methods to clean up and optimize your WordPress database step-by-step. These are the same simple techniques we recommend to keep websites healthy and fast.

How to clean up and optimize WordPress database

🔖 TL;DR: To clean up a bloated WordPress database, we recommend DB Optimizer, which gives you a 0-to-100 health score and safely removes clutter like old post revisions and spam comments. If you want a free option, then WP-Optimize handles the same database cleanup at no cost. A leaner database mainly speeds up your WordPress admin area and makes your backups smaller and faster to restore, so always back up your site before running any cleanup.

Why Clean Up and Optimize Your WordPress Database?

If you have been using WordPress for a while, then there is probably a lot of useless data in your database, such as post revisions, spam comments, trash, transient options, orphaned metadata, and so on.

Most of this builds up on its own. WordPress saves a post revision every time you update or autosave a post, comments pile up in your spam and trash folders, and expired transients (temporary cached data that WordPress stores and then forgets to clear out) sit around long after they are useful.

Orphaned metadata is another common one. It gets left behind when you remove a plugin, since the plugin’s settings often stay in the database even after the plugin is gone.

Another consideration is autoload size. Autoloaded data is information WordPress loads into memory on every single page request, so a bloated autoload table makes WordPress work harder each time a page loads.

You will feel this most in your admin area, where the dashboard can start to drag.

All of this data increases your WordPress database size, which means your WordPress backups will take more disk space and time to restore.

Removing and cleaning up this unwanted data significantly reduces your WordPress database size. This will lead to faster backups, easier restores, and improved database performance.

Besides that, you can also optimize your WordPress database by compressing images, minifying JavaScript and CSS files, and setting up caching on your site. This will further improve your site’s performance and help deliver a fast user experience to visitors.

Pro Tip: Before cleaning and optimizing your database, we recommend first creating a complete WordPress backup of your site. We use Duplicator to handle ours. Changes made by a cleanup plugin are irreversible. This way, you can easily restore your site in case something goes wrong.

Not sure which method to use? If you want a dedicated maintenance dashboard with a health score and a backup-first cleanup, then go with DB Optimizer (which is also free if you already own Duplicator Pro or Elite). If you want a capable freemium tool that also handles caching and image compression, then choose WP-Optimize.

Let’s take a look at how you can optimize your WordPress database:

Method 1: How to Optimize Your Database with DB Optimizer

Best for: Users who want a dedicated database-maintenance dashboard with a real-time health score and a backup-first cleanup (and anyone already on Duplicator Pro or Elite, who gets it free).

DB Optimizer is a dedicated WordPress database maintenance plugin built by the Duplicator team. It gives you a real-time health score and lets you safely clean up database clutter before it starts affecting your site’s performance.

DB Optimizer is available as a standalone plugin starting at $29/year. It is also included free with Duplicator Pro and Elite plans.

Important Note: The plugin requires WordPress 6.5 or higher and PHP 7.4 or higher. You can check your versions at Tools » Site Health » Info.

The first thing you need to do is install and activate the DB Optimizer plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.

Once activated, go to DB Optimizer » Settings, paste your license key into the License field, and then click the ‘Activate’ button.

Enter Your DB Optimizer License Key

If you have a Duplicator Pro or Elite license, the same key works for DB Optimizer.

After verifying your license, you can click DB Optimizer in your WordPress admin menu.

The dashboard shows your database health score from 0 to 100, with five color-coded progress bars: table overhead, transients, revisions, autoload size, and trash items. Green means healthy, yellow means the area needs attention, and red means cleanup is required.

Viewing DB Optimizer's Database Health Score

If you also have Duplicator installed, DB Optimizer detects it automatically and shows a direct link to create a backup before you start. We recommend taking that backup before running any cleanup, as the changes are not reversible.

Next, click on the ‘Cleanup’ tab to review three categories of removable data: Posts & Pages, Comments, and Transients & Cache. A summary bar shows the total items scheduled for removal and how much disk space you will recover.

Run a Database Cleanup Using DB Optimizer

You can set a retention period before running the cleanup. The default is 7 days, which protects recently created data from being removed. You can also preview the full list of items and deselect anything you want to keep.

When you are ready, click the ‘Clean Selected Items’ button to run the cleanup.

You can clean each category individually or batch process everything at once. DB Optimizer will update your health score and show new database statistics after the cleanup completes.

If any of your database tables show overhead, switch to the ‘Tables’ tab. From here, you can optimize individual tables or click the bulk option to optimize all flagged tables at once.

Optimizing Tables Using DB Optimizer

Method 2: How to Clean Up Your WordPress Database with WP-Optimize

Best for: Users who want a capable freemium option that also handles caching and image compression.

Another popular option for cleaning up your WordPress database is the WP-Optimize plugin.

WP-Optimize is a popular caching and optimization plugin that aims to improve your website’s speed and performance. It can clean your database, compress your images, remove unused image sizes, cache your content, and reduce the size of HTML, CSS, and JavaScript files.

This plugin is built by the same team behind the popular WordPress backup plugin, UpdraftPlus. To learn more, see our detailed WP-Optimize review.

For this tutorial, we will be using the WP-Optimize free version. There is also a premium version that offers more features like scheduling optimization, WP-CLI support, lazy loading, premium support, and more.

The first thing you need to do is install and activate the WP-Optimize plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.

Upon activation, you can go to the WP-Optimize » Database page from the WordPress dashboard. Next, there will be different tasks you can select for optimization and cleanup.

For example, you can optimize database tables, clean all post revisions, clean all auto-draft posts, remove spam and trashed comments, and more.

Clean up and optimize database

After selecting different options, go ahead and click the ‘Run all selected optimizations’ button at the top.

The plugin will now start optimizing your WordPress database and show you the progress.

Next, you can switch to the ‘Tables’ tab in WP-Optimize.

Tables tab in WP-Optimize

The plugin will show different tables that are inactive in the database.

You can remove these tables to free up space, but you should be very careful. Only delete tables if you are sure they belong to a plugin that you have already removed. If you are unsure, it is safer to leave them alone.

Remove inactive tables

Lastly, you can switch to the ‘Settings’ tab and choose how many weeks of data to keep.

There is also an option to enable scheduled clean-ups for your database. You can schedule daily, weekly, every two weeks, or monthly clean-ups.

WP-Optimize settings

That’s all. You have successfully optimized and cleaned up your WordPress database!

Bonus: Other WP-Optimize Features

WP-Optimize also includes image compression, page caching, and file minification to help boost site performance.

Optimize Your Images: WP-Optimize can compress your images and automatically convert them to WebP format to reduce file sizes. See our guide on how to optimize images.

Enable Page Cache: The plugin can cache your pages and serve them to visitors without regenerating from scratch, which speeds up load times. You can customize caching by user role, device, and login status.

Minify HTML, CSS, and JavaScript: WP-Optimize can minify your site’s files by stripping unnecessary whitespace and characters, reducing file sizes and speeding up page loads.

FAQs About WordPress Database Optimization

Cleaning up a database can feel intimidating if you have never done it before. So we have pulled together the questions our readers ask us most often about WordPress database maintenance, with straightforward answers to each one.

Is it safe to optimize my WordPress database?

Yes, optimizing your WordPress database is safe when done properly. However, we always recommend creating a full backup of your website before making any changes to your database.

Use reputable plugins like DB Optimizer or WP-Optimize and avoid manually deleting database entries unless you’re experienced with MySQL. Start with basic optimizations like removing spam comments and post revisions before moving to more advanced techniques.

How often should I optimize my WordPress database?

We recommend optimizing your WordPress database at least once a month for active websites. High-traffic sites or those with frequent content updates may benefit from weekly optimization.

Many database optimization plugins offer scheduling features that can automate this process. The key is consistency. Regular maintenance prevents your database from becoming bloated.

Will database optimization speed up my WordPress site?

Database optimization can help improve your site performance, especially in the WordPress admin area. If your database is very cluttered, cleaning it up can help your dashboard load faster and prevent errors.

However, database optimization is just one factor in site speed. You’ll get the best results when combined with other optimization techniques like caching, image compression, and choosing quality hosting.

What data can I safely remove from my WordPress database?

You can safely remove spam comments, trashed comments, post revisions (keeping 2–3 recent ones), auto-drafts, expired transients, and unused tags.

Most optimization plugins will also clean up pingbacks, trackbacks, and orphaned metadata. Be cautious with plugin data. Only remove data from plugins you’ve uninstalled and no longer use.

Can I optimize my database manually using phpMyAdmin?

Yes. Advanced users can log into phpMyAdmin, select their WordPress database, select all tables, and choose ‘Optimize table’ from the dropdown menu.

However, this only defragments the tables. It won’t delete old revisions or spam comments like DB Optimizer or WP-Optimize will. For safety and a deeper clean, we recommend using a plugin.

Can database optimization break my WordPress site?

While rare, database optimization can cause issues if done incorrectly. This usually happens when important data is accidentally deleted or when working with a corrupted database.

Stick to well-reviewed plugins and avoid deleting data you’re unsure about. If something goes wrong, you can always restore from your backup.

Additional Resources on WordPress Database Optimization

We hope this article helped you learn how to clean up and optimize your WordPress database.

You may also want to see some other guides and helpful tutorials for making sure your WordPress database works smoothly and without any errors:

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

19 CommentsLeave a Reply

  1. I’ve been managing WordPress sites for years, and I can attest to the importance of regular database maintenance.
    One aspect I particularly appreciated was the emphasis on creating a backup before performing any optimizations – this is crucial advice that can save website owners from potential disasters.

    I’ve used WP-Optimize in the past and found it to be an excellent tool, especially for its image compression features.

    But, I’d like to add that for larger sites or those with complex setups, it might be worth considering a more robust solution like WP Rocket, which offers advanced caching and optimization features.

  2. Many people focus on website optimization and forget about the MySQL database. I use an equally great plugin called Sweep, which performs similar optimizations. Recently, we faced a significant slowdown of the website, and no one knew what was causing it. It turned out that the issue was due to revisions, of which there were thousands accumulated on the blog (the blog itself has over 1300 articles). These revisions incredibly slowed down the website. After optimizing the database, the website’s speed returned to its original state. So, optimization really makes a big difference. I just want to point out that it’s really important to make a backup before optimizing the database in case something goes wrong.

    • While not necessary, we strongly recommend it on the off chance something goes wrong or you run into an error. While it is rare for that to happen, it is better to be safe :)

      Admin

  3. Hello! Great article! I have one question. Can I use this plugin simultaneously with autooptimize and wp3 total cache plugins?

  4. How to fix “Optimize InnoDB tables anyway” in WP-Optimize plugin?

    Have any solution to optimize InnoDB tables in WordPress?

  5. Hey guys,

    In this article:

    /plugins/how-to-clean-up-your-wordpress-database-for-improved-performance/

    It is stated:

    “… the main [benefit of wp-sweep over wp-optimize] is that it uses proper WordPress delete functions as much as possible instead of running direct delete MySQL queries. Whereas the WP-Optimize plugin uses direct delete SQL queries which can leave orphaned data left behind. In other words, WP-Sweep is a better coded plugin than WP-Optimize.”

    Quote and closed quote!

    Perhaps you can explain why you have two clearly contradictory articles published on your site at the same time. Edit one, or the other, please!

    An incredibly influential site such as this needs more attentive editorial review.

    Thanks bunches!

    • Hi James,

      We often recommend plugins that do the same thing. If there is a difference, then we also try to highlight it as you have quoted. One great thing about WordPress is that you often have plenty of excellent solutions for a problem.

      Admin

      • It’s clear that actions like removing post revisions will make no difference whatsoever to “database performance”. I think the confusion is caused by some misunderstanding about how relational databases work and specifically about how indexed queries are executed.

        The problem is exacerbated by so many WordPress users being quite certain that optimising their database is required. Given that relations databases and related technologies like Indexed Sequential Access Method (ISAM) on which the internals are based have been around for some 50 years it ought to be well understood.

        The entire point of using a database is to access data in a way that scalable. The time it takes to find an indexed record, for example, a published WordPress post, is not dependent on the size of the database.

        I’d invite the authors of this article to actually test this. Create a WordPress install and create a few thousand revisions of a post. You’ll find it makes zero difference to performance.

        The time it takes to find a post is dependent on the number of seeks it takes. You can work this out like this:

        log(row_count) / log(index_block_length / 3 * 2 / (index_length + data_pointer_length)) + 1

        I can tell you that the number of seeks will not increase between thousands of revisions and tens of thousands. You’ll get an extra seek when you enter the hundred of thousands of rows. But, the odds are it’s in query cache anyway so it won’t matter.

        I know from testing, for no reason at all, that having a post with 200,000 revisions is just as quick to access as one with none.

        • So if my host is saying my sites keep going down because i need to optimise my db, really it’s the number of hits/seeks that my hosting can’t cope with?

    • I can’t speak for the author but thought I would throw some thoughts out there.

      When it comes to loading your site on the front end, WordPress is actually smart enough to ignore previous revisions as it loads individual pages. However, overall database bloat can slow down a site if you have a large site with many pages and posts. Post revisions do add to the overall size of a database but are certainly not the only contributor. That being said… anything that you can do to reduce the size of your database will keep your site running at peak performance.

      I have been using WP Optimize for years both on personal and client sites and can honestly say it does an excellent job at keeping your database clean. I have also noticed speed boosts when installing on older sites with larger databases that haven’t been optimized. With regard to post revisions, It has a great setting that allows you to limit the number of stored revisions. I keep it set at about 10 which is more than enough for post revision backup purposes.

      I believe the premium version of the plugin also lets you schedule optimization cycles without having to manually go in and click the optimize button.

    • Hi Ian Spare,

      Post revisions don’t affect database performance or your site’s page load times. However, they do increase database size. On older websites with lots of content, cleaning up or limiting post revisions can significantly reduce database backup file size. This means you will be to do on-demand backups, restore from backups, or move backup files around a bit faster. It will also save space on your cloud storage service where you save your backups.

      Admin

      • Thanks, I think you’re moving closer to an accurate position now.

        I think we can dismiss size considerations pretty quickly. A MySQL dump of WordPress database is pretty small. It’s highly compressible data as well, I’d suggest as pure text with a midrange compressional level you’d get around 10:1.

        So I suggest this site might have 1000 posts with 10 revisions per post which for some (unlikely) reason are all the same size (in practice, they’ll be smaller you’d think). And we’ll say a post is about 2800 characters in size because that’s around the size of your post here, we’ll add a bit because it’s not going to make a lot of difference and say 3000 chars.

        1000 * 10 * 3000 = 30000000

        or about 28mb which is going to be around 2.8mb in compressed size.

        Which is, in technical terms, diddly squat. A handful of images at best.

        The footprint of an average WordPress post is very often the associated images. They’ll need backing up as well. That footprint will only be trivially impacted by the number of revisions.

        There’s not a realistic chance these backups will fit into, for example, the free cloud storage of 2gb on Dropbox. So, anyone storing backups in the cloud might well have paid for a service which will be delivering unlimited storage (ie the jetpack backup service) or terabytes.

        It’s hardly a realistic concern to be bothered about a couple of mb in size for a backup file. I appreciate there’ll be some who’ll produce a contrived use case where 10k makes a difference which is fine, I’m just saying in general usage, this is nothing.

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.