Learn how to optimize WordPress database

Learn how to optimize WordPress database

Before starting the topic , you must know why WordPress Database optimization so necessary. It is very important because of its role in page generation on your site, the way you communicate with your database is very important. The SQL queries used to get and update information in your database should be optimized to do so as quickly as possible. By optimizing both the data in the database and the SQL queries communicating with it, you’ll improve your site load time, Time to First Byte, and overall user experience.

Now you know that database optimization is so much important for every WordPress Website. It is use to make space, take control, clean up and fasting your website.

atabase optimization

Let’s get started to Learn how to optimize your WordPress database


Cleanup WordPress Table wp_commentmeta . You can totally ignore this. If you are using  Akismet or  plugin then both plugins adds lots of junk data which you never used and not gonna use in the future. You could simply delete it without any hesitation.

  • Go to phpMyAdmin
  • Choose your WordPress database
  • Click on Empty link for table wp_commentmeta
  • On Confirm dialog just click OK.


Cleanup all records from wp_postmeta table where meta_key is _edit_lock and _edit_last .

If you are the only blog author for your WordPress website then you can ignore _edit_lock and _edit_last records, as it helps you stop unintentional overriding other author changes on the same post when there are multiple author of your blog.

Just use below SQL query to clean up both _edit_lock and _edit_last. MySQL query

DELETE FROM wp_postmeta WHERE meta_key = "_edit_lock";
DELETE FROM wp_postmeta WHERE meta_key = "_edit_last";

You could also use phpMyAdmin Query editor.


Step-3 Disable Auto Save

By default WordPress save your post every 2 minutes and stores as revisions in Database. It also save latest draft every 30 seconds which has latest copy. If you feel, you don’t need all the revisions of the post then you could simply delete it.

Add below function to your theme’s functions.php file and you are all set. functions.php

function DisableAutoSave() {
add_action( 'wp_print_scripts', 'DisableAutoSave' );

Step-4 Better use plugin WP Sweep to clean up Metadata

WP Sweep. How to Entire Clean Up WordPress Database and How To Reduce WordPress Database Size? Below all steps are the solution.

  • Stored Post Revisions
  • Auto drafts
  • Orphaned post meta
  • Orphaned comment meta
  • Orphaned user meta
  • Deleted comments
  • Unapproved comments
  • Spammed comments
  • Deleted comments
  • Orphan term relationships
  • And much more….

This is the Easiest Way To CleanUP WP Database. Do you have a question on wp sweep vs wp optimize? Well, I would suggest to go with WP Sweep.

Step-5 Please delete unwanted Plugin – I mean it.

This is big one. I absolutely stand behind this. You know,  Disqus,  WooCommerce,  JetPack, WP Post Review Pro and lot more plugins are adding lots of unnecessary records to your Database?

If you used any of above plugins before and not using right now then I would suggest strongly to go over each Database optimization.

Step-6 Empty and drop all unused Database Tables

Here is a simple example. Let’s say you used Easy Digital Download on your site before. In order for it to run, plugin creates 3 Database tables. Now as you may moved over your premium subscription site to another or altogether stopped using EDD then there is no point of keeping those 3 tables in your live site’s Database.


Step-7 After all above steps, Optimize your Database

We are using plugin WP-DBManager for optimizing Database.


Let me explain you some key benefits of Database optimization :

  • Make space: When you edit a post or page on your website, WordPress automatically saves the new revision to the database. If you edit things a few times (and particularly if the post is long), your database soon gets clogged up with old revisions that just sit there, taking up valuable space. Database Optimization removes these unnecessary post revisions, freeing up valuable Megabytes of data and increasing speed and efficiency. It also cleans up your comments table, removing all the spam and un-approved comments that have built up with a single click.
  • Take control: Database Optimization reports on exactly which of your database tables have overhead and wasted space, giving you the insight, control and power to keep your website neat, fast and efficient.
  • Keep it clean: Clean-up on a schedule, keeping a selected number of weeks’ data, according to your specification.

I hope these steps help you boost up your site speed. Eventually fast site will rank high in Google SERP and will attract more visitors.

Back to Top