A few days ago I reported about the massive amount of comment metadata that Akismet can leave behind in your WordPress database and how to remove them. As good as that is, it’s still possible to further optimize the size of your database by removing post and page revisions.
What will you learn in this post?
I will show you how to:
- check the overall number of revisions stored in your WordPress database
- remove all of these revisions
- remove only some of these revisions
- set up a policy regarding revision management
If you have only a few posts published so far, the easiest way to remove unnecessary post revisions is to install and activate the Revision Control plugin by Dion Hulse.
Once the plugin is activated, go to
When done selecting the options, don’t forget to click on the
Next, go to
Don’t make any changes to the posts themselves, just click on the
This step is necessary so that the number of revisions gets reset to the number you selected in the Revision Control plugin’s options page.
Bulk updating all posts right from
You have to manually open each post for editing and update all of them one by one.
Only then will the extra revisions get removed.
Better Delete Revision
The above approach might work if you have only a few posts. But what if you have already lots of posts published, say a hundred. Opening them all manually would be very time-consuming…
The solution is called Better Delete Revision.
This plugin analyzes your database and lets you remove all the revisions from it by one click of the mouse.
To do so, after installing and activating the plugin, go to
In the plugin’s manager page click on the
When the revision analysis is complete, you will be able to remove all existing revisions by clicking on the
After you delete all the revisions, you will receive a feedback such as this one from the plugin:
As you can see, revisions add up over time. In my case, for 178 posts they added up to 4474 revisions, in other words I was storing more than 25 revisions for each published post — that was a lot of redundant data in my WordPress database.
Once the revisions are removed, go back to
This step is necessary, so that the changes you have just made to your database get translated into the database’s improved performance.
Another way to remove all revisions from your database is to delete them directly using an SQL query. I don’t consider this a good idea, though, because this solution leaves behind all kinds of connected post metadata in the database tables.
If you want to do it anyway, use this code:
DELETE FROM wp_posts WHERE post_type = "revision";
Create a Revision Management Policy
Even if you have a lot of published posts, you can still make use of the Revision Control plugin.
Recall that it enables you to set a revision management policy for posts, pages, forums, topics, and other objects depending on what plugins you use.
You can set everything to
A more hardcore approach is to set your own values for the post autosave and post revision functionalities of WordPress.
To do this, you will have to access and edit the
Add the following lines to wp-config.php just before the stop editing line:
define('AUTOSAVE_INTERVAL', 3600 );
/* the interval is defined in seconds, 3600 seconds = 1 hour */
define('WP_POST_REVISIONS', false );
/* no post revisions will be saved in the database */
/* That's all, stop editing! Happy blogging. */
In my case, removing all redundant revisions from the database was an excellent choice.
My database shrunk from 33.1 megabytes to only 6.6 megabytes, thus 80% of my database was gone just like that.
The combination of removing all Akismet comment metadata and removing all revisions will make your database very lightweight. And I am sure that it will perform much faster afterwards.
Liked this post?
Subscribe to our newsletter to receive early notification of new posts and deals: