Delete wordpress post revisions to reduce the db size

When you edit wordpress posts it automatically creates revision of the post. This is useful if you wanted to rollback to a previous version of the post.

But a problem with this is it creates a record in database each time. This means it increases your database size. This won’t be a much issue for a small site with few posts. But when you have more posts and if you edit posts very often it will affect a lot for your site in the long run. Sometimes this will increase your site loading time and make the site to perform slowly.

Best thing is to delete the revisions often. You can do this by running a simple mysql query. This is the query for it,

DELETE a,b,c
FROM wp_posts a
LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)
LEFT JOIN wp_postmeta c ON (a.ID = c.post_id)
WHERE a.post_type = 'revision'

This will delete all the revisions as well as the post meta and term relationship records related to them.

If you wish to turn off creating revisions add following code to wp-config.php

define('WP_POST_REVISIONS', false );

Instead turn off revisions if you wish to limit the number of revision created per post, add following code to wp-config.php

define('WP_POST_REVISIONS', 3);

You can modify the number 3 to any number you like. WordPress will keep only that amount of revisions per a post.

If you are not familiar with sql and php there are many plugins that you can use to manage revisions. Here is a better one.

Delete Post Revisions by Donal MacArthur

Enjoyed this article? Share with friends


Subscribe to our email feed and never miss a post

Join Us