# Upgrade Issues: Failed Upgrade due to Duplicate Key, Failed Snapshot Restore

**URL:** https://meta.discourse.org/t/upgrade-issues-failed-upgrade-due-to-duplicate-key-failed-snapshot-restore/182714
**Category:** Self-hosting
**Created:** [March 10, 2021, 7:55am UTC](https://meta.discourse.org/t/upgrade-issues-failed-upgrade-due-to-duplicate-key-failed-snapshot-restore/182714 "2021-03-10T07:55:23Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [March 10, 2021, 11:30am UTC](https://meta.discourse.org/t/upgrade-issues-failed-upgrade-due-to-duplicate-key-failed-snapshot-restore/182714/3 "2021-03-10T11:30:17Z")

</div>

I had what u think was a similar case yesterday (see [Help! Upgrade led to complete fail - #8 by Judith](https://meta.discourse.org/t/help-upgrade-led-to-complete-fail/182547/8)). In broad strokes, I think you need to do something like

- rename the postgres\_data \_old back to postgres\_data
- restart he old container
- fix the corrupt index problem by renaming the duplicate users (or perhaps users that are duplicate because they have different capitalization
- build the indexes on the user table to make sure they are all fixed
- change to the postgres 12 template as described in [PostgreSQL 13 update](https://meta.discourse.org/t/postgresql-13-update/172563)
- rebuild to upgrade
- when that works, you can change the template back and finish the upgrade.
- note that you need to update not only the username but also the username\_lower

The one that I fixed yesterday had a duplicate username as old as February 2020, so you likely don’t want to try to fix this by restoring an older database.

To fix it you need to understand how to modify records with the postgres command line , rebuild databases, and deal with complex, but well documented, issues in the postgres 13 upgrade.

If you have a $500 budget you can contact me. My contact info is in my profile.

---

_[View the full topic](https://meta.discourse.org/t/upgrade-issues-failed-upgrade-due-to-duplicate-key-failed-snapshot-restore/182714)._
