簡體   English   中英

Postgres:10 在 docker swarm 集群中。 數據庫系統已關閉

[英]Postgres:10 in docker swarm cluster. Database system is shut down

我使用 postgres:10 ( https://hub.docker.com/_/postgres/ ) 圖像作為數據庫。 它部署在 docker swarm 集群中。

運行數據庫副本后,我在數據庫的日志中database system is shut downdatabase system is shut down

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初始化過程一旦完成就停止初始化過程,它是另一個跟進並接受連接的過程。

因此我有:

  postgres:
    deploy:
      restart_policy:
        condition: on-failure
        window: 15m

顯然 docker 收到了一個進程結束狀態代碼,所以它在沒有進入下一個進程的情況下停止了,所以從不接受連接。

我的解釋可能不正確,但至少如果您遇到問題,請嘗試刪除restart_policy密鑰以查看是否可以解決問題。

我還沒有嘗試恢復healthcheck ,因為它也可能有不想要的副作用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM