WordPress Optimization – Removing Revisions

On this page
  1. Access phpMyAdmin
  2. Log In to the Database
  3. Open the SQL Query Editor
  4. Remove WordPress Revisions
  5. What Does This Query Do?
  6. Benefits of Removing Revisions
  7. Limiting Future Revisions
  8. Alternative Cleanup Methods
  9. Summary

WordPress automatically creates revisions whenever you edit posts, pages, or other content. These revisions act as restore points, allowing you to compare changes and revert to previous versions if necessary.

This feature is particularly useful when multiple people manage website content or when you need to recover an earlier version of an article.

However, on larger websites with frequent content updates, revisions can accumulate quickly and significantly increase the size of the database. Periodically removing old revisions can help reduce database size and improve performance.

Important

This guide is intended for users with basic database administration knowledge.

Before executing any SQL queries:

  • Create a complete database backup.
  • Verify that you have selected the correct database.
  • Test your website after performing any cleanup operations.

Access phpMyAdmin

  1. Log in to the mybox Panel.
  2. Navigate to:
Databases
  1. Click:
phpMyAdmin

A new browser tab will open with the database login page.

Log In to the Database

Use the database credentials assigned to your WordPress website.

If you do not know the credentials, you can find them in the wp-config.php file located in your WordPress installation directory.

Example:

define('DB_NAME', 'database_name');
define('DB_USER', 'database_user');
define('DB_PASSWORD', 'database_password');
define('DB_HOST', 'database_host');

By default, the file is located in:

public_html

Open the SQL Query Editor

After logging in:

  1. Select the WordPress database from the left-hand menu.
  2. Click the:
SQL

tab at the top of the page.

This will open the query editor where you can execute SQL commands.

Remove WordPress Revisions

Enter the following SQL query:

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)
LEFT JOIN wp_term_taxonomy d ON (b.term_taxonomy_id = d.term_taxonomy_id)
WHERE a.post_type = 'revision'
AND d.taxonomy != 'link_category';

Click:

Execute

to run the query.

What Does This Query Do?

The query removes:

  • Revision entries stored in the wp_posts table.
  • Related metadata stored in the wp_postmeta table.
  • Associated taxonomy relationships stored in the wp_term_relationships table.

This helps eliminate unnecessary database records created by WordPress revision history.

Benefits of Removing Revisions

Cleaning old revisions can provide several benefits:

  • Reduced database size.
  • Faster database backups.
  • Improved database query performance.
  • Reduced storage consumption.
  • Easier database maintenance.

These benefits become more noticeable on websites with:

  • Large numbers of posts.
  • Multiple content editors.
  • Frequent content updates.
  • Long operating history.

Limiting Future Revisions

To prevent excessive revision growth in the future, you can limit the number of revisions WordPress stores.

Add the following line to your wp-config.php file:

define('WP_POST_REVISIONS', 10);

This example limits WordPress to storing the 10 most recent revisions for each post.

You can adjust the value as needed.

Alternative Cleanup Methods

If you prefer not to work directly with SQL queries, many WordPress optimization plugins include revision cleanup tools, such as:

  • WP-Optimize
  • Advanced Database Cleaner
  • LiteSpeed Cache
  • WP Rocket

These plugins can safely remove old revisions through the WordPress administration panel.

Summary

WordPress revisions provide a useful version history for content, but they can significantly increase database size over time.

To remove accumulated revisions:

  1. Open phpMyAdmin.
  2. Select your WordPress database.
  3. Open the SQL tab.
  4. Execute the revision cleanup query.

Always create a backup before making database changes and verify that your website functions correctly after the cleanup process is complete.

Didn't find an answer?

Our support team is here for you 24/7 – write to us and we will help you sort it out.