|
|
|
|
@@ -83,7 +83,7 @@ pg_setup_conf() {
|
|
|
|
|
printf "max_replication_slots = 10\n"
|
|
|
|
|
printf "shared_preload_libraries = 'repmgr'\n"
|
|
|
|
|
if [[ -n $POSTGRES_MAX_CONNECTIONS ]]; then
|
|
|
|
|
printf "\nmax_connections = ${POSTGRES_MAX_CONNECTIONS}\n"
|
|
|
|
|
printf "\nmax_connections = '%s'\n" "$POSTGRES_MAX_CONNECTIONS"
|
|
|
|
|
fi
|
|
|
|
|
} >> "$PGDATA/postgresql.conf"
|
|
|
|
|
}
|
|
|
|
|
@@ -110,17 +110,17 @@ repmgr_setup_conf() {
|
|
|
|
|
printf "node_id = %s\n" "$REPMGR_NODE_ID"
|
|
|
|
|
printf "node_name = %s\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 "data_directory = '/var/lib/postgresql/data'\n"
|
|
|
|
|
printf "use_replication_slots = on\n"
|
|
|
|
|
printf "pg_bindir = '/usr/lib/postgresql/15/bin/'\n"
|
|
|
|
|
printf "\n"
|
|
|
|
|
printf "failover = automatic\n"
|
|
|
|
|
printf "promote_command = '/usr/bin/repmgr standby promote -f /etc/repmgr/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 "failover = automatic\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.conf --log-to-file --upstream-node-id=%n'\n"
|
|
|
|
|
printf "reconnect_attempts = 3\n"
|
|
|
|
|
printf "reconnect_interval = 5\n"
|
|
|
|
|
} > /etc/repmgr/repmgr.conf
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sudo service ssh start
|
|
|
|
|
@@ -131,17 +131,10 @@ if [ "$(id -u)" = '0' ]; then
|
|
|
|
|
exec gosu postgres "$BASH_SOURCE"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# convert to lowercase
|
|
|
|
|
REPMGR_NODE_ROLE="${REPMGR_NODE_ROLE,,}"
|
|
|
|
|
|
|
|
|
|
if [[ ! -s "$PGDATA/PG_VERSION" ]]; then
|
|
|
|
|
repmgr_setup_conf
|
|
|
|
|
|
|
|
|
|
if [[ -n $REPMGR_UPSTREAM ]] && [[ -z $REPMGR_NODE_ROLE ]]; then
|
|
|
|
|
REPMGR_NODE_ROLE="standby"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ $REPMGR_NODE_ROLE != "standby" ]]; then
|
|
|
|
|
if [[ -z $REPMGR_UPSTREAM ]]; then
|
|
|
|
|
docker_init_database_dir
|
|
|
|
|
pg_setup_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 '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
|
|
|
|
|
|
|
|
|
|
/usr/lib/postgresql/15/bin/repmgr -f /etc/repmgr.conf primary register
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
echo "Upstream host not ready. Waiting for 5 minutes..."
|
|
|
|
|
sleep 300
|
|
|
|
|
done
|
|
|
|
|
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
|
|
|
|
|
fi
|
|
|
|
|
/usr/lib/postgresql/15/bin/repmgr -f /etc/repmgr.conf standby register --force
|
|
|
|
|
|
|
|
|
|
case "$REPMGR_NODE_ROLE" in
|
|
|
|
|
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
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
docker_temp_server_stop
|
|
|
|
|
fi
|
|
|
|
|
@@ -189,6 +176,10 @@ set -m
|
|
|
|
|
postgres &
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|