# Can't rebuild due to failed postgres 12 upgrade

**URL:** https://meta.discourse.org/t/cant-rebuild-due-to-failed-postgres-12-upgrade/157428
**Category:** Self-hosting
**Created:** [11 juli 2020 om 01:43 UTC](https://meta.discourse.org/t/cant-rebuild-due-to-failed-postgres-12-upgrade/157428 "2020-07-11T01:43:47Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![Benjamin\_D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/benjamin_d/32/277831_2.png) [@Benjamin\_D](https://meta.discourse.org/u/Benjamin_D)
#### Post date: [12 juli 2020 om 16:23 UTC](https://meta.discourse.org/t/cant-rebuild-due-to-failed-postgres-12-upgrade/157428/22 "2020-07-12T16:23:38Z")

</div>

Which guide?  
Port 2045 reminds me of something I can’t pin exactly 🤔

---

<div class="post-metadata">

### Author: ![pr0cesor](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@pr0cesor](https://meta.discourse.org/u/pr0cesor)
#### Post date: [12 juli 2020 om 16:29 UTC](https://meta.discourse.org/t/cant-rebuild-due-to-failed-postgres-12-upgrade/157428/23 "2020-07-12T16:29:34Z")

</div>

After few failure installation few months back I changed it to 2045, but this is not relevant since it’s commented with #. The issue is not with that port.

I followed this guide [discourse/docs/INSTALL-cloud.md at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/master/docs/INSTALL-cloud.md)

---

<div class="post-metadata">

### Author: ![Benjamin\_D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/benjamin_d/32/277831_2.png) [@Benjamin\_D](https://meta.discourse.org/u/Benjamin_D)
#### Post date: [12 juli 2020 om 16:34 UTC](https://meta.discourse.org/t/cant-rebuild-due-to-failed-postgres-12-upgrade/157428/24 "2020-07-12T16:34:39Z")

</div>

> [@pr0cesor](#):
>
> The app.yml file comes from templates and what never touched the lines that you are suggesting me so I don’t understand how it could be bad

Well… It was changed, slippery fingers happen 😅

---

<div class="post-metadata">

### Author: ![Benjamin\_D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/benjamin_d/32/277831_2.png) [@Benjamin\_D](https://meta.discourse.org/u/Benjamin_D)
#### Post date: [12 juli 2020 om 16:41 UTC](https://meta.discourse.org/t/cant-rebuild-due-to-failed-postgres-12-upgrade/157428/25 "2020-07-12T16:41:52Z")

</div>

I understand, but to come up with 2045 at some point you might have followed something which led you here and now.  
I think i followed the same post because i too have a 2045 proxy in my nginx conf for some reason that i can’t remember…

[![](https://global.discourse-cdn.com/meta/original/3X/f/0/f02dd637ca349a2e4f502cc4077644dbd5905220.jpeg "Fantasia Sorcerer's Apprentice") ](https://www.youtube.com/watch?v=3hKgEylk8ks)

🤪

---

<div class="post-metadata">

### Author: ![pr0cesor](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@pr0cesor](https://meta.discourse.org/u/pr0cesor)
#### Post date: [12 juli 2020 om 16:49 UTC](https://meta.discourse.org/t/cant-rebuild-due-to-failed-postgres-12-upgrade/157428/26 "2020-07-12T16:49:52Z")

</div>

@Benjamin_D there is no 2045 port in my nginx file, you can take a look at it by scrolling up. That line in app.yml is commented by #, so I dont understand why are you guys pointing fingers at it. The issue does not come from there thats for sure, otherwise the error message would point it out.

I can remove that line from the app.yml file if you want, the result would be the same as before.

I think at the time I have installed it for the first time, the container said that the port 80 or 443 are being used so I might read somewhere to just add random port on it but again that line is commented with #, which should not take into account..

---

<div class="post-metadata">

### Author: ![Benjamin\_D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/benjamin_d/32/277831_2.png) [@Benjamin\_D](https://meta.discourse.org/u/Benjamin_D)
#### Post date: [12 juli 2020 om 16:53 UTC](https://meta.discourse.org/t/cant-rebuild-due-to-failed-postgres-12-upgrade/157428/27 "2020-07-12T16:53:35Z")

</div>

> [@pr0cesor](#):
>
> can remove that line from the app.yml file if you want, the result would be the same as before

Not at all, we are merely trying to retrace your steps and compare our setup with your

---

<div class="post-metadata">

### Author: ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)
#### Post date: [12 juli 2020 om 16:53 UTC](https://meta.discourse.org/t/cant-rebuild-due-to-failed-postgres-12-upgrade/157428/28 "2020-07-12T16:53:56Z")

</div>

This error is definitely related to a failed postgres upgrade.

Check out the meta topic to get the issue fixed.

> [@PostgreSQL 12 update](https://meta.discourse.org/t/postgresql-12-update/151236):
>
> warning WARNING! If your database is very large, you will need a lot of extra disk space (2x database size) and should be very careful with this upgrade! We just landed the long waited PostgreSQL major version upgrade. Any site admins rebuilding Discourse from the command line will be upgraded to PostgreSQL 12 from the old PostgreSQL 10. We are running this new version for a while on Meta, and everything is working fine. PostgreSQL 12 brings lots of improvements that will be automatical…

---

<div class="post-metadata">

### Author: ![pr0cesor](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@pr0cesor](https://meta.discourse.org/u/pr0cesor)
#### Post date: [12 juli 2020 om 16:57 UTC](https://meta.discourse.org/t/cant-rebuild-due-to-failed-postgres-12-upgrade/157428/29 "2020-07-12T16:57:29Z")

</div>

I will check the postgres upgrade topic. I will came back if I encounter any other error.

---

<div class="post-metadata">

### Author: ![pr0cesor](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@pr0cesor](https://meta.discourse.org/u/pr0cesor)
#### Post date: [13 juli 2020 om 13:36 UTC](https://meta.discourse.org/t/cant-rebuild-due-to-failed-postgres-12-upgrade/157428/30 "2020-07-13T13:36:07Z")

</div>

So after upgrading postgres from 10 to 12, I still have problems after executing the command: ./launcher rebuild app

```
sudo ./launcher rebuild app
fatal: not a git repository (or any of the parent directories): .git
Stopping old container
+ /usr/bin/docker stop -t 60 app
app
cd /pups && git pull && /pups/bin/pups --stdin
Already up to date.
I, [2020-07-13T13:34:21.635079 #1] INFO -- : Loading --stdin
I, [2020-07-13T13:34:21.643465 #1] INFO -- : > locale-gen $LANG && update-locale
I, [2020-07-13T13:34:21.713536 #1] INFO -- : Generating locales (this might take a while)...
Generation complete.

I, [2020-07-13T13:34:21.713917 #1] INFO -- : > mkdir -p /shared/postgres_run
I, [2020-07-13T13:34:21.720693 #1] INFO -- :
I, [2020-07-13T13:34:21.721042 #1] INFO -- : > chown postgres:postgres /shared/postgres_run
I, [2020-07-13T13:34:21.724919 #1] INFO -- :
I, [2020-07-13T13:34:21.725387 #1] INFO -- : > chmod 775 /shared/postgres_run
I, [2020-07-13T13:34:21.728768 #1] INFO -- :
I, [2020-07-13T13:34:21.729117 #1] INFO -- : > rm -fr /var/run/postgresql
I, [2020-07-13T13:34:21.732712 #1] INFO -- :
I, [2020-07-13T13:34:21.733008 #1] INFO -- : > ln -s /shared/postgres_run /var/run/postgresql
I, [2020-07-13T13:34:21.735981 #1] INFO -- :
I, [2020-07-13T13:34:21.736200 #1] INFO -- : > socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1
2020/07/13 13:34:21 socat[27] E connect(6, AF=1 "/shared/postgres_run/.s.PGSQL.5432", 36): No such file or directory
I, [2020-07-13T13:34:21.751266 #1] INFO -- :
I, [2020-07-13T13:34:21.752242 #1] INFO -- : > rm -fr /shared/postgres_run/.s*
I, [2020-07-13T13:34:21.757300 #1] INFO -- :
I, [2020-07-13T13:34:21.757817 #1] INFO -- : > rm -fr /shared/postgres_run/*.pid
I, [2020-07-13T13:34:21.761287 #1] INFO -- :
I, [2020-07-13T13:34:21.761706 #1] INFO -- : > mkdir -p /shared/postgres_run/10-main.pg_stat_tmp
I, [2020-07-13T13:34:21.765114 #1] INFO -- :
I, [2020-07-13T13:34:21.765725 #1] INFO -- : > chown postgres:postgres /shared/postgres_run/10-main.pg_stat_tmp
I, [2020-07-13T13:34:21.770573 #1] INFO -- :
I, [2020-07-13T13:34:21.781057 #1] INFO -- : File > /etc/service/postgres/run chmod: +x chown:
I, [2020-07-13T13:34:21.791681 #1] INFO -- : File > /etc/service/postgres/log/run chmod: +x chown:
I, [2020-07-13T13:34:21.800244 #1] INFO -- : File > /etc/runit/3.d/99-postgres chmod: +x chown:
I, [2020-07-13T13:34:21.808363 #1] INFO -- : File > /root/upgrade_postgres chmod: +x chown:
I, [2020-07-13T13:34:21.809170 #1] INFO -- : > chown -R root /var/lib/postgresql/10/main
chown: cannot access '/var/lib/postgresql/10/main': No such file or directory
I, [2020-07-13T13:34:21.817357 #1] INFO -- :

FAILED
--------------------
Pups::ExecError: chown -R root /var/lib/postgresql/10/main failed with return #<Process::Status: pid 42 exit 1>
Location of failure: /pups/lib/pups/exec_command.rb:112:in `spawn'
exec failed with the params {"cmd"=>["chown -R root /var/lib/postgresql/10/main", "[! -e /shared/postgres_data] && install -d -m 0755 -o postgres -g postgres /shared/postgres_data && sudo -E -u postgres /usr/lib/postgresql/10/bin/initdb -D /shared/postgres_data || exit 0", "chown -R postgres:postgres /shared/postgres_data", "chown -R postgres:postgres /var/run/postgresql"]}
3e7af3d49be0616ae52ee03d6ee0867d25e5db96de40d92c7ec7abeded5d3262
**FAILED TO BOOTSTRAP** please scroll up and look for earlier error messages, there may be more than one.
./discourse-doctor may help diagnose the problem.

```

I don’t get it, I give up… ;/

What means "fatal: not a git repository (or any of the parent directories): .git " ??

Also I get the following

```
sudo ./discourse-setup
The configuration file containers/app.yml already exists!

. . . reconfiguring . . .

Saving old file as app.yml.2020-07-13-153931.bak
Stopping existing container in 5 seconds or Control-C to cancel.
+ /usr/bin/docker stop -t 10 app
app

Found 4GB of memory and 2 physical CPU cores
setting db_shared_buffers = 1024MB
setting UNICORN_WORKERS = 4
containers/app.yml memory parameters updated.

Hostname for your Discourse? [cp2077.eu]:

Checking your domain name . . .
WARNING: Port 443 of computer does not appear to be accessible using hostname: cp2077.eu.
WARNING: Connection to http://cp2077.eu (port 80) also fails.

This suggests that cp2077.eu resolves to some IP address that does not reach thi s
machine where you are installing discourse.

The first thing to do is confirm that cp2077.eu resolves to the IP address of th is server.
You usually do this at the same place you purchased the domain.

If you are sure that the IP address resolves correctly, it could be a firewall i ssue.
A web search for "open ports YOUR CLOUD SERVICE" might help.

This tool is designed only for the most standard installations. If you cannot re solve
the issue above, you will need to edit containers/app.yml yourself and then type

./launcher rebuild app

```

The website is up and running secured using port 443 (SSL), I don’t understand why it says it cannot reach the website. I don’t know what else to do anymore. Please help

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [13 juli 2020 om 14:10 UTC](https://meta.discourse.org/t/cant-rebuild-due-to-failed-postgres-12-upgrade/157428/31 "2020-07-13T14:10:40Z")

</div>

You have a reverse proxy, so you can’t use discourse-setup. Also, you likely need to remove the let’s encrypt template from your config file.

I don’t know what your postgres problem might be.

---

<div class="post-metadata">

### Author: ![pr0cesor](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@pr0cesor](https://meta.discourse.org/u/pr0cesor)
#### Post date: [13 juli 2020 om 14:13 UTC](https://meta.discourse.org/t/cant-rebuild-due-to-failed-postgres-12-upgrade/157428/32 "2020-07-13T14:13:22Z")

</div>

You mean those lines about proxy in my nginx file?

---

<div class="post-metadata">

### Author: ![Benjamin\_D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/benjamin_d/32/277831_2.png) [@Benjamin\_D](https://meta.discourse.org/u/Benjamin_D)
#### Post date: [13 juli 2020 om 14:30 UTC](https://meta.discourse.org/t/cant-rebuild-due-to-failed-postgres-12-upgrade/157428/33 "2020-07-13T14:30:34Z")

</div>

Aren’t you trying to re-install discourse “on top” of a previous install (the one in february), thus the existing app.yml from the screenshot of the first post, and the need to upgrade postgresql from 10 to 12 (which I don’t think you did, considering the error message, well maybe you did on your host but not in your data container, which might not exist anymore, I don’t know the state of your previous install) ?  
Do you have some backup, do you want a fresh install ?

---

<div class="post-metadata">

### Author: ![lucasbasquerotto](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lucasbasquerotto/32/133376_2.png) [@lucasbasquerotto](https://meta.discourse.org/u/lucasbasquerotto)
#### Post date: [13 juli 2020 om 14:39 UTC](https://meta.discourse.org/t/cant-rebuild-due-to-failed-postgres-12-upgrade/157428/34 "2020-07-13T14:39:24Z")

</div>

I think @pfaffman means that because your are using a reverse proxy (nginx), the script `discourse-setup` might not work (I have never run discourse with a reverse proxy, so I don’t know if this is the case). If you define the `app.yml` correctly it should be fine too, without running `discourse-setup`.

> [@pr0cesor](#):
>
> ```plaintext
> I, [2020-07-13T13:34:21.809170 #1] INFO -- : > chown -R root /var/lib/postgresql/10/main
> chown: cannot access '/var/lib/postgresql/10/main': No such file or directory
> 
> ```

This seems like it’s trying to execute this code in a container that doesn’t have postgres 10 (you are probably using the version 12). If this is what you want, and your template is `templates/postgres.template.yml` as defined in your first post, maybe the `discourse_docker` repository in your machine (at `/var/discourse`) is outdated.

Is your installed discourse recent or old? It may fix that problem if you update the repository:

```
cd /var/discourse
git pull

```

and then run the rebuild step.

Also make sure that the discourse container is destroyed and recreated (and not only stopped and started), to not use an old container (I think the discourse rebuild should already do that, but just in case…).

If it doesn’t work and you have a backup, it is advisable to try to install in a fresh new instance as @Benjamin_D said.

---

<div class="post-metadata">

### Author: ![pr0cesor](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@pr0cesor](https://meta.discourse.org/u/pr0cesor)
#### Post date: [13 juli 2020 om 14:59 UTC](https://meta.discourse.org/t/cant-rebuild-due-to-failed-postgres-12-upgrade/157428/35 "2020-07-13T14:59:56Z")

</div>

@Benjamin_D,

I am trying to install discourse for another domain “on top” of my previous install. 2 domains in the same server to be precise. Please forgive my ignorance, in which part of app.yml can I find postgresql? cause I just looked at my app.yml and I don’t see anything related to that.

I do have backups of the old files that I had, I kinda copied some info from my previous install to the new app.yml for the new server.

@lucasbasquerotto

Here also please forgive my ignorance, are you guys referring to this line when you say “proxy” nginx?

```
location / {
        proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock;
        proxy_set_header Host $http_host;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Real-IP $remote_addr;

```

Before I used postgresql 10 but yesterday I have upgraded it to 12.

I would like very much to start a new instance in this case, how can I remove the old ones to make sure that everything will be installed fresh? Thanks a lot

---

<div class="post-metadata">

### Author: ![Benjamin\_D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/benjamin_d/32/277831_2.png) [@Benjamin\_D](https://meta.discourse.org/u/Benjamin_D)
#### Post date: [13 juli 2020 om 15:17 UTC](https://meta.discourse.org/t/cant-rebuild-due-to-failed-postgres-12-upgrade/157428/36 "2020-07-13T15:17:07Z")

</div>

Two discourse instances on the same server, that would be the multisite config, a whole other story 😄  
For know i think it would be best to be sure you have a backup of the first site, have it up and running pg12 upgraded, and then try the multisite adventure for which i’m absolutly not qualified 😅

---

<div class="post-metadata">

### Author: ![pr0cesor](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@pr0cesor](https://meta.discourse.org/u/pr0cesor)
#### Post date: [13 juli 2020 om 15:19 UTC](https://meta.discourse.org/t/cant-rebuild-due-to-failed-postgres-12-upgrade/157428/37 "2020-07-13T15:19:51Z")

</div>

Thanks Benjamin,

I would start fresh, I do have the backup of the first site, however it was a try out and not necessary anymore. I would like to start clean again.

How do I remove the old container and everything so that I can start a new slate?

---

<div class="post-metadata">

### Author: ![lucasbasquerotto](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lucasbasquerotto/32/133376_2.png) [@lucasbasquerotto](https://meta.discourse.org/u/lucasbasquerotto)
#### Post date: [13 juli 2020 om 15:30 UTC](https://meta.discourse.org/t/cant-rebuild-due-to-failed-postgres-12-upgrade/157428/38 "2020-07-13T15:30:46Z")

</div>

**Have you tried to update the `discourse_docker` repository locally (at `/var/discourse`) first? It didn’t work?**

> [@pr0cesor](#):
>
> Here also please forgive my ignorance, are you guys referring to this line when you say “proxy” nginx?

About the reverse proxy, it’s because nginx is in the middle of the requests and routing to the correct services (instead of the service, in this case discourse, exposed directly to the internet), so nginx is acting as a reverse proxy and the ports (80 and 443) exposed to the internet belongs to the nginx service.

---

<div class="post-metadata">

### Author: ![pr0cesor](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@pr0cesor](https://meta.discourse.org/u/pr0cesor)
#### Post date: [13 juli 2020 om 15:39 UTC](https://meta.discourse.org/t/cant-rebuild-due-to-failed-postgres-12-upgrade/157428/39 "2020-07-13T15:39:04Z")

</div>

> [@lucasbasquerotto](#):
>
> About the reverse proxy, it’s because nginx is in the middle of the requests and routing to the correct services (instead of the service, in this case discourse, exposed directly to the internet), so nginx is acting as a reverse proxy and the ports (80 and 443) exposed to the internet belongs to the nginx service

Strangely the discourse setup worked in February in one of my domain, as you noticed Benjamin remember cause I have also been posting stuff related to that while back ago. So I am surprised that people never ran discourse with nginx. To be honest it worked perfectly fine, until yesterday when I tried to install discourse on another domain using the same server.

What exactly should I look for in discourse\_docker? Here is the content of that folder

```
discourse_docker$ ls
bin containers discourse-setup launcher README.md scripts templates
cids discourse-doctor image LICENSE samples shared

```

---

<div class="post-metadata">

### Author: ![lucasbasquerotto](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lucasbasquerotto/32/133376_2.png) [@lucasbasquerotto](https://meta.discourse.org/u/lucasbasquerotto)
#### Post date: [13 juli 2020 om 15:46 UTC](https://meta.discourse.org/t/cant-rebuild-due-to-failed-postgres-12-upgrade/157428/40 "2020-07-13T15:46:43Z")

</div>

Just run `git pull` to update the repository (the `/var/discourse` directory itself is the local repository), as I said in one of the posts above:

> [@lucasbasquerotto](#):
>
> ```plaintext
> cd /var/discourse
> git pull
> 
> ```

and after it run the rebuild command.

There other people that use nginx in front, but it must be much fewer cases than the [standard install](https://meta.discourse.org/t/142537?silent=true) in a dedicated machine for discourse only. I also don’t know if it breaks `discourse-setup`, I’m just guessing based on your results, and given that the error happened when checking DNS and open ports (and having in mind that it is not your discourse container that uses the ports 80 and 443 in the host).

---

<div class="post-metadata">

### Author: ![pr0cesor](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@pr0cesor](https://meta.discourse.org/u/pr0cesor)
#### Post date: [13 juli 2020 om 15:55 UTC](https://meta.discourse.org/t/cant-rebuild-due-to-failed-postgres-12-upgrade/157428/41 "2020-07-13T15:55:32Z")

</div>

Okay, so I went to the folder discourse\_docker as you mentioned Lucas and I copied my app.yml file to the containers of that folder and ran the command ./launcher rebuild app

Something happened without any error and I think it’s working

 ![discourse](https://global.discourse-cdn.com/meta/original/3X/e/2/e2c4f23e3e4ac5f1a73a3641783918700457065b.jpeg)

I don’t want to jinx it yet, I will try to setup the new account now 😃

[Vorige pagina](https://meta.discourse.org/t/cant-rebuild-due-to-failed-postgres-12-upgrade/157428.md?page=1)

[Volgende pagina](https://meta.discourse.org/t/cant-rebuild-due-to-failed-postgres-12-upgrade/157428.md?page=3)
