Answer the question
In order to leave comments, you need to log in
How can I fix the Postgresql promoter script?
There are 2 containers with postgresql 14 (not a cluster) on 2 different hosts with a remounted postgres volume (respectively, one of them is the master, the other is the replica).
It is not possible to set up a script with manual failover, namely, stopping the container of the former master, promoting the slave to the master and creating a slave for the new master.
When trying to pg_ctl promote on a slave, an error occurs:
could not open PID file "/postmaster.pid" : Permission denied.
version: '3.3'
services:
postgres:
container_name: postgresr
image: postgres:14-bullseye
volumes:
- ./postgres-data:/var/lib/postgresql/data
restart: always
environment:
POSTGRES_USER: ******
POSTGRES_PASSWORD: ******
POSTGRES_DB: ******
ports:
- "5432:5432"
#!/bin/bash
HIP=(hostname -i)
MIP=['10.XX.1XX.16']
SIP=['10.XX.1XX.17']
DATE=(date "+%Y%m%d%H%M%S")
if [ "$HIP" = "$MIP" ]; then
sudo chown user /home/user/compose/postgres-data && ssh [email protected]$SIP 'sudo -u postgres /usr/pgsql-14/bin/pg_ctl promote \
-D /home/user/compose/postgres-data/'
elif [ "$HIP" = "$SIP" ]; then
ssh [email protected]$MIP 'sudo -u postgres /usr/pgsql-14/bin/pg_ctl promote \
-D /home/user/compose/postgres-data/'
fi
sudo docker stop postgresr
sudo docker rm -v postgresr
rm -rf /user/compose/postgres-data*
if [ "$HIP" = "$MIP" ]; then
"pg_basebackup -h $SIP -D /home/user/compose/postgres-data/ -U replicator -P -v -R -X stream -C -S $DATE"
elif [ "$HIP" = "$SIP" ]; then
"pg_basebackup -h $MIP -D /home/user/compose/postgres-data/ -U replicator -P -v -R -X stream -C -S $DATE"
fi
sudo docker-compose up
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question