Error (could not create unique index "badges_pkey") attempting to restore backup


(Andrew Rambaut) #1

Hi,

I have attempted to restore a backup to a clean rebuild of discourse.

./launcher enter app

discourse enable_restore

discourse restore my_backup.tar.gz

It starts restoring the dump file and the quits with the error:

ERROR:  could not create unique index "badges_pkey"
DETAIL:  Key (id)=(37) is duplicated.

The backup was made with Discourse v1.8.0beta10 and I tried reverting to this version before restoring but it gave the same error.

I also tried a slightly older backup and that gave the same error so it isn’t just a single corrupt backup file.

Any ideas? Thanks.


Error restoring backup "key is duplicated"
(Jay Pfaffman) #2

@zogstrip, could this be related to this similar error with a duplicate key?


(Andrew Rambaut) #3

Thanks for the reply. I saw that thread. The actual error and the detail here is a bit different but I guess it may have a similar root cause (corrupted .sql file?). I have had a look at the .sql file and can’t see anything obviously corrupted but I am not too sure what I am looking for.


(Andrew Rambaut) #4

I just did a fresh backup, and tried to restore it immediately. This was the result:

.
.
.
1
(1 row)
COPY 0
setval
--------
1
(1 row)
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ERROR:  could not create unique index "badges_pkey"
DETAIL:  Key (id)=(31) is duplicated.
ERROR:  current transaction is aborted, commands ignored until end of transaction block

I guess this means there is something corrupt in my current database that is causing problems with the SQL dump file?


(Andrew Rambaut) #5

I managed to restore the database using the instructions here:

I am not sure why the discourse restore didn’t work.