version: '3.9'
services:
  postgresql_primary:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password_file
      POSTGRES_DB: postgres
      POSTGRES_USER: postgres
    secrets:
    - postgres_password_file
    volumes:
    - pg_data:/var/lib/postgresql/data
    networks:
    - database-network
    healthcheck:
      test:
      - CMD-SHELL
      - pg_isready -U postgres
      interval: 30s
      timeout: 10s
      retries: 5
      start_period: 60s
    deploy:
      resources:
        limits:
          memory: 4G
          cpus: '2.0'
        reservations:
          memory: 2G
          cpus: '1.0'
      placement:
        constraints:
        - node.labels.role==db
      replicas: 1
volumes:
  pg_data:
    driver: local
secrets:
  postgres_password_file:
    external: true
networks:
  database-network:
    external: true
