Compare commits

10 Commits

Author SHA1 Message Date
Bernhard Radermacher
2f7983ad4c wip 2026-02-24 11:37:41 +01:00
Bernhard Radermacher
a50eb92c6d wip 2026-02-24 10:11:10 +01:00
Bernhard Radermacher
8799f67db6 add pgpool user 2026-02-24 10:04:32 +01:00
Bernhard Radermacher
1d608f9f99 fix 2026-02-23 13:05:10 +01:00
Bernhard Radermacher
ec6516df67 enforce standby registration 2026-02-23 13:02:54 +01:00
Bernhard Radermacher
8b1e252589 speed up failover 2026-02-23 12:56:52 +01:00
Bernhard Radermacher
838baf9860 keep alive loop... 2026-02-23 12:35:01 +01:00
Bernhard Radermacher
ba3bc385ec don't foreground 2026-02-23 12:29:40 +01:00
Bernhard Radermacher
e520f975f7 remove support for witness 2026-02-23 12:28:27 +01:00
Bernhard Radermacher
5ba26897bf remove support for witness 2026-02-23 12:18:27 +01:00
2 changed files with 27 additions and 36 deletions

View File

@@ -25,9 +25,9 @@ RUN apt-get update && \
chmod 700 /var/lib/postgresql/.ssh && \ chmod 700 /var/lib/postgresql/.ssh && \
chown postgres: /var/lib/postgresql/.ssh && \ chown postgres: /var/lib/postgresql/.ssh && \
chmod g-w,o-w /var/lib/postgresql chmod g-w,o-w /var/lib/postgresql
COPY --chmod=600 --chown=postgres:postgres authorized_keys id_ed25519 /var/lib/postgresql/.ssh/
COPY --chmod=644 --chown=postgres profile /var/lib/postgresql/.profile COPY --chmod=644 --chown=postgres:postgres profile /var/lib/postgresql/.profile
COPY --chmod=600 --chown=postgres authorized_keys id_ed25519 /var/lib/postgresql/.ssh/
COPY --chmod=755 entrypoint.sh /usr/local/bin/ COPY --chmod=755 entrypoint.sh /usr/local/bin/

View File

