Home » WordPress

Clean Up Your WordPress Database: Post Revisions

Posted By: Tuesday 8 March 2011 12 Comments

I’ve been using WordPress for a long time and I must say: I LOVE it! Not only I’m using it for my own blog but I’ve used it for clients as well and it has never let me down. It’s easy to work with, you can find millions themes (free and premium ones) and you can extend the standard functionality with plugins so what else do you need? :wink:

If you’re using WordPress for your blog then you must have seen your database size grow over time. I mean all of your posts, pages, categories etc will be stored in the database.  Having a large database size can compromise the loading time of your blog, slowing it down considerably. This is why you need to pay some attention to your WordPress Database as well. You can do this with a couple of small tricks. However before I continue: Make sure to make a backup of your database fist!! You can use a plugin for this: WordPress Database Backup.

Post Revisions:

Ever since WordPress 2.6 we can make use of the so called “Post Revisions”. This function can be useful and allows you to keep track of all the revisions. So every time a draft is saved, this is saved in the database. The next time this same draft is saved, another revised draft will be saved in the database. As mentioned it can be useful as you can return to a previous revision.

This means that you can have up to 20 revisions, off course it depends on how often you save a post. Now imagine having 200 posts which have 20 revisions on their own and imagine the size of those. Now if you want to clean up your WordPress Database and get rid off the Post Revisions, you can either use a plugin which deletes them for you. However if you’re like me and you don’t want to have too much plugins you can execute a simple query inside your database using PHPMyAdmin;

DELETE FROM wp_posts WHERE post_type = "revision";

Post Revision Query

This query will look for post type Revision within wp_posts table and will delete them all.

This can make your database much smaller. I’ve seen cases where this saves 20+ MB’s! So perhaps it might save you a couple of MB’s as well.

Disable Post Revisions:

However this feature doesn’t work for me so I’ve disabled this feature and have added the following code into my wp-config.php file.

define ('WP_POST_REVISIONS', 0);

When you use the line above you actually say that no Post Revisions is allowed except one autosave per post. However you change the 0 (zero) into 3 which means that a maximum of 3 Post Revisions can be saved. Off course you can decide who much revisions you want to save as you don’t need to stick with the 3 revisions as suggested here above. :wink:

So tell me… With how many MB’s did your WordPress database shrinked after deleting the revisions?

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed and I'll deliver the future articles to your feed reader.
Behrad

About Behrad:

I'm 29 years "old", married to Jannie and about to be a daddy! We live happily in Eindhoven, The Netherlands.
In 2006 I started BioTecK.net just to show/share my portfolio. After a while I started to blog about my experiences and stuff I do in my life, my interests; computers & computer related stuff, tips & tricks and basically everything which I want to share.
Read more about me, follow me on Twitter @BioTecK or contact me .

12 Comments so far, be the next one! »

  1. papabear says:

    never thought of that since I still have plenty of space. but now since I know, I might want to clean it too.

    Btw, last time I read about a plugin that can clean the option database. Option referring to plugin options that we set when we installed a new plugin. When the plugins are disabled or removed, the options still remain in the database. That plugin is supposed to look for orphaned options and removed them. May be you can research that now :)

  2. Dana says:

    Thanks for this useful WordPress hacking. I think I will utilize it to limit the revision post number.

    • Behrad says:

      If you haven’t limited your post revisions number, then this should save you a lot of space. Give it a try and let me know how much your database size shrinked.

  3. [...] couple of days ago I wrote a post called Clean Up Your WordPress Database: Post Revisions in which I explained how you could clean up your WordPress database. In this post I’ll get to [...]

  4. Dominic says:

    Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.

  5. Though I do not run one, WP blogs interests me a lot and I’ve always thought about how they manage such huge files and how wisely the owners use space. I can now understand why less is always better for the database size.

  6. Lalit says:

    i am also a big fan of wordpress and install it on my every website whether it is required or not :)

    The insight to variable wp_post_revisions is nice . i shall set it to 3 or 4.

    so like having 20 revisions for single post will slow down the database ? but how , because as i know those wount be selected in any query in database ?

Leave a Reply

All line breaks and paragraphs will be generated automatically.
BioTecK.net is a Gravatar-enabled blog. To get your own avatar, please register at Gravatar.
You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.