Removing revisions in wordpress database

1. Check the revisions you have in the WordPress database.

SELECT id FROM wp_posts WHERE post_type="revision";
SELECT * FROM wp_postmeta WHERE post_id IN (SELECT id FROM wp_posts WHERE post_type="revision");
SELECT * FROM wp_term_relationships WHERE object_id IN (SELECT id FROM wp_posts WHERE post_type="revision");
SELECT * FROM wp_comments WHERE comment_post_ID IN (SELECT id FROM wp_posts WHERE post_type="revision");

2. Backup your WordPress database. You can do it from the php admin interface, or backup through mysql query yourself if you have direct access to your WordPress database.

3. Run the following queries to delete the revisions.

DELETE FROM wp_posts WHERE post_type="revision";
DELETE FROM wp_postmeta WHERE post_id IN (SELECT id FROM wp_posts WHERE post_type="revision");
DELETE FROM wp_term_relationships WHERE object_id IN (SELECT id FROM wp_posts WHERE post_type="revision");
DELETE FROM wp_comments WHERE comment_post_ID IN (SELECT id FROM wp_posts WHERE post_type="revision");

4. Disable WordPress to auto save revisions when you modify the post. Put this line in the wp-config.php which is in your WordPress root folder.

define('WP_POST_REVISIONS', false);

WordPress database table strucure

Search within Codexpedia

Custom Search

Search the entire web

Custom Search