# "EXCEPTION: psql failed: DETAIL: Key (post\_id)=(36946) is duplicated."

**URL:** <https://meta.discourse.org/t/exception-psql-failed-detail-key-post-id-36946-is-duplicated/230356>\
**Category:** Self-hosting\
**Created:** [June 18, 2022, 5:24am UTC](https://meta.discourse.org/t/exception-psql-failed-detail-key-post-id-36946-is-duplicated/230356 "2022-06-18T05:24:27Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![MiG](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mig/32/119486_2.png) [@MiG](https://meta.discourse.org/u/MiG)\
**Post date:** [June 18, 2022, 5:24am UTC](https://meta.discourse.org/t/exception-psql-failed-detail-key-post-id-36946-is-duplicated/230356/1 "2022-06-18T05:24:27Z")

</div>

I’m trying to migrate my server to a new host, so I downloaded a backup file, and uploaded it to the new host. Installed a fresh copy of discourse, and followed the instructions to do so from the command line:

> [@Restore a backup from the command line](https://meta.discourse.org/t/restore-a-backup-from-command-line/108034):
>
> bookmark This guide explains how to restore a Discourse backup from the command line without using the Discourse web UI. person_raising_hand Required user level: Administrator wrench Console access required Here’s how to restore a Discourse backup from the command line, without ever booting the Discourse web UI. This is handy when you’re moving servers. Prerequisites Before you start, make sure you complete the following steps: Download the latest backup file from the source Disco…

Unfortunately, the `discourse restore databasename` fails with:

```plaintext
ALTER TABLE
ALTER TABLE
ALTER TABLE
ERROR: could not create unique index "posts_search_pkey"
DETAIL: Key (post_id)=(36946) is duplicated.
EXCEPTION: psql failed: DETAIL: Key (post_id)=(36946) is duplicated.
/var/www/discourse/lib/backup_restore/database_restorer.rb:92:in `restore_dump'
/var/www/discourse/lib/backup_restore/database_restorer.rb:26:in `restore'
/var/www/discourse/lib/backup_restore/restorer.rb:51:in `run'
script/discourse:149:in `restore'

```

Seems there’s something wrong with the database file? Can someone give me some direction on how I can fix this error? I still have access to the original server, which seems to be running fine.

Is there some sql command or something I can run that will analyze (and fix?) the database before I download a backup?

---

_[View the full topic](https://meta.discourse.org/t/exception-psql-failed-detail-key-post-id-36946-is-duplicated/230356)._
