When rebuild, Discourse removes PostGreSQL 10 and reinstalls version 9.5

When I try to use ./launcher rebuild app command, it seems the script removes the already installed PostgreSQL v10 and tries to reinstall v9.5 and it blocks the script on queries execution.

./launcher rebuild app
Ensuring launcher is up to date
Fetching origin
Launcher is up-to-date
Stopping old container
+ /usr/bin/docker stop -t 10 app
app
cd /pups && git pull && /pups/bin/pups --stdin
Already up to date.
I, [2020-05-08T10:12:43.767891 #1]  INFO -- : Loading --stdin
I, [2020-05-08T10:12:43.782184 #1]  INFO -- : > apt-get remove -y postgresql-10 postgresql-client-10 postgresql-contrib-10
I, [2020-05-08T10:12:46.569346 #1]  INFO -- : Reading package lists...
Building dependency tree...
Reading state information...
The following packages will be REMOVED:
  postgresql-10 postgresql-client-10
0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
After this operation, 30.6 MB disk space will be freed.
(Reading database ... 42938 files and directories currently installed.)
Removing postgresql-10 (10.12-2.pgdg100+1) ...
invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of stop.
Removing postgresql-client-10 (10.12-2.pgdg100+1) ...
Processing triggers for postgresql-common (213.pgdg100+1) ...
Building PostgreSQL dictionaries from installed myspell/hunspell packages...
Removing obsolete dictionary files:

I, [2020-05-08T10:12:46.570949 #1]  INFO -- : > apt-get update && apt-get install -y postgresql-9.5 postgresql-client-9.5 postgresql-contrib-9.5
debconf: delaying package configuration, since apt-utils is not installed
I, [2020-05-08T10:12:57.347153 #1]  INFO -- : Get:1 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]
Hit:2 http://deb.debian.org/debian buster InRelease
Get:3 http://deb.debian.org/debian buster-updates InRelease [49.3 kB]
Get:4 http://apt.postgresql.org/pub/repos/apt buster-pgdg InRelease [84.4 kB]
Hit:5 https://deb.nodesource.com/node_10.x buster InRelease
Get:6 http://security.debian.org/debian-security buster/updates/main amd64 Packages [197 kB]
Get:7 http://apt.postgresql.org/pub/repos/apt buster-pgdg/main amd64 Packages [168 kB]
Fetched 564 kB in 1s (543 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
Suggested packages:
  postgresql-doc-9.5 libdbd-pg-perl
The following NEW packages will be installed:
  postgresql-9.5 postgresql-client-9.5 postgresql-contrib-9.5
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 5,700 kB of archives.
After this operation, 27.2 MB of additional disk space will be used.
Get:1 http://apt.postgresql.org/pub/repos/apt buster-pgdg/main amd64 postgresql-client-9.5 amd64 9.5.21-2.pgdg100+1 [1,249 kB]
Get:2 http://apt.postgresql.org/pub/repos/apt buster-pgdg/main amd64 postgresql-9.5 amd64 9.5.21-2.pgdg100+1 [3,988 kB]
Get:3 http://apt.postgresql.org/pub/repos/apt buster-pgdg/main amd64 postgresql-contrib-9.5 amd64 9.5.21-2.pgdg100+1 [463 kB]
Fetched 5,700 kB in 0s (30.5 MB/s)
Selecting previously unselected package postgresql-client-9.5.
(Reading database ... 42096 files and directories currently installed.)
Preparing to unpack .../postgresql-client-9.5_9.5.21-2.pgdg100+1_amd64.deb ...
Unpacking postgresql-client-9.5 (9.5.21-2.pgdg100+1) ...
Selecting previously unselected package postgresql-9.5.
Preparing to unpack .../postgresql-9.5_9.5.21-2.pgdg100+1_amd64.deb ...
Unpacking postgresql-9.5 (9.5.21-2.pgdg100+1) ...
Selecting previously unselected package postgresql-contrib-9.5.
Preparing to unpack .../postgresql-contrib-9.5_9.5.21-2.pgdg100+1_amd64.deb ...
Unpacking postgresql-contrib-9.5 (9.5.21-2.pgdg100+1) ...
Setting up postgresql-client-9.5 (9.5.21-2.pgdg100+1) ...
update-alternatives: using /usr/share/postgresql/9.5/man/man1/psql.1.gz to provide /usr/share/man/man1/psql.1.gz (psql.1.gz) in auto mode
Setting up postgresql-9.5 (9.5.21-2.pgdg100+1) ...
Creating new PostgreSQL cluster 9.5/main ...
/usr/lib/postgresql/9.5/bin/initdb -D /var/lib/postgresql/9.5/main --auth-local peer --auth-host md5
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "C.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/9.5/main ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... Etc/UTC
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
creating template1 database in /var/lib/postgresql/9.5/main/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
syncing data to disk ... ok

Success. You can now start the database server using:

    /usr/lib/postgresql/9.5/bin/pg_ctl -D /var/lib/postgresql/9.5/main -l logfile start

Ver Cluster Port Status Owner    Data directory               Log file
9.5 main    5433 down   postgres /var/lib/postgresql/9.5/main /var/log/postgresql/postgresql-9.5-main.log
update-alternatives: using /usr/share/postgresql/9.5/man/man1/postmaster.1.gz to provide /usr/share/man/man1/postmaster.1.gz (postmaster.1.gz) in auto mode
invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of start.
Setting up postgresql-contrib-9.5 (9.5.21-2.pgdg100+1) ...
Processing triggers for postgresql-common (213.pgdg100+1) ...
Building PostgreSQL dictionaries from installed myspell/hunspell packages...
Removing obsolete dictionary files:

I, [2020-05-08T10:12:57.348808 #1]  INFO -- : > mkdir -p /shared/postgres_run
I, [2020-05-08T10:12:57.352684 #1]  INFO -- :
I, [2020-05-08T10:12:57.353381 #1]  INFO -- : > chown postgres:postgres /shared/postgres_run
I, [2020-05-08T10:12:57.357476 #1]  INFO -- :
I, [2020-05-08T10:12:57.358473 #1]  INFO -- : > chmod 775 /shared/postgres_run
I, [2020-05-08T10:12:57.362147 #1]  INFO -- :
I, [2020-05-08T10:12:57.362866 #1]  INFO -- : > rm -fr /var/run/postgresql
I, [2020-05-08T10:12:57.366500 #1]  INFO -- :
I, [2020-05-08T10:12:57.367283 #1]  INFO -- : > ln -s /shared/postgres_run /var/run/postgresql
I, [2020-05-08T10:12:57.370661 #1]  INFO -- :
I, [2020-05-08T10:12:57.371341 #1]  INFO -- : > socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1
2020/05/08 10:12:57 socat[1583] E connect(6, AF=1 "/shared/postgres_run/.s.PGSQL.5432", 36): No such file or directory
I, [2020-05-08T10:12:57.378628 #1]  INFO -- :
I, [2020-05-08T10:12:57.379219 #1]  INFO -- : > rm -fr /shared/postgres_run/.s*
I, [2020-05-08T10:12:57.382871 #1]  INFO -- :
I, [2020-05-08T10:12:57.383391 #1]  INFO -- : > rm -fr /shared/postgres_run/*.pid
I, [2020-05-08T10:12:57.387099 #1]  INFO -- :
I, [2020-05-08T10:12:57.387666 #1]  INFO -- : > mkdir -p /shared/postgres_run/9.5-main.pg_stat_tmp
I, [2020-05-08T10:12:57.390634 #1]  INFO -- :
I, [2020-05-08T10:12:57.391391 #1]  INFO -- : > chown postgres:postgres /shared/postgres_run/9.5-main.pg_stat_tmp
I, [2020-05-08T10:12:57.394278 #1]  INFO -- :
I, [2020-05-08T10:12:57.401477 #1]  INFO -- : File > /etc/service/postgres/run  chmod: +x  chown:
I, [2020-05-08T10:12:57.408202 #1]  INFO -- : File > /etc/runit/3.d/99-postgres  chmod: +x  chown:
I, [2020-05-08T10:12:57.409009 #1]  INFO -- : > chown -R root /var/lib/postgresql/9.5/main
I, [2020-05-08T10:12:57.422867 #1]  INFO -- :
I, [2020-05-08T10:12:57.423930 #1]  INFO -- : > [ ! -e /shared/postgres_data ] && install -d -m 0755 -o postgres -g postgres /shared/postgres_data && sudo -E -u postgres /usr/lib/postgresql/9.5/bin/initdb -D /shared/postgres_data || exit 0
I, [2020-05-08T10:12:57.426672 #1]  INFO -- :
I, [2020-05-08T10:12:57.427242 #1]  INFO -- : > chown -R postgres:postgres /shared/postgres_data
I, [2020-05-08T10:12:57.462928 #1]  INFO -- :
I, [2020-05-08T10:12:57.464158 #1]  INFO -- : > chown -R postgres:postgres /var/run/postgresql
I, [2020-05-08T10:12:57.467828 #1]  INFO -- :
I, [2020-05-08T10:12:57.468624 #1]  INFO -- : Replacing data_directory = '/var/lib/postgresql/9.5/main' with data_directory = '/shared/postgres_data' in /etc/postgresql/9.5/main/postgresql.conf
I, [2020-05-08T10:12:57.469564 #1]  INFO -- : Replacing (?-mix:#?listen_addresses *=.*) with listen_addresses = '*' in /etc/postgresql/9.5/main/postgresql.conf
I, [2020-05-08T10:12:57.470341 #1]  INFO -- : Replacing (?-mix:#?synchronous_commit *=.*) with synchronous_commit = $db_synchronous_commit in /etc/postgresql/9.5/main/postgresql.conf
I, [2020-05-08T10:12:57.471161 #1]  INFO -- : Replacing (?-mix:#?shared_buffers *=.*) with shared_buffers = $db_shared_buffers in /etc/postgresql/9.5/main/postgresql.conf
I, [2020-05-08T10:12:57.471959 #1]  INFO -- : Replacing (?-mix:#?work_mem *=.*) with work_mem = $db_work_mem in /etc/postgresql/9.5/main/postgresql.conf
I, [2020-05-08T10:12:57.472759 #1]  INFO -- : Replacing (?-mix:#?default_text_search_config *=.*) with default_text_search_config = '$db_default_text_search_config' in /etc/postgresql/9.5/main/postgresql.conf
I, [2020-05-08T10:12:57.473527 #1]  INFO -- : > install -d -m 0755 -o postgres -g postgres /shared/postgres_backup
I, [2020-05-08T10:12:57.477638 #1]  INFO -- :
I, [2020-05-08T10:12:57.478527 #1]  INFO -- : Replacing (?-mix:#?max_wal_senders *=.*) with max_wal_senders = $db_max_wal_senders in /etc/postgresql/9.5/main/postgresql.conf
I, [2020-05-08T10:12:57.479383 #1]  INFO -- : Replacing (?-mix:#?wal_level *=.*) with wal_level = $db_wal_level in /etc/postgresql/9.5/main/postgresql.conf
I, [2020-05-08T10:12:57.480297 #1]  INFO -- : Replacing (?-mix:#?checkpoint_segments *=.*) with checkpoint_segments = $db_checkpoint_segments in /etc/postgresql/9.5/main/postgresql.conf
I, [2020-05-08T10:12:57.481086 #1]  INFO -- : Replacing (?-mix:#?logging_collector *=.*) with logging_collector = $db_logging_collector in /etc/postgresql/9.5/main/postgresql.conf
I, [2020-05-08T10:12:57.481922 #1]  INFO -- : Replacing (?-mix:#?log_min_duration_statement *=.*) with log_min_duration_statement = $db_log_min_duration_statement in /etc/postgresql/9.5/main/postgresql.conf
I, [2020-05-08T10:12:57.482800 #1]  INFO -- : Replacing (?-mix:^#local +replication +postgres +peer$) with local replication postgres  peer in /etc/postgresql/9.5/main/pg_hba.conf
I, [2020-05-08T10:12:57.483651 #1]  INFO -- : Replacing (?-mix:^host.*all.*all.*127.*$) with host all all 0.0.0.0/0 md5 in /etc/postgresql/9.5/main/pg_hba.conf
I, [2020-05-08T10:12:57.484408 #1]  INFO -- : > HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/9.5/bin/postmaster -D /etc/postgresql/9.5/main
I, [2020-05-08T10:12:57.486842 #1]  INFO -- : > sleep 5
2020-05-08 10:12:57.553 UTC [1602] LOG:  database system was shut down at 2020-05-08 10:04:26 UTC
2020-05-08 10:12:57.556 UTC [1602] LOG:  MultiXact member wraparound protections are now enabled
2020-05-08 10:12:57.560 UTC [1599] LOG:  database system is ready to accept connections
2020-05-08 10:12:57.561 UTC [1606] LOG:  autovacuum launcher started
I, [2020-05-08T10:13:02.496896 #1]  INFO -- :
I, [2020-05-08T10:13:02.497338 #1]  INFO -- : > su postgres -c 'createdb discourse' || true
Error: PostgreSQL version 10 is not installed
I, [2020-05-08T10:13:02.581202 #1]  INFO -- :
I, [2020-05-08T10:13:02.581940 #1]  INFO -- : > su postgres -c 'psql discourse -c "create user discourse;"' || true
Error: PostgreSQL version 10 is not installed
I, [2020-05-08T10:13:02.646709 #1]  INFO -- :
I, [2020-05-08T10:13:02.647394 #1]  INFO -- : > su postgres -c 'psql discourse -c "grant all privileges on database discourse to discourse;"' || true
Error: PostgreSQL version 10 is not installed
I, [2020-05-08T10:13:02.719733 #1]  INFO -- :
I, [2020-05-08T10:13:02.720430 #1]  INFO -- : > su postgres -c 'psql discourse -c "alter schema public owner to discourse;"'
Error: PostgreSQL version 10 is not installed
I, [2020-05-08T10:13:02.784568 #1]  INFO -- :
I, [2020-05-08T10:13:02.785461 #1]  INFO -- : Terminating async processes
I, [2020-05-08T10:13:02.785916 #1]  INFO -- : Sending INT to HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/9.5/bin/postmaster -D /etc/postgresql/9.5/main pid: 1599
2020-05-08 10:13:02.786 UTC [1599] LOG:  received fast shutdown request
2020-05-08 10:13:02.786 UTC [1599] LOG:  aborting any active transactions
2020-05-08 10:13:02.787 UTC [1606] LOG:  autovacuum launcher shutting down
2020-05-08 10:13:02.793 UTC [1603] LOG:  shutting down
2020-05-08 10:13:02.798 UTC [1603] LOG:  database system is shut down


FAILED
--------------------
Pups::ExecError: su postgres -c 'psql discourse -c "alter schema public owner to discourse;"' failed with return #<Process::Status: pid 1617 exit 1>
Location of failure: /pups/lib/pups/exec_command.rb:112:in `spawn'
exec failed with the params "su postgres -c 'psql $db_name -c \"alter schema public owner to $db_user;\"'"
7830e2259ebf66011b6d9f2882ecfc3d204f354ee965ccdc06126682b0fab6d1
** 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.

1 Like

How and when did you install discourse?

Classic installation, on a Digital Océan droplet, using this method https://github.com/discourse/discourse/blob/master/docs/INSTALL-cloud.md

(At least 2 years ago but I made many updates, this instance is on 2.5.0b3 and I try to upgrade to beta 4)

1 Like

Can you please share the first few lines of you app.yml?

The ones under templates.

1 Like

You are right, the following line was at beginning of app.yml
"templates/postgres.9.5.template.yml"
I replaced it by:
"templates/postgres.template.yml"
The first rebuild after this change upgraded my Postgres database
And the second rebuild is currently running, but it seems to work :slight_smile:

Thanks for all !

4 Likes

So you changed that to 9.5 over 2 years ago and forgot about it.

Well, just in time, the upgrade to PostgreSQL 12 is coming very soon. Meta is already running on it.

4 Likes

It seems to be :slight_smile: Thanks for your help, @Falco !

2 Likes