# Error restoring backup "key is duplicated"

**URL:** https://meta.discourse.org/t/error-restoring-backup-key-is-duplicated/68999
**Category:** Self-hosting
**Created:** [August 29, 2017, 3:40pm UTC](https://meta.discourse.org/t/error-restoring-backup-key-is-duplicated/68999 "2017-08-29T15:40:45Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![appcomq](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/appcomq/32/84767_2.png) [@appcomq](https://meta.discourse.org/u/appcomq)
#### Post date: [August 29, 2017, 3:40pm UTC](https://meta.discourse.org/t/error-restoring-backup-key-is-duplicated/68999/1 "2017-08-29T15:40:45Z")

</div>

😂😂 I…

version is v1.9.0.beta7 +341

```
[2017-08-29 15:27:03] ERROR: could not create unique index "index_topic_users_on_topic_id_and_user_id"
[2017-08-29 15:27:03] DETAIL: Key (topic_id, user_id)=(59700, 11226) is duplicated.
[2017-08-29 15:27:03] ERROR: current transaction is aborted, commands ignored until end of transaction block
[2017-08-29 15:27:03] ERROR: current transaction is aborted, commands ignored until end of transaction block
[2017-08-29 15:27:03] ERROR: current transaction is aborted, commands ignored until end of transaction block
[2017-08-29 15:27:03] ERROR: current transaction is aborted, commands ignored until end of transaction block
....

[2017-08-29 15:27:03] EXCEPTION: psql failed
[2017-08-29 15:27:03] /var/www/discourse/lib/backup_restore/restorer.rb:279:in `restore_dump'
/var/www/discourse/lib/backup_restore/restorer.rb:42:in `run'
/var/www/discourse/lib/backup_restore/backup_restore.rb:163:in `block in start!'
/var/www/discourse/lib/backup_restore/backup_restore.rb:160:in `fork'

...

```

---

<div class="post-metadata">

### Author: ![appcomq](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/appcomq/32/84767_2.png) [@appcomq](https://meta.discourse.org/u/appcomq)
#### Post date: [August 29, 2017, 3:42pm UTC](https://meta.discourse.org/t/error-restoring-backup-key-is-duplicated/68999/2 "2017-08-29T15:42:15Z")

</div>

now, I just have backup tar.gz, my old server has been resintall OS/

Plz help me .😥

---

<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: [August 29, 2017, 5:31pm UTC](https://meta.discourse.org/t/error-restoring-backup-key-is-duplicated/68999/3 "2017-08-29T17:31:30Z")

</div>

I’ve seen a few similar reports like [https://meta.discourse.org/t/error-could-not-create-unique-index-badges-pkey-attempting-to-restore-backup/67726](https://meta.discourse.org/t/error-could-not-create-unique-index-badges-pkey-attempting-to-restore-backup/67726). I suspect that there is a bug somewhere, but no one has shown a way to replicate it.

I think your solution is to do this: [Manually create and restore Discourse backups](https://meta.discourse.org/t/advanced-manual-method-of-manually-creating-and-restoring-discourse-backups/18273).

---

<div class="post-metadata">

### Author: ![appcomq](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/appcomq/32/84767_2.png) [@appcomq](https://meta.discourse.org/u/appcomq)
#### Post date: [August 29, 2017, 11:54pm UTC](https://meta.discourse.org/t/error-restoring-backup-key-is-duplicated/68999/4 "2017-08-29T23:54:23Z")

</div>

😥😥

but the server has reinstll OS, so I lost my forum 50,000 user. 😣😣

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [August 30, 2017, 12:16am UTC](https://meta.discourse.org/t/error-restoring-backup-key-is-duplicated/68999/5 "2017-08-30T00:16:54Z")

</div>

That looks a lot like this one:

> [@Update failed due to primary key sequence error](https://meta.discourse.org/t/update-to-1-9-0-beta5-failed-due-to-primary-key-sequence-error/67852):
>
> I’ve tried to update from Version v1.9.0.beta4 +300 to 1.9.0.beta5 by pulling the latest changes (git pull) and try to rebuild the app (./launcher rebuild app), but the migration failed with the following message: Any fix? I, [2017-08-11T05:43:33.644343 #15] INFO -- : \> cd /var/www/discourse && su dis course -c 'bundle exec rake db:migrate' 2017-08-11 05:43:38.795 UTC [399] discourse@discourse ERROR: duplicate key valu …

---

<div class="post-metadata">

### Author: ![appcomq](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/appcomq/32/84767_2.png) [@appcomq](https://meta.discourse.org/u/appcomq)
#### Post date: [August 30, 2017, 8:22am UTC](https://meta.discourse.org/t/error-restoring-backup-key-is-duplicated/68999/6 "2017-08-30T08:22:38Z")

</div>

```
discourse=> \d topic_users_id_seq
     Sequence "public.topic_users_id_seq"
    Column | Type | Value        
---------------+---------+---------------------
 sequence_name | name | topic_users_id_seq
 last_value | bigint | 2481334
 start_value | bigint | 1
 increment_by | bigint | 1
 max_value | bigint | 9223372036854775807
 min_value | bigint | 1
 cache_value | bigint | 1
 log_cnt | bigint | 0
 is_cycled | boolean | f
 is_called | boolean | f
Owned by: public.topic_users.id

discourse=> select count(id),max(id) from topic_users;
  count | max   
---------+---------
 2467987 | 2481334
(1 row)

```

---

<div class="post-metadata">

### Author: ![appcomq](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/appcomq/32/84767_2.png) [@appcomq](https://meta.discourse.org/u/appcomq)
#### Post date: [August 30, 2017, 8:27am UTC](https://meta.discourse.org/t/error-restoring-backup-key-is-duplicated/68999/7 "2017-08-30T08:27:57Z")

</div>

```
discourse=> select * from topic_users where id=59700;
user_id | topic_id | posted | last_read_post_number | highest_seen_post_number | last_visited_at | first_visited_at | notification_level | notifications_changed_at | notifications_reason_id | total_msecs_viewed | cleared_pinned_at | id | last_emailed_post_number | liked | bookmarked 
---------+----------+--------+-----------------------+--------------------------+----------------------------+----------------------------+--------------------+----------------------------+-------------------------+--------------------+-------------------+-------+--------------------------+-------+------------
       1 | 11091 | t | 1 | 1 | 2017-02-13 12:51:41.857104 | 2017-02-13 12:51:41.857104 | 3 | 2017-02-13 12:51:41.855492 | 1 | 0 | | 59700 | | f | f
(1 row)

```

~

---

<div class="post-metadata">

### Author: ![appcomq](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/appcomq/32/84767_2.png) [@appcomq](https://meta.discourse.org/u/appcomq)
#### Post date: [August 30, 2017, 12:21pm UTC](https://meta.discourse.org/t/error-restoring-backup-key-is-duplicated/68999/8 "2017-08-30T12:21:33Z")

</div>

I have fix this.

vi .sql file, delete all include 59700 and 11226

😂😂😂 everything is fine.

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [August 31, 2017, 4:16pm UTC](https://meta.discourse.org/t/error-restoring-backup-key-is-duplicated/68999/9 "2017-08-31T16:16:36Z")

</div>


