我正在尝试使用 Docker 容器升级 PostgreSQL。 在升级过程中,我收到一个错误:
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"?"
如果您对此问题有任何帮助,我将不胜感激。
我的 Dockerfile 包含:
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
我使用以下命令运行它:
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"
我的升级日志说:
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.
答案 0 :(得分:0)
看起来您已经发现了问题:
/usr/lib/postgresql/11/bin/postgres: error while loading shared libraries:
libssl.so.10: cannot open shared object file: No such file or directory
您的 postgresql 11 二进制文件需要一个在 postgres:13 映像中不可用的 openessl 版本。这可能是由于 Debian 版本 9(用于 postgres:11 映像)和 Debian 版本 10(用于 postgres:13 映像)之间的重大变化。
解决此问题的最简单方法是从 postgres:13 图像中可用的软件包,而不是尝试 从您的主机安装它们。
考虑将您的 Dockerfile 修改为如下所示:
FROM postgres:13
# Install binaries for postgresql 11
RUN apt update && apt install -y postgresql-11 postgresql-12
COPY docker-upgrade.sh /usr/local/bin/docker-upgrade.sh
RUN chmod 755 /usr/local/bin/docker-upgrade.sh
这里我安装了 postgres 11 版和 12 版,因为
这样我们就可以使用相同的图像从 11 -> 12
、11 -> 13
或 12 -> 13
升级。
我的 docker-upgrade.sh
看起来像这样:
#!/bin/sh
PGBINNEW=/usr/lib/postgresql/$PGNEW/bin
PGBINOLD=/usr/lib/postgresql/$PGOLD/bin
export PGBINNEW PGBINOLD
PGDATANEW=/var/lib/postgresql/$PGNEW
PGDATAOLD=/var/lib/postgresql/$PGOLD
export PGDATANEW PGDATAOLD
chown postgres:postgres $PGDATANEW
chmod 750 $PGDATANEW
runuser -u postgres -- initdb $PGDATANEW
cd $PGDATANEW
runuser -u postgres -- pg_upgrade
在我的系统上,我使用 Dockerfile 和脚本:
pgupdgrade
综合起来,假设我们在一个卷中有旧数据
名为 docker build -t pgupgrade .
,我可以创建一个新的 pgdata12
卷
通过像这样运行 pgdata13
图像来升级数据:
pgupdate
这将使用 docker run --rm \
-v pgdata12:/var/lib/postgresql/12 \
-v pgdata13:/var/lib/postgresql/13 \
-e PGNEW=13 \
-e PGOLD=12 \
pgupgrade docker-upgrade.sh
初始化新卷,然后运行
initdb
过程。一旦容器退出,我就可以启动一个新的
使用 pg_upgrade
卷的 postgres 13 容器:
pgdata13