@@ -83,7 +83,7 @@ pg_setup_conf() {
printf "max_replication_slots = 10\n" printf "max_replication_slots = 10\n"
printf "shared_preload_libraries = 'repmgr'\n" printf "shared_preload_libraries = 'repmgr'\n"
if [[ -n $POSTGRES_MAX_CONNECTIONS ]]; then if [[ -n $POSTGRES_MAX_CONNECTIONS ]]; then
printf "\nmax_connections = ${POSTGRES_MAX_CONNECTIONS}\n" printf "\nmax_connections = '%s'\n" "$POSTGRES_MAX_CONNECTIONS"
fi fi
} >> "$PGDATA/postgresql.conf" } >> "$PGDATA/postgresql.conf"
} }
@@ -110,17 +110,17 @@ repmgr_setup_conf() {
printf "node_id = %s\n" "$REPMGR_NODE_ID" printf "node_id = %s\n" "$REPMGR_NODE_ID"
printf "node_name = %s\n" "$REPMGR_NODE_NAME" printf "node_name = %s\n" "$REPMGR_NODE_NAME"
printf "conninfo = 'host=%s dbname=repmgr user=repmgr connect_timeout=2'\n" "$REPMGR_NODE_NAME" printf "conninfo = 'host=%s dbname=repmgr user=repmgr connect_timeout=2'\n" "$REPMGR_NODE_NAME"
printf "location = '%s'\n" "$REPMGR_NODE_LOCATION"
printf "\n" printf "\n"
printf "data_directory = '/var/lib/postgresql/data'\n" printf "data_directory = '/var/lib/postgresql/data'\n"
printf "use_replication_slots = on\n" printf "use_replication_slots = on\n"
printf "pg_bindir = '/usr/lib/postgresql/15/bin/'\n" printf "pg_bindir = '/usr/lib/postgresql/15/bin/'\n"
printf "\n" printf "\n"
printf "failover = automatic\n" printf "failover = automatic\n"
printf "promote_command = '/usr/bin/repmgr standby promote -f /etc/repmgr/repmgr.conf --log-to-file'\n" printf "promote_command = '/usr/bin/repmgr standby promote -f /etc/repmgr.conf --log-to-file'\n"
printf "follow_command = '/usr/bin/repmgr standby follow -f /etc/repmgr/repmgr.conf --log-to-file --upstream-node-id=%n'\n" printf "follow_command = '/usr/bin/repmgr standby follow -f /etc/repmgr.conf --log-to-file --upstream-node-id=%n'\n"
printf "reconnect_attempts = 3\n"
printf "reconnect_interval = 5\n"
} > /etc/repmgr/repmgr.conf } > /etc/repmgr/repmgr.conf
} }
sudo service ssh start sudo service ssh start
@@ -131,17 +131,10 @@ if [ "$(id -u)" = '0' ]; then
exec gosu postgres "$BASH_SOURCE" exec gosu postgres "$BASH_SOURCE"
fi fi
# convert to lowercase
REPMGR_NODE_ROLE="${REPMGR_NODE_ROLE,,}"
if [[ ! -s "$PGDATA/PG_VERSION" ]]; then if [[ ! -s "$PGDATA/PG_VERSION" ]]; then
repmgr_setup_conf repmgr_setup_conf
if [[ -n $REPMGR_UPSTREAM ]] && [[ -z $REPMGR_NODE_ROLE ]]; then if [[ -z $REPMGR_UPSTREAM ]]; then
REPMGR_NODE_ROLE="standby"
fi
if [[ $REPMGR_NODE_ROLE != "standby" ]]; then
docker_init_database_dir docker_init_database_dir
pg_setup_conf pg_setup_conf
pg_setup_hba_conf pg_setup_hba_conf
@@ -153,33 +146,27 @@ if [[ ! -s "$PGDATA/PG_VERSION" ]]; then
psql -c "CREATE DATABASE repmgr WITH OWNER repmgr;" psql -c "CREATE DATABASE repmgr WITH OWNER repmgr;"
psql -c 'ALTER USER repmgr SET search_path TO repmgr, "$user", public;' psql -c 'ALTER USER repmgr SET search_path TO repmgr, "$user", public;'
if [[ -n $PGPOOL_PASSWORD ]]; then
psql -c "CREATE USER pgpool WITH ENCRYPTED PASSWORD '${PGPOOL_PASSWORD}';"
fi
unset PGPASSWORD unset PGPASSWORD
/usr/lib/postgresql/15/bin/repmgr -f /etc/repmgr.conf primary register
else else
until /usr/lib/postgresql/15/bin/repmgr -h $REPMGR_UPSTREAM -U repmgr -f /etc/repmgr/repmgr.conf standby clone --dry-run &> /dev/null until /usr/lib/postgresql/15/bin/repmgr -h $REPMGR_UPSTREAM -U repmgr -f /etc/repmgr.conf standby clone --dry-run &> /dev/null
do do
echo "Upstream host not ready. Waiting for 5 minutes..." echo "Upstream host not ready. Waiting for 5 minutes..."
sleep 300 sleep 300
done done
echo "Upstream host found..." echo "Upstream host found..."
/usr/lib/postgresql/15/bin/repmgr -h $REPMGR_UPSTREAM -U repmgr -f /etc/repmgr/repmgr.conf standby clone /usr/lib/postgresql/15/bin/repmgr -h $REPMGR_UPSTREAM -U repmgr -f /etc/repmgr.conf standby clone
docker_temp_server_start docker_temp_server_start
fi /usr/lib/postgresql/15/bin/repmgr -f /etc/repmgr.conf standby register --force
case "$REPMGR_NODE_ROLE" in fi
standby )
/usr/lib/postgresql/15/bin/repmgr -f /etc/repmgr/repmgr.conf standby register
;;
witness )
until /usr/lib/postgresql/15/bin/repmgr -h $REPMGR_UPSTREAM -f /etc/repmgr/repmgr.conf witness register &> /dev/null
do
echo "Primary host not ready. Waiting for 5 minutes..."
sleep 300
done
;;
* )
/usr/lib/postgresql/15/bin/repmgr -f /etc/repmgr/repmgr.conf primary register
;;
esac
docker_temp_server_stop docker_temp_server_stop
fi fi
@@ -189,6 +176,10 @@ set -m
postgres & postgres &
sleep 10 sleep 10
repmgrd -f /etc/repmgr/repmgr.conf --pid-file /tmp/repmgrd.pid repmgrd -f /etc/repmgr.conf --pid-file /tmp/repmgrd.pid
fg %1 while true
do
echo "$(date)"
sleep 3600
done