Deleting WordPress Revisions

WordPress 2.6 introduced a post revisions feature, which automatically saves a draft as you begin to write a post or page and saves a revision for each change made afterwards. That’s right, every time you make even the slightest alteration to a post or page, a new revision is saved. Now don’t get me wrong, this is an incredibly useful feature, especially if you accidentally cut half of your post during a late night edit or lose power while composing your latest masterpiece, but these revisions can slowly build up in your database. If it’s been a few days since you’ve last edited your blog, chances are that you don’t need to keep any revisions around, and they’re probably just siting in your database taking up space and growing cobwebs. To remove all of your revisions safely without harming your published posts and pages, backup your database, then use either […]


WordPress 2.6 introduced a post revisions feature, which automatically saves a draft as you begin to write a post or page and saves a revision for each change made afterwards. That’s right, every time you make even the slightest alteration to a post or page, a new revision is saved. Now don’t get me wrong, this is an incredibly useful feature, especially if you accidentally cut half of your post during a late night edit or lose power while composing your latest masterpiece, but these revisions can slowly build up in your database.

If it’s been a few days since you’ve last edited your blog, chances are that you don’t need to keep any revisions around, and they’re probably just siting in your database taking up space and growing cobwebs. To remove all of your revisions safely without harming your published posts and pages, backup your database, then use either Delete-Revision or Better Delete Revision. If you’re handy with SQL queries, use either phpMyAdmin or the MySQL command line to run the following query (change the table prefix as necessary):

DELETE FROM wp_posts WHERE post_type = "revision"

Update: Thanks to Ozh for pointing out that the above query “just deletes post marked as revisions. If for some reason you associated a revision with a tag or a category that was then removed when the final post was published, you will have extra entries in other tables such as terms.” The proper query to safely remove all of your revisions is as follows (change the table prefix as necessary):

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'

If you want to disable the revision system, add the following line to your wp-config.php file:

define('WP_POST_REVISIONS', false );

If you want to specify the number of revisions that WordPress can save, add the following line to your wp-config.php file (change the number to your desired maximum revision count):

define('WP_POST_REVISIONS', 3);

As the revision system is a form of backup, I recommend periodically deleting revisions as opposed to disabling or limiting it.

I ran the above query on my blog for the first time last night and reduced the database size by almost half! How much did you save?


Leave a Reply

Your email address will not be published. Required fields are marked *