Deleting WordPress Post Revisions
Saturday, February 25th, 2012To all WordPress bloggers: As a blogger who has used WordPress blogging software for his blogs for several years, I often find that the number of saved post revisions grows quite large in a short time, especially since I’m constantly updating my collection of blog posts. Deleting WordPress post revisions occasionally, becomes necessary to preserve efficient WordPress database operation. While I wish to retain the post revisions for a week or two, those older ones I can certainly do without. Indeed, one sure way to better optimize the WordPress database is to keep only the posts, comments, and other data that you actually need, in order to keep your blog quickly responding to page requests and to shorten the time required for a WordPress database backup to complete.
So, each time I back up my blog databases, I first delete the WordPress post revisions I no longer want. Remember that each time you save a post during editing, a new post revision record is created in the WordPress database. Therefore, if you make many revisions to a document, you’ll create many copies of it saved in the database. If the document is a large one, the amount of storage required for it and its revisions quickly becomes significant. So be sure to periodically delete those WordPress post revisions regularly to help keep your blog running at top speed.
To delete WordPress post revisions, use the following procedure:
- Log into yout MySQL account that hosts your WordPress blog’s database you’re working with.
- Then, execute the following SQL statement in the quotes: “DELETE FROM wp_posts WHERE post_type = “revision”;” Note that this particular SQL statement removes all post revisions. However, you could add timestamp constraints, to, for example, delete only those post revisions that are more than two weeks old.
- You should then see a response from MySQL, telling you how many records were actually deleted from the wp_posts table.
- If you have no further tasks, log out of your MySQL account.
I’ve successfully executed the above procedure for WordPress 2 and WordPress 3 blogs. So I expect that you will experience no problems with it on your WordPress blogs. Indeed, it would be possible to automate this command into a PHP script that you could run with task scheduling software (like UNIX Cron). Good luck.