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?


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

| improve this answer | |
  • @carlcs to the rescue, as always. :) – Brad Bell Jul 23 '15 at 17:26

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.

| improve this answer | |

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. :)

| improve this answer | |
  • 2
    +1 for "backup your database first" – Lindsey D Jul 23 '15 at 5:02
  • 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 Jul 23 '15 at 5:49

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

| improve this answer | |
  • 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 Apr 20 at 17:31

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!

| improve this answer | |
  • This is NOT a good idea, current version != last added version. – carlcs Nov 30 '15 at 17:12
  • 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 Nov 30 '15 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.