# Dringend, geüpgraded build mislukt UniqueViolation

**URL:** https://meta.discourse.org/t/urgent-upgraded-build-failed-uniqueviolation/176858
**Category:** Self-hosting
**Created:** [21 januari 2021 om 18:55 UTC](https://meta.discourse.org/t/urgent-upgraded-build-failed-uniqueviolation/176858 "2021-01-21T18:55:14Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![vw\_james](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vw_james/32/206850_2.png) [@vw\_james](https://meta.discourse.org/u/vw_james)
#### Post date: [21 januari 2021 om 18:55 UTC](https://meta.discourse.org/t/urgent-upgraded-build-failed-uniqueviolation/176858/1 "2021-01-21T18:55:14Z")

</div>

I tried to upgrade discourse and got the following message -

```
I, [2021-01-21T18:39:25.045454 #1] INFO -- : > cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate'
2021-01-21 18:39:32.724 UTC [4051] discourse@discourse LOG: duration: 336.116 ms statement: UPDATE users
	SET locale = 'en_GB'
	WHERE locale = 'en'
	
2021-01-21 18:39:33.373 UTC [4051] discourse@discourse ERROR: duplicate key value violates unique constraint "index_users_on_username_lower"
2021-01-21 18:39:33.373 UTC [4051] discourse@discourse DETAIL: Key (username_lower)=(xyz123) already exists.
2021-01-21 18:39:33.373 UTC [4051] discourse@discourse STATEMENT: UPDATE users
	SET locale = 'en'
	WHERE locale = 'en_US'
	
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

```

I tried to do `./launcher enter app` and `su postgres -c 'psql discourse'`, got the following error -

> psql: error: could not connect to server: could not connect to server: No such file or directory  
> Is the server running locally and accepting  
> connections on Unix domain socket “/var/run/postgresql/.s.PGSQL.5432”?

---

<div class="post-metadata">

### Author: ![vw\_james](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vw_james/32/206850_2.png) [@vw\_james](https://meta.discourse.org/u/vw_james)
#### Post date: [21 januari 2021 om 19:09 UTC](https://meta.discourse.org/t/urgent-upgraded-build-failed-uniqueviolation/176858/2 "2021-01-21T19:09:07Z")

</div>

Do you have any idea @merefield ? thanks!

> [@Failed upgrade: UniqueViolation: duplicate key value violates unique constraint "data\_explorer\_queries\_pkey"](https://meta.discourse.org/t/failed-upgrade-uniqueviolation-duplicate-key-value-violates-unique-constraint-data-explorer-queries-pkey/163667/4):
>
> So restart the container? ./launcher start app Then you want something like: ./launcher enter app then: su postgres -c 'psql discourse'

---

<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: [21 januari 2021 om 19:18 UTC](https://meta.discourse.org/t/urgent-upgraded-build-failed-uniqueviolation/176858/3 "2021-01-21T19:18:25Z")

</div>

Hey.

When an upgrade fails the container is left stopped. (Try to connect to your site via browser and you’ll see that’s the case)

So you may have simply not started the latest working container. (Pre-upgrade)

Do that with `./launcher start app` then enter the container and attempt to jump into the DB CLI.

---

<div class="post-metadata">

### Author: ![vw\_james](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vw_james/32/206850_2.png) [@vw\_james](https://meta.discourse.org/u/vw_james)
#### Post date: [21 januari 2021 om 19:23 UTC](https://meta.discourse.org/t/urgent-upgraded-build-failed-uniqueviolation/176858/4 "2021-01-21T19:23:26Z")

</div>

Thanks, I did restart the container, any thought? I tried `./launcher enter app` anything else I can try?

> ubuntu@:/var/discourse$ ./launcher start app  
> WARNING: Docker version 17.05.0-ce deprecated …  
> Nothing to do, your container has already started!

---

<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: [21 januari 2021 om 19:24 UTC](https://meta.discourse.org/t/urgent-upgraded-build-failed-uniqueviolation/176858/5 "2021-01-21T19:24:00Z")

</div>

Did you get an error when entering the container?

---

<div class="post-metadata">

### Author: ![vw\_james](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vw_james/32/206850_2.png) [@vw\_james](https://meta.discourse.org/u/vw_james)
#### Post date: [21 januari 2021 om 19:26 UTC](https://meta.discourse.org/t/urgent-upgraded-build-failed-uniqueviolation/176858/6 "2021-01-21T19:26:53Z")

</div>

No error, but when I did `./launcher logs app` I got the following -

> ok: run: redis: (pid 47) 918s  
> timeout: down: postgres: 1s, normally up, want up  
> ok: run: redis: (pid 47) 925s  
> timeout: down: postgres: 0s, normally up, want up  
> ok: run: redis: (pid 47) 933s  
> ok: run: postgres: (pid 1855) 0s  
> supervisor pid: 1847 unicorn pid: 1857  
> config/unicorn\_launcher: line 71: kill: (1857) - No such process  
> config/unicorn\_launcher: line 15: kill: (1857) - No such process  
> (1847) exiting  
> ok: run: redis: (pid 47) 938s  
> timeout: down: postgres: 0s, normally up, want up  
> ok: run: redis: (pid 47) 945s

---

<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: [21 januari 2021 om 19:31 UTC](https://meta.discourse.org/t/urgent-upgraded-build-failed-uniqueviolation/176858/7 "2021-01-21T19:31:00Z")

</div>

> [@vw\_james](#):
>
> psql: error: could not connect to server: could not connect to server: No such file or directory  
> Is the server running locally and accepting  
> connections on Unix domain socket “/var/run/postgresql/.s.PGSQL.5432”?

What’s the result of `ps -ef | grep postgres`?

---

<div class="post-metadata">

### Author: ![vw\_james](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vw_james/32/206850_2.png) [@vw\_james](https://meta.discourse.org/u/vw_james)
#### Post date: [21 januari 2021 om 19:32 UTC](https://meta.discourse.org/t/urgent-upgraded-build-failed-uniqueviolation/176858/8 "2021-01-21T19:32:45Z")

</div>

> root 38 35 0 19:09 ? 00:00:00 runsv postgres  
> root 46 38 0 19:09 ? 00:00:00 svlogd /var/log/postgres  
> root 2573 2571 0 19:31 ? 00:00:00 sv start postgres  
> root 2575 2497 0 19:31 ? 00:00:00 grep postgres

---

<div class="post-metadata">

### Author: ![vw\_james](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vw_james/32/206850_2.png) [@vw\_james](https://meta.discourse.org/u/vw_james)
#### Post date: [21 januari 2021 om 19:34 UTC](https://meta.discourse.org/t/urgent-upgraded-build-failed-uniqueviolation/176858/9 "2021-01-21T19:34:36Z")

</div>

Should I run it inside the container or just at the linux box?

---

<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: [21 januari 2021 om 19:38 UTC](https://meta.discourse.org/t/urgent-upgraded-build-failed-uniqueviolation/176858/10 "2021-01-21T19:38:02Z")

</div>

Inside. Looks like it’s not running.

You will need to restart it manually I suspect, as postgres user.

---

<div class="post-metadata">

### Author: ![vw\_james](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vw_james/32/206850_2.png) [@vw\_james](https://meta.discourse.org/u/vw_james)
#### Post date: [21 januari 2021 om 19:46 UTC](https://meta.discourse.org/t/urgent-upgraded-build-failed-uniqueviolation/176858/11 "2021-01-21T19:46:18Z")

</div>

Do you know the quick command to restart it?

---

<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: [21 januari 2021 om 19:51 UTC](https://meta.discourse.org/t/urgent-upgraded-build-failed-uniqueviolation/176858/12 "2021-01-21T19:51:18Z")

</div>

~~You could try:~~

~~`su - postgres /usr/lib/postgresql/13/bin/postmaster -D /etc/postgresql/13/main` - replacing the `13` with your current version.~~

~~Which is the command advertised on the process of a healthy install.~~

~~No warranty with that though as I’ve not tested it!~~

No don’t bother doing this, see further down.

---

<div class="post-metadata">

### Author: ![vw\_james](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vw_james/32/206850_2.png) [@vw\_james](https://meta.discourse.org/u/vw_james)
#### Post date: [21 januari 2021 om 19:56 UTC](https://meta.discourse.org/t/urgent-upgraded-build-failed-uniqueviolation/176858/13 "2021-01-21T19:56:08Z")

</div>

thanks. I have version 12, but got the following error -

> su: invalid option – ‘D’  
> Try ‘su --help’ for more information.

---

<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: [21 januari 2021 om 19:57 UTC](https://meta.discourse.org/t/urgent-upgraded-build-failed-uniqueviolation/176858/14 "2021-01-21T19:57:04Z")

</div>

> **[postmaster](https://www.postgresql.org/docs/7.4/app-postmaster.html)**
>
> postmaster postmaster — PostgreSQL database server Synopsis postmaster \[option...\] Description postmaster is a deprecated alias of postgres. See Also postgres …

-D is a legal switch.

Make sure you didn’t include the hyphen outside the code snippet?

---

<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: [21 januari 2021 om 19:59 UTC](https://meta.discourse.org/t/urgent-upgraded-build-failed-uniqueviolation/176858/15 "2021-01-21T19:59:15Z")

</div>

btw, I’m wondering if your version 13 upgrade process failed.

If so you might like to take a look at and potentially post in this Topic: [PostgreSQL 13 update](https://meta.discourse.org/t/postgresql-13-update/172563)

---

<div class="post-metadata">

### Author: ![vw\_james](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vw_james/32/206850_2.png) [@vw\_james](https://meta.discourse.org/u/vw_james)
#### Post date: [21 januari 2021 om 20:01 UTC](https://meta.discourse.org/t/urgent-upgraded-build-failed-uniqueviolation/176858/16 "2021-01-21T20:01:20Z")

</div>

Yeah, I am still on version 12…

---

<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: [21 januari 2021 om 20:09 UTC](https://meta.discourse.org/t/urgent-upgraded-build-failed-uniqueviolation/176858/17 "2021-01-21T20:09:09Z")

</div>

> [@merefield](#):
>
> su - postgres /usr/lib/postgresql/13/bin/postmaster -D /etc/postgresql/13/main

Sorry, looks like this is wrapped and managed by a higher level process.

If I kill mine, it automatically restarts.

try: `sv start postgres`

as root

---

<div class="post-metadata">

### Author: ![vw\_james](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vw_james/32/206850_2.png) [@vw\_james](https://meta.discourse.org/u/vw_james)
#### Post date: [21 januari 2021 om 20:17 UTC](https://meta.discourse.org/t/urgent-upgraded-build-failed-uniqueviolation/176858/18 "2021-01-21T20:17:29Z")

</div>

do you mean run it inside docker container? thanks

---

<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: [21 januari 2021 om 20:21 UTC](https://meta.discourse.org/t/urgent-upgraded-build-failed-uniqueviolation/176858/19 "2021-01-21T20:21:48Z")

</div>

Yes, that’s where the service is running.

Even better do this: `sv restart postgres`

Then check:

`tail /var/log/postgres/current`

Healthy situation is going to look something like:

`2021-01-21 20:21:10.284 UTC [575368] LOG: database system is ready to accept connections` somewhere there.

---

<div class="post-metadata">

### Author: ![vw\_james](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vw_james/32/206850_2.png) [@vw\_james](https://meta.discourse.org/u/vw_james)
#### Post date: [21 januari 2021 om 20:26 UTC](https://meta.discourse.org/t/urgent-upgraded-build-failed-uniqueviolation/176858/20 "2021-01-21T20:26:27Z")

</div>

Here is the error log -

> root@ip–app:/var/www/discourse# cat /var/log/postgresql/postgresql-12-main.log  
> 2021-01-21 18:12:04.965 UTC [623] FATAL: database files are incompatible with server  
> 2021-01-21 18:12:04.965 UTC [623] DETAIL: The data directory was initialized by PostgreSQL version 13, which is not compatible with this version 12.3 (Debian 12.3-1.pgdg100+1).  
> pg\_ctl: could not start server  
> Examine the log output.

[Next page](https://meta.discourse.org/t/urgent-upgraded-build-failed-uniqueviolation/176858.md?page=2)
