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

WordPress Database Maintenance: How to Optimize Your Database

Editorial Note: We earn a commission from partner links on WPBeginner. Commissions do not affect our editors' opinions or evaluations. Learn more about Editorial Process.

Over the years, many users have asked us how to remove unwanted data from WordPress databases.

A cluttered WordPress database can slow down your website, leading to frustrated visitors and lost sales. That’s why regular WordPress database maintenance and optimization are so important for optimal website performance.

We’ve helped a lot of different users get started with WordPress and optimize their site’s databases. In our experience, the easiest way to start is by using free database plugins like WP-Optimize. Alternatively, you can use a WordPress maintenance service for this task.

In this article, we will show you how to clean up and optimize your WordPress database.

How to clean up and optimize WordPress database

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.

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. Changes made by a cleanup plugin are irreversible. This way, you can easily restore your site in case something goes wrong.

That said, let’s look at how you can optimize your WordPress database.

How to Optimize and Clean Up Your WordPress Database in One Click

The easiest way to clean up and optimize your WordPress database is by using 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 some space and further optimize your site.

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, fortnightly, or monthly clean-ups.

WP optimize settings

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

Additional Optimization Features in WP-Optimize

There are other additional features offered by WP-Optimize that can also help you optimize your database.

Let’s look at them in detail.

Optimize Your Images

If you go to the ‘Images’ tab or navigate to WP-Optimize » Images from the WordPress admin panel, then you’ll find options to compress images on your site.

Image compression wp optimize

WP-Optimize will also automatically convert JPG and PNG images to the WebP format and serve that version whenever possible.

This can result in significantly smaller files and help optimize WordPress databases.

Converting and serving images in WebP format

You may also want to see our guide on how to easily optimize images without losing quality.

Enable Page Cache

The plugin also offers an option to enable page caching.

This can improve your site’s speed and performance by storing a copy of your content on the server. The server can then simply show that copy to visitors rather than download it from scratch.

Customizing the WordPress cache using WP-Optimize

WP-Optimize also lets you change the cache settings.

You can deliver different content based on user role, device, and whether they’re currently logged in or not.

How to enable caching for your WordPress blog, website, or online store

Minify HTML, CSS, and JavaScript Files

Another way you can clean up and optimize your WordPress database is by enabling minification.

It removes white spaces, lines, and unnecessary characters from the source code. This makes your WordPress CSS and JavaScript files load faster.

You can simply go to the Minify tab in WP-Optimize and then click the ‘Enable Minify’ option.

How to enable minification on your website, blog, or online store

The plugin will automatically handle the minification process, but you can fine-tune the settings and customize which CSS and JavaScript files to exclude.

Alternative to WP-Optimize: If you are looking for an alternative option for cleaning the database, then you can also use the WP-Sweep plugin. It is completely free and uses all the proper WordPress delete functions to clean up the database. However, it lacks the optimization options that you’d get in WP-Optimize.

Bonus: Hire Experts to Optimize Your WordPress Database

If optimizing the WordPress database is too time-consuming or technical for you, consider hiring a WordPress support agency to handle all your WordPress database maintenance needs.

There are many WordPress maintenance services on the market, but we recommend our affordable WordPress Maintenance & Support Services.

We can handle everything related to the basic WordPress database maintenance of your website, including 24/7 uptime monitoring, fixing database errors, optimizing your site for performance, cleaning up the database, and more.

WPBeginner Pro Maintenance Services

We also offer Emergency WordPress Support to quickly and reliably resolve one-time problems on your website, including a bloated database. We can also fix WordPress database connection strings, plugin errors, broken links, and much more.

Besides that, there are more Pro services to choose from. You can get your hacked site repaired, optimize your site for speed, boost organic traffic with SEO optimization, and more.

Just see our complete list of WPBeginner Pro Services for more details.

Helpful Resources for WordPress Database Optimization

Here are more guides and helpful tutorials for making sure your WordPress database works smoothly and without any errors:

We hope this article helped you learn how to clean up and optimize your WordPress database. You may also want to check out our guide on how to create a WordPress disaster recovery plan and how to do WordPress database management with phpMyAdmin.

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.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

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

