Home:ALL Converter>Postgres Docker upgrade fails with connection to database failed: could not connect to server: No such file or directory

Postgres Docker upgrade fails with connection to database failed: could not connect to server: No such file or directory

Ask Time:2021-07-01T01:28:57         Author:Justin Mahesh

Json Formatter

I am trying to upgrade PostgreSQL using a Docker container. During the upgrade process I am getting an error:

connection to database failed: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/upgrade/.s.PGSQL.50432"?"

I would appreciate any assistance on this issue.

My Dockerfile contains:

FROM postgres:13
ENV PG_MAJOR=13
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/postgresql/13/bin
EXPOSE 5432
RUN mkdir -p /var/run/postgresql  \
        && chown -R postgres:postgres /var/run/postgresql  \
        && chmod 2777 /var/run/postgresql
ENV PGBINNEW /usr/lib/postgresql/13/bin
ENV PGBINOLD /usr/lib/postgresql/11/bin
ENV PGDATAOLD /var/lib/postgresql/11/data
ENV PGDATANEW /var/lib/postgresql/13/data
ENV PG_VERSION=13.3-1.pgdg100+1
RUN mkdir -p "$PGDATAOLD" "$PGDATANEW" \
        && chown -R postgres:postgres /var/lib/postgresql
RUN mkdir -p /var/log
WORKDIR /var/lib/postgresql
COPY docker-upgrade /usr/local/bin/
RUN mkdir -p /var/log
RUN touch /var/log/postgresql.log
RUN chmod 777 -R /var/log/
RUN chmod 777 -R /var/log/postgresql.log
RUN chmod 777 -R /usr/local/bin/docker-upgrade

ENTRYPOINT docker-upgrade

# recommended: --link
CMD pg_upgrade

I am running it with the following command:

docker run                                         \
  -w /tmp/upgrade                                  \
  -v "../data/postgres-$NEW-upgrade:/tmp/upgrade"  \
  -v "../11.1/data:/var/lib/postgresql/11/data"    \ # old dir
  -v "../13/data/:/var/lib/postgresql/13/data"     \ # new Dir
  -v /usr/pgsql-11/bin/:/usr/lib/postgresql/11/bin \ # old 11 binary at host machine e 
  "pgupgrade"

My upgrade log says:

Performing Consistency Checks
-----------------------------
Checking cluster versions                                   ok

*failure*
Consult the last few lines of "pg_upgrade_server.log" for
the probable cause of the failure.

connection to database failed: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/upgrade/.s.PGSQL.50432"?

could not connect to source postmaster started with the command:
"/usr/lib/postgresql/11/bin/pg_ctl" -w -l "pg_upgrade_server.log" -D "/var/lib/postgresql/11/data" -o "-p 50432 -b  -c listen_addresses='' -c unix_socket_permissions=0700 -c unix_socket_directories='/tmp/upgrade'" start
Failure, exiting

postgres_server_log (pg_upgrade)

/usr/lib/postgresql/11/bin/postgres: error while loading shared libraries: libssl.so.10: cannot open shared object file: No such file or directory
no data was returned by command ""/usr/lib/postgresql/11/bin/postgres" -V"
The program "postgres" is needed by pg_ctl but was not found in the
same directory as "/usr/lib/postgresql/11/bin/pg_ctl".
Check your installation.

Author:Justin Mahesh,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/68199210/postgres-docker-upgrade-fails-with-connection-to-database-failed-could-not-conn
yy