Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-20T17:31:09.907Z
Answers.Text: 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! :)
Answers.UserDisplayName: Friksel
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-18T11:41:51.490Z
Answers.Text: As much as I love carlcs' work and plugin - this should be the right answer @bperdue
Answers.UserDisplayName: Max Strebel
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-20T14:36:42.020Z
Answers.LastActivityDate: 2021-07-31T21:26:05.907Z
Answers.LastEditDate: 2021-07-31T21:26:05.907Z
Answers.UserDisplayName: Volker Andres
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-02T04:13:29.847Z
Answers.LastActivityDate: 2017-03-13T01:14:00.203Z
Answers.LastEditDate: 2017-03-13T01:14:00.203Z
Answers.UserDisplayName: Johan Douma
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-23T05:02:55.957Z
Answers.Text: +1 for "backup your database first"
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-23T05:49:46.620Z
Answers.Text: 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!!).
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-23T00:43:59.913Z
Answers.LastActivityDate: 2015-07-23T00:43:59.913Z
Answers.UserDisplayName: Brad Bell
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-30T17:12:19.370Z
Answers.Text: This is NOT a good idea, current version != last added version.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-30T17:34:27.880Z
Answers.Text: 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!
Answers.UserDisplayName: Cole Henley
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-30T14:44:06.800Z
Answers.LastActivityDate: 2015-11-30T14:57:55.177Z
Answers.LastEditDate: 2015-11-30T14:57:55.177Z
Answers.UserDisplayName: Cole Henley
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-23T17:26:54.927Z
Answers.Text: @carlcs to the rescue, as always. :)
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-18T11:42:27.310Z
Answers.Text: While this Plugin is great, please also note there seems to be a native way now -> https://craftcms.stackexchange.com/a/35150/6673
Answers.UserDisplayName: Max Strebel
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-23T07:59:47.820Z
Answers.LastActivityDate: 2015-07-23T07:59:47.820Z
Answers.UserDisplayName: carlcs
Body: <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>
  
Tags: <entries><entry-versions>
Title: Delete all old versions from the database
ThreadText: # 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/username_7/craft-deleteallentryversions)
  
  > **Comments:**
  > **username_5**: @username_7 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 username_7' work and plugin - this should be the right answer @username_0  
  
  ---
  
  ### 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!  
  
  ---
  
  