81 lines
2.1 KiB
YAML
81 lines
2.1 KiB
YAML
version: '3.8'
|
|
x-postgres-common:
|
|
&postgres-common
|
|
image: postgres:16.3-alpine3.20
|
|
user: postgres
|
|
restart: always
|
|
healthcheck:
|
|
test: 'pg_isready -U mt_qa_postgres --dbname=mt_qa_billing'
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
|
|
services:
|
|
postgres_primary:
|
|
<<: *postgres-common
|
|
container_name: postgres_primary
|
|
ports:
|
|
- 172.20.64.140:5432:5432
|
|
environment:
|
|
POSTGRES_USER: "mt_qa_postgres"
|
|
POSTGRES_DB: "mt_qa_billing"
|
|
POSTGRES_PASSWORD: "xM9A4!exJbQNhqJ"
|
|
POSTGRES_HOST_AUTH_METHOD: "scram-sha-256\nhost replication all 0.0.0.0/0 md5"
|
|
POSTGRES_INITDB_ARGS: "--auth-host=scram-sha-256"
|
|
command: |
|
|
postgres
|
|
-c wal_level=replica
|
|
-c hot_standby=on
|
|
-c max_wal_senders=10
|
|
-c max_replication_slots=10
|
|
-c hot_standby_feedback=on
|
|
volumes:
|
|
- ./scripts/00_init.sql:/docker-entrypoint-initdb.d/00_init.sql
|
|
- pgprimary_data:/var/lib/postgresql/data
|
|
# - ./config/postgresql.conf:/var/lib/postgresql/data/postgresql.conf
|
|
networks:
|
|
- portal_qa
|
|
|
|
postgres_replica:
|
|
<<: *postgres-common
|
|
container_name: postgres_replica
|
|
ports:
|
|
- 172.20.64.140:5433:5432
|
|
environment:
|
|
PGUSER: "replicator"
|
|
PGPASSWORD: "pP5UUJM0mj5b7rZMU5C6"
|
|
volumes:
|
|
- pgreplica_data:/var/lib/postgresql/data
|
|
command: |
|
|
bash -c "
|
|
until pg_basebackup --pgdata=/var/lib/postgresql/data -R --slot=replication_slot --host=postgres_primary --port=5432
|
|
do
|
|
echo 'Waiting for primary to connect...'
|
|
sleep 1s
|
|
done
|
|
echo 'Backup done, starting replica...'
|
|
chmod 0700 /var/lib/postgresql/data
|
|
postgres
|
|
"
|
|
depends_on:
|
|
- postgres_primary
|
|
networks:
|
|
- portal_qa
|
|
|
|
volumes:
|
|
pgprimary_data:
|
|
driver: local
|
|
driver_opts:
|
|
o: bind
|
|
type: none
|
|
device: /data/container_volumes/pgprimary_data
|
|
pgreplica_data:
|
|
driver: local
|
|
driver_opts:
|
|
o: bind
|
|
type: none
|
|
device: /data/container_volumes/pgreplica_data
|
|
networks:
|
|
portal_qa:
|
|
external: true
|