29 CommentsLeave a Reply

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Jiří Vaněk says

    I use the WP Sweep plugin on all the websites I create, primarily for one reason: revisions. Since I often use Elementor, the website tends to suffer from a large number of revisions. Both WordPress and Elementor create a significant number of these revisions. On a site with many pages and articles, the revisions can grow to absurd numbers. These revisions can then significantly slow down the website. The Sweep plugin has brilliantly solved this problem for me. I use it at regular intervals, and thanks to it, I have peace of mind from revisions and website slowdowns. It’s a great and lightweight plugin that everyone should have.

  3. Sally G. says

    In terms of comments, does Empty Spam and Empty Trash do the same thing as this plug-in? I can certainly see where it would be useful for earlier revisions to a post, etc.

    • WPBeginner Support says

      For sites just starting out it would be the same but as a site grows it can clean up information from comments that were deleted and a few other things :)

      Admin

  4. Ed says

    What a fantastic plugin. Has made such a difference to my website and increased the speed by a lot

  5. Nivesh Gandhi says

    Both are great plug ins. Normally you don’t even need to do backup. But its always good to be on safe side.

  6. Dave says

    WP Sweep – what a plugin. I have a WP site that hadn’t had much love over the past 18 months and somehow had a 1.4Gb DB. Worryingly WP Sweep managed to reduce that to just over 17MB.

    More investigation needed.

  7. Francis says

    Hello , i have a question. Im using godaddy managed wordpress . They have a staging site. Can i use the staging site to clean up database then , push it to live production site after. Will it clean my database. Thanks

  8. Mike Patterson says

    Thank you for the useful information on cleaning WordPress Site. This helps me a lot as my site is getting bulky and take a lot of time to get load.

  9. Ramon says

    Looked promissing but I’m not sure about the result. I had about 2600 revisions.. hoped cleaning them would make a difference but it didn’t, at least not in database size, might even be bigger now .. about 800MB.. What options are there to compact database if cleaning up doesn’t help?

    By the way: looked like wp-sweep locked up a couple of times.. after refesh I noticed that the numbers were decreased and I started again, and again, and again till all revisions where removed. Can’t say I’m excited about wp-sweep but maybe I used it wrong, is that possible?

  10. Ahmed says

    Very nice post!
    Cleaning database is very usefull especially for large ones.
    I have used the Advanced Database Cleaner, it is also very powerful and provides many features such as scheduling the cleaning of database and more…

  11. Chris says

    I really enjoyed this article, the layout, and the links. I really just had to say I appreciate the 50 second video that quickly and easily explained what to do and the lead in of backing up your site with a quick little article to find a backup service. I’m new to WP and blogging but trying to learn fast and after viewing this page I can tell I’m going to be spending a lot of time on your site! Well done and thanks!

  12. Gerard says

    Nice job .. on article and plugin … Are the WP-Sweep commands visible under WP-CLI?

    Ta!

    Gerard.

  13. Anna says

    I had wp optimize on my “to install” list, but after seeing this post I downloaded WP sweep. it’s so easy to use. I usually clean up my spam comments, but I know that I have a lot of revisions on my posts so it’s good to get rid of those!

  14. Bhongo says

    yet another great article. Good job guys, I have never thought about about a database clean-up for my WP sites but now thanks to you, I will be doing a clean-up ASAP.

  15. Nikky says

    We’ve been using Wp-Optimize plugin and it works great with similar options to the plugin mentioned above. What you suggest Wp-Optimize or WP-Sweep ?

  16. KennyTheMap says

    Certainly cleaned up a lot of trash from my main website.
    Like Broken Link Checker it is a really useful plugin.

    A question; I deactivate such plugins until I next need to use them as I gather that can improve performance. Is my assumption correct?

    Thanks, Kenny

    • WPBeginner Support says

      Properly coded plugins will not affect your site’s performance when you are not using them. But there can be plugins that will add additional style sheets or JavaScript even if you are not using them. So it is best to deactivate the plugins you are not using.

      Admin

  17. Marcelo says

    Whoa! I’ll be switching almost right now, unless the author of WP-Optimize upgrade its plugin this week :)

  18. Dave says

    I agree! I have used a bunch of tools for this purpose before, with mostly good results. But this plugin is SO much easier to use, and really did a great job of cleaning.

    Of course, some people won’t heed the clear warning to back up first, but that’s human nature, I suppose. :)

    A super job by Lester Chan, an under-appreciated outstanding coder and contributor to WordPress!

    Dave

  19. Kenneth Adair says

    I deleted the wp-optimize and added the wp-sweep but where does one see what the database size is before and after sweeping?

    • Marcelo says

      That’s the thing with this Sweep plugin. Its author wants things clear, simple, and minimalistic. But I think the UI for such a critical tool like a database cleaning, should be more detailed.
      Also, the lack of a scheduling feature will make it pass unnoticed.

      I think the best approach would be if Ruhani Rabin could upgrade its own and well known plugin to use official, native, WP queries to the cleaning. I will ask him what does he think about it.
      https://github.com/ruhanirabin/WP-Optimize/issues/60

      Lester Chan is a great programmer, but I wouldn’t like to abandon WP-Optimize because of the approach.

      What do you think guys?

      Best regards

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.