Need solution for docker postgresql replication, failover, load balancing with zero downtime high availability

I want to achieve Docker Postgres Volume Replication , Failover and load balancing with zero down time high availability of PostgreSQL.

When I using bitnami/postgres-repmgr in docker swarm environment setup like
One Manager node
• Manager IP: 192.168.1.10
Two Worker nodes
• Worker1 IP: 192.168.1.11
• Worker2 IP: 192.168.1.12

version: '3.8'
services:
  pg-0:
    image: bitnami/postgresql-repmgr:15
    ports:
      - 5050:5432
    volumes:
      - pg_0_data:/bitnami/postgresql
    environment:
      - POSTGRESQL_POSTGRES_PASSWORD=adminpassword
      - POSTGRESQL_USERNAME=customuser
      - POSTGRESQL_PASSWORD=custompassword
      - POSTGRESQL_DATABASE=customdatabase
      - REPMGR_PASSWORD=repmgrpassword
      - REPMGR_PRIMARY_HOST=pg-0
      - REPMGR_PRIMARY_PORT=5432
      - REPMGR_PARTNER_NODES=pg-0,pg-1:5432
      - REPMGR_NODE_NAME=pg-0
      - REPMGR_NODE_NETWORK_NAME=pg-0
      - REPMGR_PORT_NUMBER=5432
  pg-1:
    image: bitnami/postgresql-repmgr:15
    ports:
      - 5051:5432
    volumes:
      - pg_1_data:/bitnami/postgresql
    environment:
      - POSTGRESQL_POSTGRES_PASSWORD=adminpassword
      - POSTGRESQL_USERNAME=customuser
      - POSTGRESQL_PASSWORD=custompassword
      - POSTGRESQL_DATABASE=customdatabase
      - REPMGR_PASSWORD=repmgrpassword
      - REPMGR_PRIMARY_HOST=pg-0
      - REPMGR_PRIMARY_PORT=5432
      - REPMGR_PARTNER_NODES=pg-0,pg-1:5432
      - REPMGR_NODE_NAME=pg-1
      - REPMGR_NODE_NETWORK_NAME=pg-1
      - REPMGR_PORT_NUMBER=5432

volumes:
  pg_0_data:
    driver: local
  pg_1_data:
    driver: local

I am facing the below Problems, when I am running above docker compose file.

  1. I couldn’t achieve high availability and load balancing.
  2. How can I call common ip and port postgres database
    • Primary node port – 5050
    • Replica node port - 5051
  3. If primary database goes down, how to handle the situation for downtime if it possible or not.
  4. I want to achieve zero downtime without data losing, if it possible or not.

kindly could give me solution as soon as possible

I fixed your post replacing quote with code block. Please, use code blocks for code instead of quotes (right next to the quote button: </>)

High availability is probably never as easy as running a simple docker compose project copied out from the image description with some additional modification. Since I don’t know the Postgresql replication manager, I can’t tell you how it should be done. First you need to learn about repmgr and when you understand it, you can try to run it in Docker containers.

Although this is forum is a place where we can help with Docker-related questions, there are complex issues that cannot be answer with a short reply and requires much more than knowing Docker. I hope you will find a solution.

PS.: Please stop ending your questions with “as soon as possible”. The word “kindly” will not make it better. Everyone’s post is equally important, although we can’t answer everything and urging answers will have the opposite effect.

1 Like