# 업그레이드 실패: UniqueViolation: 중복된 키 값이 유니크 제약 조건 "data\_explorer\_queries\_pkey"을 위반했습니다

**URL:** https://meta.discourse.org/t/failed-upgrade-uniqueviolation-duplicate-key-value-violates-unique-constraint-data-explorer-queries-pkey/163667
**Category:** Self-hosting
**Created:** [9월 10, 2020, 7:30오후 UTC](https://meta.discourse.org/t/failed-upgrade-uniqueviolation-duplicate-key-value-violates-unique-constraint-data-explorer-queries-pkey/163667 "2020-09-10T19:30:26Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![omarfilip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omarfilip/32/208019_2.png) [@omarfilip](https://meta.discourse.org/u/omarfilip)
#### Post date: [9월 10, 2020, 7:30오후 UTC](https://meta.discourse.org/t/failed-upgrade-uniqueviolation-duplicate-key-value-violates-unique-constraint-data-explorer-queries-pkey/163667/1 "2020-09-10T19:30:26Z")

</div>

오늘 최신 버전으로 업그레이드하는 동안 실패가 발생했습니다:

```
FAILED
--------------------
Pups::ExecError: cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate' 실행이 실패했으며 반환 값은 #<Process::Status: pid 3194 exit 1>입니다.
실패 위치: /pups/lib/pups/exec_command.rb:112:in `spawn'
파라미터 {"cd"=>"$home", "hook"=>"db_migrate", "cmd"=>["su discourse -c 'bundle exec rake db:migrate'"]}로 실행이 실패했습니다.
590cf0611c566ea6df5f70ffdd2cec2359e84eaea29b7abcde77d56288a46370
**부트스트랩 실패** 이전의 오류 메시지를 확인하려면 위로 스크롤하십시오. 오류가 하나 이상 있을 수 있습니다.

```

로그의 위쪽 부분:

```
Caused by:
PG::UniqueViolation: ERROR: unique constraint "data_explorer_queries_pkey"를 위반하는 중복 키 값
DETAIL: Key (id)=(-10)이(가) 이미 존재합니다.

```

그리고

```
rake aborted!
StandardError: 오류가 발생했으며, 이 마이그레이션 및 그 이후의 모든 마이그레이션이 취소되었습니다:

ERROR: unique constraint "data_explorer_queries_pkey"를 위반하는 중복 키 값
DETAIL: Key (id)=(-10)이(가) 이미 존재합니다.

```

따라서 중복된 `data_explorer_queries_pkey` 키를 제거해야 할 것 같습니다.

어떻게 하면 되나요?

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [9월 10, 2020, 7:34오후 UTC](https://meta.discourse.org/t/failed-upgrade-uniqueviolation-duplicate-key-value-violates-unique-constraint-data-explorer-queries-pkey/163667/2 "2020-09-10T19:34:11Z")

</div>

> [@중복된 데이터 탐색기 키로 인해 재구성이 막힘](https://meta.discourse.org/t/duplicate-data-explorer-key-blocking-rebuild/162375?u=merefield):
>
> Hey all, Rare I ask for help, but I’m puzzled about how to resolve this. Just rebuilt my site and getting this: discourse-data-explorer is already at latest compatible version I, [2020-08-28T17:53:57.578920 #1] INFO -- : \> cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate' 2020-08-28 17:54:07.380 UTC [3060] discourse@discourse ERROR: duplicate key value violates unique constraint "data\_explorer\_queries\_pkey" 2020-08-28 17:54:07.380 UTC [3060] discourse@discourse DETAIL:…

---

<div class="post-metadata">

### Author: ![omarfilip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omarfilip/32/208019_2.png) [@omarfilip](https://meta.discourse.org/u/omarfilip)
#### Post date: [9월 10, 2020, 7:40오후 UTC](https://meta.discourse.org/t/failed-upgrade-uniqueviolation-duplicate-key-value-violates-unique-constraint-data-explorer-queries-pkey/163667/3 "2020-09-10T19:40:58Z")

</div>

감사합니다. 하지만 앱에 접근할 수 없습니다:

```
./launcher enter app
Error response from daemon: Container 694b24a2a235e90456fb0ca770c86ac14bb914ad33ada8a18fc4777a1188d848 is not running
root@gaoa-discourse:/var/discourse#

```

그리고:

```
root@gaoa-discourse:/var/discourse# su - postgres
No passwd entry for user 'postgres'

```

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [9월 10, 2020, 7:57오후 UTC](https://meta.discourse.org/t/failed-upgrade-uniqueviolation-duplicate-key-value-violates-unique-constraint-data-explorer-queries-pkey/163667/4 "2020-09-10T19:57:49Z")

</div>

그럼 컨테이너를 재시작하나요?

`./launcher start app`

그다음에는 이런 명령이 필요합니다:

`./launcher enter app`

그리고:

`su postgres -c 'psql discourse'`

---

<div class="post-metadata">

### Author: ![omarfilip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omarfilip/32/208019_2.png) [@omarfilip](https://meta.discourse.org/u/omarfilip)
#### Post date: [9월 10, 2020, 8:29오후 UTC](https://meta.discourse.org/t/failed-upgrade-uniqueviolation-duplicate-key-value-violates-unique-constraint-data-explorer-queries-pkey/163667/5 "2020-09-10T20:29:08Z")

</div>

감사합니다! 처음 시도했을 때 왜 시작되지 않았는지는 모르겠네요.

중복된 “10” ID가 있는 것 같습니다:

```
4374 | discourse-data-explorer | q:-10 | JSON | {"id":-10,"name":"Inactive Users with no posts","description":"analyze pre-Discourse signups.","sql":"SELECT\
n u.id,\n u.username_lower AS \"username\",\n u.created_at,\n u.last_seen_at\nFROM users u\nWHERE u.active = false\nORDER BY u.id\n","created_by":"-1",
"created_at":null,"group_ids":[],"last_run_at":"2019-10-21T04:03:35.548+00:00"}

4114 | discourse-data-explorer | q:-10 | JSON | {"id":-10,"name":"Inactive Users with no posts","description":"analyze pre-Discourse signups.","sql":"SELECT\
n u.id,\n u.username_lower AS \"username\",\n u.created_at,\n u.last_seen_at\nFROM users u\nWHERE u.active = false\nORDER BY u.id\n","created_by":"-1",
"created_at":null,"last_run_at":"2019-02-27T06:17:48.317+00:00"}

```

그러면 다음을 실행해야 할 것 같습니다:  
~~  
`DELETE from plugin_store_rows WHERE id = 10`~~

아니면 이렇게 해야 하나요:

~~`DELETE from plugin_store_rows WHERE id = -10`~~

궁금한 점이 있습니다 - 위의 명령어로 삭제될 항목은 첫 번째로 찾은 항목 하나인가요, 아니면 두 항목 모두인가요?

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [9월 10, 2020, 8:31오후 UTC](https://meta.discourse.org/t/failed-upgrade-uniqueviolation-duplicate-key-value-violates-unique-constraint-data-explorer-queries-pkey/163667/6 "2020-09-10T20:31:07Z")

</div>

ID 열의 숫자는 `4374`와 `4114`입니다. 가장 큰 숫자의 항목을 삭제하세요.

`DELETE from plugin_store_rows WHERE id = 10`을 실행하지 마세요!! 그렇지 않으면 잘못된 항목이 삭제됩니다!

---

<div class="post-metadata">

### Author: ![omarfilip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omarfilip/32/208019_2.png) [@omarfilip](https://meta.discourse.org/u/omarfilip)
#### Post date: [9월 10, 2020, 8:33오후 UTC](https://meta.discourse.org/t/failed-upgrade-uniqueviolation-duplicate-key-value-violates-unique-constraint-data-explorer-queries-pkey/163667/7 "2020-09-10T20:33:23Z")

</div>

아, 이거 말하는 거야?

`DELETE from plugin_store_rows WHERE id = 4374;`

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [9월 10, 2020, 8:34오후 UTC](https://meta.discourse.org/t/failed-upgrade-uniqueviolation-duplicate-key-value-violates-unique-constraint-data-explorer-queries-pkey/163667/8 "2020-09-10T20:34:57Z")

</div>

네. plsql 쿼리 출력에서 올바른 컬럼 헤더가 표시되어야 하지 않나요?

---

<div class="post-metadata">

### Author: ![omarfilip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omarfilip/32/208019_2.png) [@omarfilip](https://meta.discourse.org/u/omarfilip)
#### Post date: [9월 10, 2020, 8:37오후 UTC](https://meta.discourse.org/t/failed-upgrade-uniqueviolation-duplicate-key-value-violates-unique-constraint-data-explorer-queries-pkey/163667/9 "2020-09-10T20:37:37Z")

</div>

말씀해 주니 그렇군. 출력이 이렇게 나와서 아래로 스크롤했었어:

 ![psql output](https://global.discourse-cdn.com/meta/original/3X/2/6/26d804bed1dec803504b54ce0affb4ac2bb5286b.png)

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [9월 10, 2020, 8:40오후 UTC](https://meta.discourse.org/t/failed-upgrade-uniqueviolation-duplicate-key-value-violates-unique-constraint-data-explorer-queries-pkey/163667/10 "2020-09-10T20:40:36Z")

</div>

네, 그리고 일반적으로 커밋하기 전에 명령을 실행하여 그 영향을 확인해 보세요. 참고:

> **[PostgreSQL - TRANSACTIONS](https://www.tutorialspoint.com/postgresql/postgresql_transactions.htm)**
>
> In PostgreSQL, a transaction is a logical unit of work that uses SQL queries to combine one or more database operations. These operations shows the sequences like INSERT, UPDATE, DELETE, or SELECT.

예를 들어, 한 줄만 삭제하려고 했는데 500줄을 삭제해 버렸다면, 걱정 없이 롤백할 수 있는 기회가 생기는 겁니다.

---

<div class="post-metadata">

### Author: ![omarfilip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omarfilip/32/208019_2.png) [@omarfilip](https://meta.discourse.org/u/omarfilip)
#### Post date: [9월 10, 2020, 9:01오후 UTC](https://meta.discourse.org/t/failed-upgrade-uniqueviolation-duplicate-key-value-violates-unique-constraint-data-explorer-queries-pkey/163667/11 "2020-09-10T21:01:54Z")

</div>

성공! 🎉 @merefield 님, 조언 감사합니다.

제 DELETE 명령어에서 마침표가 빠져 있었습니다. (위에서 수정했습니다.)

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [9월 10, 2020, 9:37오후 UTC](https://meta.discourse.org/t/failed-upgrade-uniqueviolation-duplicate-key-value-violates-unique-constraint-data-explorer-queries-pkey/163667/12 "2020-09-10T21:37:54Z")

</div>

> [@omarfilip](#):
>
> 제 DELETE 명령문에 닫는 세미콜론이 빠져 있었습니다. (위에서 수정했습니다.)

아 네, 그거 매번 저를 당하게 하네요 😉

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [10월 10, 2020, 9:39오후 UTC](https://meta.discourse.org/t/failed-upgrade-uniqueviolation-duplicate-key-value-violates-unique-constraint-data-explorer-queries-pkey/163667/13 "2020-10-10T21:39:20Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
