# A PostgreSQL primary and one streaming replica, cloned with pg_basebackup when it starts.
configs:
  hba:
    content: |
      local all all trust
      host all all all trust
      host replication all all trust
services:
  primary:
    image: postgres:17.6
    environment:
      POSTGRES_PASSWORD: lab
      POSTGRES_HOST_AUTH_METHOD: trust
    command: ["postgres", "-c", "wal_level=replica", "-c", "hba_file=/etc/pg_hba.conf"]
    configs: [{ source: hba, target: /etc/pg_hba.conf }]
    ports: ["55472:5432"]
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "postgres"]
      interval: 1s
      retries: 30
  replica:
    image: postgres:17.6
    user: postgres
    depends_on:
      primary: { condition: service_healthy }
    entrypoint: ["bash", "-c", "pg_basebackup -h primary -U postgres -D /tmp/replica -R -X stream && chmod 700 /tmp/replica && exec postgres -D /tmp/replica -c hot_standby=on -c hba_file=/etc/pg_hba.conf"]
    configs: [{ source: hba, target: /etc/pg_hba.conf }]
    ports: ["55473:5432"]
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "postgres"]
      interval: 1s
      retries: 60
