A great feature of WordPress is its ability to save different versions of your posts as you go -- such as when you hit the "save draft" or "preview" buttons. These saved versions are called "revisions," and they give you restore points if anything goes wrong.
Awesome, right? Well, it can be. But WordPress revisions have to be saved to your database just like your current post drafts do. And because WordPress can end up saving a dozen or more revisions for a post, your database might be much larger than you think. So for this week's quick tip, let's look some ways you can fix and prevent this problem.
Who Cares if the WordPress Database Gets Too Big?
A WordPress database that's unnecessarily large can cause several problems.
- Backups take up more space (especially if you like to save several backups at any given time instead of just the latest).
- Importing large databases can cause problems with the setup of some hosting accounts.
- Your site can run more slowly when you have a large database.
- A large WordPress database could cause you to exceed limits placed by your host (such as CPU or memory limits). This is a bigger problem with shared hosts where they often advertise "unlimited" services without being transparent about their true resource limits (they all have them).
What Can You do About a Large WordPress Database?
One way you can deal with this issue is to prevent WordPress from saving an unruly number of revisions in the first place. To do that, you'll need to open your wp-config.php file. You can find it in the top level of your WordPress installation on your server.
Prevent WordPress From Saving Too Many Revisions
You'll want to add the following line to limit your number of revisions per post (changing "5" to whatever number you want -- I recommend at least four).
define( 'WP_POST_REVISIONS', 5 );
If you aren't worried about keeping revisions for whatever reason, you can turn them off entirely by adding this to wp-config.php instead:
define( 'WP_POST_REVISIONS', false );
Add either of these right above the line that says "That's all, stop editing! Happy blogging."
You can learn more about controlling future post revisions in the WordPress Codex.
Remove Existing Revisions From Your WordPress Database
Those solutions are great if you have a new WordPress installation or if you want to limit revisions in the future. But what if you already have hundreds (or thousands) of posts, with a lot of revisions saved for each, in your database?
That's where plugins come in handy. Specifically, I use one called Thin Out Revisions. This allows you to remove old revisions that you no longer need. For example, you can have it remove any revisions older than 30, 60, or 90 days (assuming if you haven't needed to restore in that time period, you probably never will, or could from a backup). You can even have this automatically run so it clears out revisions on a regular basis.
Another option is to have the plugin delete all revisions when you first publish a post. That can come in handy if you write directly in WordPress (which I don't recommend, but which I'm also still guilty of from time to time). Writing in WordPress can lead to a lot of auto-saves with unfinished content as you use the preview feature, so it makes sense to delete them once you have a version ready for publication.
When was the last time you thinned unnecessary post revisions from your database? Give it a try if you're worried that your database might be bloated. But of course, back up your original first just to be safe.
Do you use other tools for managing WordPress revisions? Tell us about them in the comments.