Postgresql 博士后:docker swarm集群10名。数据库系统已关闭

Postgresql 博士后:docker swarm集群10名。数据库系统已关闭,postgresql,docker,docker-swarm,Postgresql,Docker,Docker Swarm,我将postgres:10()图像用于DB。 它部署在docker swarm集群中 在运行DB replica之后,我得到的数据库系统在DB的日志中被关闭 2018-05-11 10:26:53.073 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432, 2018-05-11 10:26:53.073 UTC [1] LOG: listening on IPv6 address "::", port 5432, 2018

我将postgres:10()图像用于DB。 它部署在docker swarm集群中

在运行DB replica之后,我得到的
数据库系统在DB的日志中被关闭

2018-05-11 10:26:53.073 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432,
2018-05-11 10:26:53.073 UTC [1] LOG:  listening on IPv6 address "::", port 5432,
2018-05-11 10:26:53.077 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432",
2018-05-11 10:26:53.092 UTC [20] LOG:  database system was shut down at 2018-05-11 10:26:20 UTC,
2018-05-11 10:26:53.100 UTC [1] LOG:  database system is ready to accept connections,
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 "en_US.utf8".,
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/data ... ok,
creating subdirectories ... ok,
selecting default max_connections ... 100,
selecting default shared_buffers ... 128MB,
selecting dynamic shared memory implementation ... posix,
creating configuration files ... ok,
running bootstrap script ... ok,
performing post-bootstrap initialization ... ok,
,
WARNING: enabling "trust" authentication for local connections,
You can change this by editing pg_hba.conf or using the option -A, or,
--auth-local and --auth-host, the next time you run initdb.,
syncing data to disk ... ok,
,
Success. You can now start the database server using:,
,
    pg_ctl -D /var/lib/postgresql/data -l logfile start,
,
waiting for server to start....2018-05-11 09:39:21.129 UTC [37] LOG:  listening on IPv4 address "127.0.0.1", port 5432,
2018-05-11 09:39:21.130 UTC [37] LOG:  could not bind IPv6 address "::1": Cannot assign requested address,
2018-05-11 09:39:21.130 UTC [37] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.,
2018-05-11 09:39:21.133 UTC [37] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432",
2018-05-11 09:39:21.147 UTC [38] LOG:  database system was shut down at 2018-05-11 09:39:20 UTC,
2018-05-11 09:39:21.152 UTC [37] LOG:  database system is ready to accept connections,
 done,
server started,
CREATE DATABASE,
,
CREATE ROLE,
,
,
/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*,
,
2018-05-11 09:39:21.595 UTC [37] LOG:  received fast shutdown request,
waiting for server to shut down....2018-05-11 09:39:21.596 UTC [37] LOG:  aborting any active transactions,
2018-05-11 09:39:21.598 UTC [37] LOG:  worker process: logical replication launcher (PID 44) exited with exit code 1,
2018-05-11 09:39:21.599 UTC [39] LOG:  shutting down,
2018-05-11 09:39:21.613 UTC [37] LOG:  database system is shut down,
 done,
server stopped,
,
PostgreSQL init process complete; ready for start up.,
,
2018-05-11 09:39:21.706 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432,
2018-05-11 09:39:21.706 UTC [1] LOG:  listening on IPv6 address "::", port 5432,
2018-05-11 09:39:21.709 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432",
2018-05-11 09:39:21.724 UTC [64] LOG:  database system was shut down at 2018-05-11 09:39:21 UTC,
2018-05-11 09:39:21.729 UTC [1] LOG:  database system is ready to accept connections,
2018-05-11 10:26:20.444 UTC [1] LOG:  received smart shutdown request,
2018-05-11 10:26:20.449 UTC [1] LOG:  worker process: logical replication launcher (PID 70) exited with exit code 1,
2018-05-11 10:26:20.449 UTC [65] LOG:  shutting down,
2018-05-11 10:26:20.460 UTC [1] LOG:  database system is shut down,
图片:

  FROM postgres:10

  COPY healthcheck /usr/local/bin/

  RUN chmod +x /usr/local/bin/healthcheck

  HEALTHCHECK --interval=30s --timeout=30s --retries=3 \
   CMD healthcheck
docker compose中的代码段:

  db_jackrabbit:
    build: ./images/pgsql_jackrabbit
    container_name: db_jackrabbit
    environment:
      - POSTGRES_DB=${JACK_POSTGRES_DB}
      - POSTGRES_USER=${JACK_POSTGRES_USER}
      - POSTGRES_PASSWORD=${JACK_POSTGRES_PASSWORD}
    volumes:
      -  pgsql_jackrabbit_local:/var/lib/postgresql/data
    ports:
      - ${PORT_DB_JACKRABBIT}:5432
健康检查:

#!/bin/bash
set -eo pipefail

host="$(hostname -i || echo '127.0.0.1')"
user="${POSTGRES_USER:-postgres}"
db="${POSTGRES_DB:-$POSTGRES_USER}"
export PGPASSWORD="${POSTGRES_PASSWORD:-}"

args=(
   # force postgres to not use the local unix socket (test "external" connectibility)
   --host "$host"
   --username "$user"
   --dbname "$db"
   --quiet --no-align --tuples-only
)

if select="$(echo 'SELECT 1' | psql "${args[@]}")" && [ "$select" = '1' ]; then
   exit 0
fi

exit 1
但是DB还活着。它会定期关闭并再次接受连接( 有什么问题吗? 提前谢谢!

好的,所以我解决了我的问题

似乎Postgres初始化过程一旦完成就会停止初始化过程,这是另一个跟进并接受connexion的过程

因此,我有:

  postgres:
    deploy:
      restart_policy:
        condition: on-failure
        window: 15m
显然docker收到了一个进程结束状态代码,所以它停止了,而没有进入下一个进程,所以从不接受连接

我的解释可能不正确,但至少如果您面临这个问题,请尝试删除
restart\u policy
键,看看它是否解决了问题


我还没有尝试还原
healthcheck
,因为它可能也有不希望的副作用。

你能提供run命令吗?@Safier,添加到描述中。healthcheck文件是什么,显然每30秒运行一次?@Paul Becotte,添加到描述中。我也有完全相同的问题!!!你解决了吗?