Manual upgrade failure due to postgres error

Hello, I am trying to upgrade manually, here’s my log
What should I do?

sudo ./launcher rebuild app

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: warning: forcing reinstallation of alternative /usr/share/postgresql/12/man/man1/postmaster.1.gz because link group postmaster.1.gz is broken
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.23-1.pgdg100+1) ...
Processing triggers for postgresql-common (217.pgdg100+1) ...
Building PostgreSQL dictionaries from installed myspell/hunspell packages...
Removing obsolete dictionary files:

I, [2020-10-28T10:22:20.196731 #1]  INFO -- : > mkdir -p /shared/postgres_run
I, [2020-10-28T10:22:20.200695 #1]  INFO -- : 
I, [2020-10-28T10:22:20.201329 #1]  INFO -- : > chown postgres:postgres /shared/postgres_run
I, [2020-10-28T10:22:20.203957 #1]  INFO -- : 
I, [2020-10-28T10:22:20.204465 #1]  INFO -- : > chmod 775 /shared/postgres_run
I, [2020-10-28T10:22:20.206513 #1]  INFO -- : 
I, [2020-10-28T10:22:20.206943 #1]  INFO -- : > rm -fr /var/run/postgresql
I, [2020-10-28T10:22:20.209197 #1]  INFO -- : 
I, [2020-10-28T10:22:20.209637 #1]  INFO -- : > ln -s /shared/postgres_run /var/run/postgresql
I, [2020-10-28T10:22:20.211799 #1]  INFO -- : 
I, [2020-10-28T10:22:20.212220 #1]  INFO -- : > socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1
2020/10/28 10:22:20 socat[1561] E connect(6, AF=1 "/shared/postgres_run/.s.PGSQL.5432", 36): No such file or directory
I, [2020-10-28T10:22:20.217266 #1]  INFO -- : 
I, [2020-10-28T10:22:20.217575 #1]  INFO -- : > rm -fr /shared/postgres_run/.s*
I, [2020-10-28T10:22:20.220449 #1]  INFO -- : 
I, [2020-10-28T10:22:20.220758 #1]  INFO -- : > rm -fr /shared/postgres_run/*.pid
I, [2020-10-28T10:22:20.223435 #1]  INFO -- : 
I, [2020-10-28T10:22:20.223813 #1]  INFO -- : > mkdir -p /shared/postgres_run/9.5-main.pg_stat_tmp
I, [2020-10-28T10:22:20.226084 #1]  INFO -- : 
I, [2020-10-28T10:22:20.226579 #1]  INFO -- : > chown postgres:postgres /shared/postgres_run/9.5-main.pg_stat_tmp
I, [2020-10-28T10:22:20.228969 #1]  INFO -- : 
I, [2020-10-28T10:22:20.233931 #1]  INFO -- : File > /etc/service/postgres/run  chmod: +x  chown: 
I, [2020-10-28T10:22:20.238588 #1]  INFO -- : File > /etc/runit/3.d/99-postgres  chmod: +x  chown: 
I, [2020-10-28T10:22:20.239031 #1]  INFO -- : > chown -R root /var/lib/postgresql/9.5/main
I, [2020-10-28T10:22:20.246966 #1]  INFO -- : 
I, [2020-10-28T10:22:20.247561 #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-10-28T10:22:20.249670 #1]  INFO -- : 
I, [2020-10-28T10:22:20.249990 #1]  INFO -- : > chown -R postgres:postgres /shared/postgres_data
I, [2020-10-28T10:22:20.262909 #1]  INFO -- : 
I, [2020-10-28T10:22:20.263584 #1]  INFO -- : > chown -R postgres:postgres /var/run/postgresql
I, [2020-10-28T10:22:20.266363 #1]  INFO -- : 
I, [2020-10-28T10:22:20.266925 #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-10-28T10:22:20.267629 #1]  INFO -- : Replacing (?-mix:#?listen_addresses *=.*) with listen_addresses = '*' in /etc/postgresql/9.5/main/postgresql.conf
I, [2020-10-28T10:22:20.268883 #1]  INFO -- : Replacing (?-mix:#?synchronous_commit *=.*) with synchronous_commit = $db_synchronous_commit in /etc/postgresql/9.5/main/postgresql.conf
I, [2020-10-28T10:22:20.269787 #1]  INFO -- : Replacing (?-mix:#?shared_buffers *=.*) with shared_buffers = $db_shared_buffers in /etc/postgresql/9.5/main/postgresql.conf
I, [2020-10-28T10:22:20.270543 #1]  INFO -- : Replacing (?-mix:#?work_mem *=.*) with work_mem = $db_work_mem in /etc/postgresql/9.5/main/postgresql.conf
I, [2020-10-28T10:22:20.271537 #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-10-28T10:22:20.272184 #1]  INFO -- : > install -d -m 0755 -o postgres -g postgres /shared/postgres_backup
I, [2020-10-28T10:22:20.275256 #1]  INFO -- : 
I, [2020-10-28T10:22:20.275862 #1]  INFO -- : Replacing (?-mix:#?checkpoint_segments *=.*) with checkpoint_segments = $db_checkpoint_segments in /etc/postgresql/9.5/main/postgresql.conf
I, [2020-10-28T10:22:20.276339 #1]  INFO -- : Replacing (?-mix:#?logging_collector *=.*) with logging_collector = $db_logging_collector in /etc/postgresql/9.5/main/postgresql.conf
I, [2020-10-28T10:22:20.277136 #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-10-28T10:22:20.278090 #1]  INFO -- : Replacing (?-mix:^#local +replication +postgres +peer$) with local replication postgres  peer in /etc/postgresql/9.5/main/pg_hba.conf
I, [2020-10-28T10:22:20.278571 #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-10-28T10:22:20.279235 #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-10-28T10:22:20.281040 #1]  INFO -- : > sleep 5
2020-10-28 10:22:20.333 UTC [1580] LOG:  database system was shut down at 2020-10-28 10:19:20 UTC
2020-10-28 10:22:20.337 UTC [1580] LOG:  MultiXact member wraparound protections are now enabled
2020-10-28 10:22:20.341 UTC [1577] LOG:  database system is ready to accept connections
2020-10-28 10:22:20.343 UTC [1584] LOG:  autovacuum launcher started
I, [2020-10-28T10:22:25.288886 #1]  INFO -- : 
I, [2020-10-28T10:22:25.289989 #1]  INFO -- : > su postgres -c 'createdb discourse' || true
createdb: error: could not connect to database template1: 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"?
I, [2020-10-28T10:22:25.344151 #1]  INFO -- : 
I, [2020-10-28T10:22:25.344889 #1]  INFO -- : > su postgres -c 'psql discourse -c "create user discourse;"' || true
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"?
I, [2020-10-28T10:22:25.408939 #1]  INFO -- : 
I, [2020-10-28T10:22:25.409561 #1]  INFO -- : > su postgres -c 'psql discourse -c "grant all privileges on database discourse to discourse;"' || true
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"?
I, [2020-10-28T10:22:25.492798 #1]  INFO -- : 
I, [2020-10-28T10:22:25.493395 #1]  INFO -- : > su postgres -c 'psql discourse -c "alter schema public owner to discourse;"'
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"?
I, [2020-10-28T10:22:25.556797 #1]  INFO -- : 
I, [2020-10-28T10:22:25.557554 #1]  INFO -- : Terminating async processes
I, [2020-10-28T10:22:25.557833 #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: 1577
2020-10-28 10:22:25.558 UTC [1577] LOG:  received fast shutdown request
2020-10-28 10:22:25.558 UTC [1577] LOG:  aborting any active transactions
2020-10-28 10:22:25.559 UTC [1584] LOG:  autovacuum launcher shutting down
2020-10-28 10:22:25.564 UTC [1581] LOG:  shutting down
2020-10-28 10:22:25.576 UTC [1581] 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 1609 exit 2>
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;\"'"
64eda6530b4c6630604201c10e122bbb767b1c31c2ef72d222d7d196db6da2b1
** 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.

sudo ./discourse-doctor

PG::ConnectionBad: 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"?
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/pg-1.2.2/lib/pg.rb:58:in `initialize'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/pg-1.2.2/lib/pg.rb:58:in `new'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/pg-1.2.2/lib/pg.rb:58:in `connect'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:46:in `postgresql_connection'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:889:in `new_connection'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:933:in `checkout_new_connection'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:912:in `try_to_checkout_new_connection'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:873:in `acquire_connection'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:595:in `checkout'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:439:in `connection'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:1121:in `retrieve_connection'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.1/lib/active_record/connection_handling.rb:238:in `retrieve_connection'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.1/lib/active_record/connection_handling.rb:206:in `connection'
/var/www/discourse/lib/site_settings/db_provider.rb:61:in `table_exists?'
/var/www/discourse/lib/site_settings/db_provider.rb:16:in `all'
/var/www/discourse/lib/site_settings/defaults_provider.rb:29:in `db_all'
/var/www/discourse/lib/site_setting_extension.rb:277:in `block in refresh!'
/var/www/discourse/lib/site_setting_extension.rb:274:in `synchronize'
/var/www/discourse/lib/site_setting_extension.rb:274:in `refresh!'
/var/www/discourse/lib/site_setting_extension.rb:495:in `block in setup_methods'
/var/www/discourse/config/initializers/004-message_bus.rb:120:in `<top (required)>'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.1/lib/active_support/dependencies.rb:319:in `load'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.1/lib/active_support/dependencies.rb:319:in `block in load'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.1/lib/active_support/dependencies.rb:291:in `load_dependency'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.1/lib/active_support/dependencies.rb:319:in `load'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-6.0.1/lib/rails/engine.rb:667:in `block in load_config_initializer'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.1/lib/active_support/notifications.rb:182:in `instrument'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-6.0.1/lib/rails/engine.rb:666:in `load_config_initializer'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-6.0.1/lib/rails/engine.rb:624:in `block (2 levels) in <class:Engine>'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-6.0.1/lib/rails/engine.rb:623:in `each'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-6.0.1/lib/rails/engine.rb:623:in `block in <class:Engine>'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-6.0.1/lib/rails/initializable.rb:32:in `instance_exec'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-6.0.1/lib/rails/initializable.rb:32:in `run'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-6.0.1/lib/rails/initializable.rb:61:in `block in run_initializers'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-6.0.1/lib/rails/initializable.rb:50:in `each'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-6.0.1/lib/rails/initializable.rb:50:in `tsort_each_child'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-6.0.1/lib/rails/initializable.rb:60:in `run_initializers'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-6.0.1/lib/rails/application.rb:363:in `initialize!'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-6.0.1/lib/rails/railtie.rb:190:in `public_send'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-6.0.1/lib/rails/railtie.rb:190:in `method_missing'
/var/www/discourse/config/environment.rb:7:in `<top (required)>'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/kernel.rb:23:in `require'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/kernel.rb:23:in `require'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.1/lib/active_support/dependencies.rb:325:in `block in require'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.1/lib/active_support/dependencies.rb:291:in `load_dependency'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.1/lib/active_support/dependencies.rb:325:in `require'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-6.0.1/lib/rails/application.rb:339:in `require_environment!'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-6.0.1/lib/rails/application.rb:515:in `block in run_tasks_blocks'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
Tasks: TOP => emails:test => environment
(See full trace by running task with --trace)

Replacing: SMTP_PASSWORD
Replacing: LETSENCRYPT_ACCOUNT_EMAIL
Replacing: DEVELOPER_EMAILS
Replacing: DISCOURSE_DB_PASSWORD
Replacing: Sending mail to

I got it to work by modifiying app.yaml

templates/postgres.9.5.template.yml ->  "templates/postgres.template.yml"
2 Likes