Error restoring backup "key is duplicated"

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