E
E
EvnMiller2021-10-30 10:48:46
PostgreSQL
EvnMiller, 2021-10-30 10:48:46

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.

Google has a solution to this problem - running pg_ctl promote as a postgres user, but this does not solve the problem.
From the root does not want to run because it asks to run from an unprivileged user.
docker-compose.yml
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"

promoter script:
#!/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

1 answer(s)
I
Ivan Kulakov, 2021-10-30
@ivankprod

Try giving 677 permissions to this pid file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question