Skip to content

Instantly share code, notes, and snippets.

@audacioustux
Last active September 14, 2024 20:25
Show Gist options
  • Save audacioustux/270d95a008768381d423561c4fb78a0f to your computer and use it in GitHub Desktop.
Save audacioustux/270d95a008768381d423561c4fb78a0f to your computer and use it in GitHub Desktop.
x-postgres-environment: &postgres-environment
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
POSTGRES_USER: ${POSTGRES_USER:-postgres}
# POSTGRES_DB: ${POSTGRES_DB:-postgres}
POSTGRESQL_REPLICATION_USER: ${POSTGRESQL_REPLICATION_USER:-replicator}
POSTGRESQL_REPLICATION_PASSWORD: ${POSTGRESQL_REPLICATION_PASSWORD:-replicator}
POSTGRESQL_LOG_HOSTNAME: ${POSTGRESQL_LOG_HOSTNAME:-true}
x-postgres-healthcheck: &postgres-healthcheck
test: [ "CMD", "pg_isready", "-U", "postgres" ]
interval: 5s
timeout: 3s
x-postgres-common: &postgres-common
image: "postgres:16"
command: |
postgres
-c shared_preload_libraries=pg_stat_statements
-c pg_stat_statements.track=all
-c max_connections=100
networks:
- postgres-network
volumes:
- /var/lib/postgresql/data
services:
db-primary:
<<: *postgres-common
environment:
<<: *postgres-environment
POSTGRESQL_PGAUDIT_LOG: READ,WRITE
POSTGRESQL_REPLICATION_MODE: master
healthcheck:
<<: *postgres-healthcheck
ports:
- 5432:5432
db-replica:
<<: *postgres-common
deploy:
replicas: 2
environment:
<<: *postgres-environment
POSTGRESQL_PGAUDIT_LOG: READ
POSTGRESQL_REPLICATION_MODE: slave
POSTGRESQL_MASTER_HOST: db-primary
POSTGRESQL_MASTER_PORT: 5432
healthcheck:
<<: *postgres-healthcheck
ports:
- 5433-5434:5432
pgadmin:
image: dpage/pgadmin4
ports:
- 5050:80
environment:
- PGADMIN_DEFAULT_EMAIL=${PGADMIN_DEFAULT_EMAIL:[email protected]}
- PGADMIN_DEFAULT_PASSWORD=${PGADMIN_DEFAULT_PASSWORD:-pgadmin}
depends_on:
- db-primary
networks:
- postgres-network
networks:
postgres-network:
driver: bridge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment