<p><strong>EDIT:</strong> This is the only answer for Craft 3! All other answers refer to solutions in Craft 2.</p>
<hr />
<p>The question is very old, but maybe in 2020 somebody still finds it. Nowadays you can just <code>./craft utils/prune-revisions</code></p>

CC BY-SA 4.0
2020-04-20T17:31:09.907Z
Hey, thanks a lot for this! I wanted to cleanup the revisions without going into sql every time, so in the end had set the max revisions to a low number to keep the entries low. But then we were missing the revisions. This solution way better! :)
Friksel
CC BY-SA 4.0
2020-11-18T11:41:51.490Z
As much as I love carlcs' work and plugin - this should be the right answer @bperdue
Max Strebel
CC BY-SA 4.0
2020-04-20T14:36:42.020Z
2021-07-31T21:26:05.907Z
2021-07-31T21:26:05.907Z
Volker Andres
<p>I have a site with quite a lot of traffic and user submissions. After a while DB backups started taking too long (uncompressed sql dump over 300mb). </p>

<p>Instead of keeping the last change, I now keep 30 days worth of changes. I have a cron job set up to remove older revisions. </p>

<pre><code>mysql -e 'DELETE FROM craft_entryversions WHERE dateUpdated &lt; DATE_SUB(NOW(),INTERVAL 30 DAY)' dbname
</code></pre>

<p>If you don't need revisions for certain sections, just disable revisions altogether on a per section basis. </p>

<p>I hope this helps other people with large <code>craft_entryversions</code> tables. </p>

CC BY-SA 3.0
2016-11-02T04:13:29.847Z
2017-03-13T01:14:00.203Z
2017-03-13T01:14:00.203Z
Johan Douma
<p>You should be able to just safely delete them from the <code>craft_entryversions</code> table.</p>

<p>Obviously this deletes all your entry versions, so each entry will just exist at its last known 'live' state.</p>

<p>Also, backup your database first. :)</p>

CC BY-SA 3.0
2015-07-23T05:02:55.957Z
+1 for "backup your database first"
Lindsey D
CC BY-SA 3.0
2015-07-23T05:49:46.620Z
There's one problem with this approach. You're also deleting the current versions with this, so you won't be able to revert to them once edits are made and saved. To solve this, open each entry and resave it (something you would better do with a custom plugin!!).
carlcs
CC BY-SA 3.0
2015-07-23T00:43:59.913Z
2015-07-23T00:43:59.913Z
Brad Bell
<p>Just to add to this, you can easily remove previous versions of files (except the current/most recent) with the following SQL query:</p>

<pre><code>DELETE FROM craft_entryversions WHERE id NOT IN (SELECT id FROM (SELECT max(id), entryId FROM craft_entryversions GROUP BY entryId) X);
</code></pre>

<p>Obviously backup the old database/table first!</p>

CC BY-SA 3.0
2015-11-30T17:12:19.370Z
This is NOT a good idea, current version != last added version.
carlcs
CC BY-SA 3.0
2015-11-30T17:34:27.880Z
Obviously a sledgehammer but in pre-launch instances where versioning isn't really being used yet this has proven a good way to clear out a bloated database of entries!
Cole Henley
CC BY-SA 3.0
2015-11-30T14:44:06.800Z
2015-11-30T14:57:55.177Z
2015-11-30T14:57:55.177Z
Cole Henley
<p>I just wrote a plugin that deletes all versions (truncates the <code>craft_entryversions</code> table) and then saves a new version for each of your entries, so you can later revert back to it:</p>

<p><a href="https://github.com/carlcs/craft-deleteallentryversions">Delete All Entry Versions</a></p>

CC BY-SA 3.0
2015-07-23T17:26:54.927Z
@carlcs to the rescue, as always. :)
Brad Bell
CC BY-SA 4.0
2020-11-18T11:42:27.310Z
While this Plugin is great, please also note there seems to be a native way now -> https://craftcms.stackexchange.com/a/35150/6673
Max Strebel
CC BY-SA 3.0
2015-07-23T07:59:47.820Z
2015-07-23T07:59:47.820Z
carlcs
<p>I've been working on a site for a while in beta. The number of versions for all the pages is getting big and the database is now over 2MB. I'd love to just delete all the old versions of all pages when I go live with the site. Is there any easy way to do this?</p>

<entries><entry-versions>
Delete all old versions from the database
# Delete all old versions from the database

(Asked by: username_0 on 2015-07-22)

I've been working on a site for a while in beta. The number of versions for all the pages is getting big and the database is now over 2MB. I'd love to just delete all the old versions of all pages when I go live with the site. Is there any easy way to do this?

**Tags:** entries, entry-versions

---

## 5 answers

### Answer by username_7 on 2015-07-23. Score: 14 | Accepted answer

I just wrote a plugin that deletes all versions (truncates the `craft_entryversions` table) and then saves a new version for each of your entries, so you can later revert back to it:

[Delete All Entry Versions](https://github.com/carlcs/craft-deleteallentryversions)

> **Comments:**
> **username_5**: @carlcs to the rescue, as always. :)  
> **username_3**: While this Plugin is great, please also note there seems to be a native way now -> https://craftcms.stackexchange.com/a/35150/6673  

---

### Answer by username_1 on 2020-04-20. Score: 11

**EDIT:** This is the only answer for Craft 3! All other answers refer to solutions in Craft 2.

---

The question is very old, but maybe in 2020 somebody still finds it. Nowadays you can just `./craft utils/prune-revisions`

> **Comments:**
> **username_2**: Hey, thanks a lot for this! I wanted to cleanup the revisions without going into sql every time, so in the end had set the max revisions to a low number to keep the entries low. But then we were missing the revisions. This solution way better! :)  
> **username_3**: As much as I love carlcs' work and plugin - this should be the right answer @bperdue  

---

### Answer by username_4 on 2016-11-02. Score: 6

I have a site with quite a lot of traffic and user submissions. After a while DB backups started taking too long (uncompressed sql dump over 300mb). 
Instead of keeping the last change, I now keep 30 days worth of changes. I have a cron job set up to remove older revisions. 
mysql -e 'DELETE FROM craft_entryversions WHERE dateUpdated < DATE_SUB(NOW(),INTERVAL 30 DAY)' dbname

If you don't need revisions for certain sections, just disable revisions altogether on a per section basis. 
I hope this helps other people with large craft_entryversions tables.


---

### Answer by username_5 on 2015-07-23. Score: 3

You should be able to just safely delete them from the `craft_entryversions` table.

Obviously this deletes all your entry versions, so each entry will just exist at its last known 'live' state.

Also, backup your database first. :)

> **Comments:**
> **username_6**: +1 for "backup your database first"  
> **username_7**: There's one problem with this approach. You're also deleting the current versions with this, so you won't be able to revert to them once edits are made and saved. To solve this, open each entry and resave it (something you would better do with a custom plugin!!).  

---

### Answer by username_8 on 2015-11-30. Score: 0

Just to add to this, you can easily remove previous versions of files (except the current/most recent) with the following SQL query:
DELETE FROM craft_entryversions WHERE id NOT IN (SELECT id FROM (SELECT max(id), entryId FROM craft_entryversions GROUP BY entryId) X);

Obviously backup the old database/table first!

> **Comments:**
> **username_7**: This is NOT a good idea, current version != last added version.  
> **username_8**: Obviously a sledgehammer but in pre-launch instances where versioning isn't really being used yet this has proven a good way to clear out a bloated database of entries!  

---

