From 5eaecf4b906916aa6a7822c32dde3269e65924a4 Mon Sep 17 00:00:00 2001 From: Bernhard Radermacher Date: Thu, 19 Feb 2026 11:09:35 +0100 Subject: [PATCH] conf prim node --- Dockerfile | 2 + docker-entrypoint-initdb.d/00-main.sh | 54 +++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100755 docker-entrypoint-initdb.d/00-main.sh diff --git a/Dockerfile b/Dockerfile index 0b18652..f174043 100644 --- a/Dockerfile +++ b/Dockerfile @@ -150,6 +150,8 @@ COPY docker-entrypoint.sh docker-ensure-initdb.sh /usr/local/bin/ RUN ln -sT docker-ensure-initdb.sh /usr/local/bin/docker-enforce-initdb.sh +COPY docker-entrypoint-initdb.d/* /docker-entrypoint-initdb.d/ + ENTRYPOINT ["docker-entrypoint.sh"] STOPSIGNAL SIGINT diff --git a/docker-entrypoint-initdb.d/00-main.sh b/docker-entrypoint-initdb.d/00-main.sh new file mode 100755 index 0000000..26edfc2 --- /dev/null +++ b/docker-entrypoint-initdb.d/00-main.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +# the variable UPSTREAM indicates that a standby instance is requested, otherwise this is primary +if [[ -z $UPSTREAM ]]; then + + # ensure required entries in configuration + # shellcheck disable=SC2129 + # echo "archive_command = 'cp %p ${WAL_ARCHIVE:-/wal_archive}/%f'" >> /var/lib/postgresql/data/postgresql.conf + echo "archive_command = '/bin/true'" >> /var/lib/postgresql/data/postgresql.conf + echo "archive_mode = on" >> /var/lib/postgresql/data/postgresql.conf + echo "hot_standby = on" >> /var/lib/postgresql/data/postgresql.conf + # echo "promote_trigger_file = '/var/lib/postgresql/data/${TRIGGER_FILE:-i_am_primary}'" >> /var/lib/postgresql/data/postgresql.conf + # echo "wal_keep_size = ${WAL_KEEP_SIZE:-1GB}" >> /var/lib/postgresql/data/postgresql.conf + echo "max_wal_senders = 10" >> /var/lib/postgresql/data/postgresql.conf + echo "max_replication_slots = 10" >> /var/lib/postgresql/data/postgresql.conf + # ensure required entries in hba + echo "local replication repmgr trust" >> /var/lib/postgresql/data/pg_hba.conf + echo "host replication repmgr ${NETWORK:-100.64.0.0/10} trust" >> /var/lib/postgresql/data/pg_hba.conf + echo "local repmgr repmgr trust" >> /var/lib/postgresql/data/pg_hba.conf + echo "host repmgr repmgr ${NETWORK:-100.64.0.0/10} trust" >> /var/lib/postgresql/data/pg_hba.conf + # create user for replication + psql -c "CREATE USER repmgr WITH REPLICATION ENCRYPTED PASSWORD '${REPLICATOR_PASSWORD}'; CREATE DATABASE repmgr WITH OWNER repmgr;" + psql -c 'ALTER USER repmgr SET search_path TO repmgr, "$user", public;' + + echo "node_id = 1" >> /etc/repmgr.conf + echo "node_name = pg-0" >> /etc/repmgr.conf + echo "conninfo ='host=pg-0 dbname=repmgr user=repmgr connect_timeout=2'" >> /etc/repmgr.conf + echo "data_directory = '/var/lib/postgresql/data'" >> /etc/repmgr.conf + + # process selected tweaks + if [[ -n $MAX_CONNECTIONS ]]; then + echo "max_connections = ${MAX_CONNECTIONS}" >> /var/lib/postgresql/data/postgresql.conf + fi + +else +# this is a standby + source /usr/local/bin/docker-entrypoint.sh + + docker_temp_server_stop + + rm -rf /var/lib/postgresql/data/* + + + echo "node_id = 2" >> /etc/repmgr.conf + echo "node_name = pg-1" >> /etc/repmgr.conf + echo "conninfo ='host=pg-1 dbname=repmgr user=repmgr connect_timeout=2'" >> /etc/repmgr.conf + echo "data_directory = '/var/lib/postgresql/data'" >> /etc/repmgr.conf + +# OLD_PGPASSWORD=$PGPASSWORD +# export PGPASSWORD=$REPLICATOR_PASSWORD +# pg_basebackup -h "${UPSTREAM}" -U repmgr -D "${PGDATA}" -Fp -Xs -P -R +# export PGPASSWORD=$OLD_PGPASSWORD + +fi