Created
November 8, 2023 19:43
-
-
Save hermesalvesbr/159a0954448473ba815e0c0450585b41 to your computer and use it in GitHub Desktop.
This Docker Compose configuration defines a multi-container setup for running Directus (a headless CMS) alongside two PostgreSQL databases, one acting as the primary server and the other as a replica. The goal is to achieve replication between the two PostgreSQL instances.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This Docker Compose file defines three services: directus, postgres-primary, and postgres-replica. | |
# directus service runs Directus, a headless CMS, and depends on the postgres-primary service. | |
# postgres-primary service is the primary PostgreSQL database server configured with various environment variables and PostgreSQL settings. | |
# postgres-replica service is the replica PostgreSQL server configured for streaming replication from the primary server. | |
# The services are connected to a custom network called mynetwork. | |
# PostgreSQL settings such as shared buffers, work memory, and replication configurations are set for both primary and replica servers. | |
# The replication configuration specifies the streaming replication mode and replication user details. | |
################ | |
# Note: Despite the provided configuration, replication is not happening as expected. Can anyone help diagnose the issue? | |
################ | |
version: "3.7" | |
services: | |
directus: | |
image: directus/directus:latest | |
container_name: directus | |
depends_on: | |
- postgres-primary | |
ports: | |
- "8055:8055" | |
environment: | |
KEY: "255d861b-5ea1-5996-9aa3-922530ec40b1" | |
SECRET: "6116487b-cda1-52c2-b5b5-c8022c45e263" | |
DB_CLIENT: "pg" | |
DB_HOST: "postgres-primary" | |
DB_PORT: "5432" | |
DB_DATABASE: "directusdb" | |
DB_USER: "finisa" | |
DB_PASSWORD: "8Fp2Ks9jE" | |
ADMIN_EMAIL: "[email protected]" | |
ADMIN_PASSWORD: "bol" | |
networks: | |
- mynetwork | |
postgres-primary: | |
image: postgres:16 | |
environment: | |
POSTGRES_USER: finisa | |
POSTGRES_PASSWORD: 8Fp2Ks9jE | |
POSTGRES_DB: directusdb | |
PGDATA: /var/lib/postgresql/data | |
POSTGRES_SHARED_BUFFERS: 2GB | |
POSTGRES_WORK_MEM: 128MB | |
POSTGRES_MAINTENANCE_WORK_MEM: 1GB | |
POSTGRES_EFFECTIVE_CACHE_SIZE: 4GB | |
POSTGRES_MAX_CONNECTIONS: 100 | |
POSTGRES_AUTOVACUUM_VACUUM_SCALE_FACTOR: 0.2 | |
POSTGRES_AUTOVACUUM_ANALYZE_SCALE_FACTOR: 0.1 | |
POSTGRES_AUTOVACUUM_VACUUM_COST_LIMIT: -1 | |
POSTGRES_MAX_WAL_SENDERS: 4 | |
POSTGRES_MAX_REPLICATION_SLOTS: 4 | |
POSTGRES_WAL_LEVEL: logical | |
POSTGRES_LOCALE: "pt_BR.utf8" | |
POSTGRES_TIMEZONE: "America/Sao_Paulo" | |
LANG: "pt_BR.UTF-8" | |
command: | |
- "postgres" | |
- "-c" | |
- "shared_buffers=2GB" | |
- "-c" | |
- "work_mem=128MB" | |
- "-c" | |
- "maintenance_work_mem=1GB" | |
- "-c" | |
- "effective_cache_size=4GB" | |
- "-c" | |
- "max_connections=100" | |
- "-c" | |
- "autovacuum_vacuum_scale_factor=0.2" | |
- "-c" | |
- "autovacuum_analyze_scale_factor=0.1" | |
- "-c" | |
- "autovacuum_vacuum_cost_limit=-1" | |
- "-c" | |
- "wal_level=logical" | |
- "-c" | |
- "max_wal_senders=4" | |
- "-c" | |
- "max_replication_slots=4" | |
ports: | |
- "5432:5432" | |
volumes: | |
- postgres-data-primary:/var/lib/postgresql/data | |
networks: | |
- mynetwork | |
restart: always | |
postgres-replica: | |
image: postgres:16 | |
environment: | |
POSTGRES_USER: finisa | |
POSTGRES_PASSWORD: 8Fp2Ks9jE | |
POSTGRES_DB: directusdb | |
PGDATA: /var/lib/postgresql/data | |
POSTGRES_SHARED_BUFFERS: 2GB | |
POSTGRES_WORK_MEM: 128MB | |
POSTGRES_MAINTENANCE_WORK_MEM: 1GB | |
POSTGRES_EFFECTIVE_CACHE_SIZE: 4GB | |
POSTGRES_MAX_CONNECTIONS: 100 | |
POSTGRES_AUTOVACUUM_VACUUM_SCALE_FACTOR: 0.2 | |
POSTGRES_AUTOVACUUM_ANALYZE_SCALE_FACTOR: 0.1 | |
POSTGRES_AUTOVACUUM_VACUUM_COST_LIMIT: -1 | |
POSTGRES_MAX_WAL_SENDERS: 4 | |
POSTGRES_MAX_REPLICATION_SLOTS: 4 | |
POSTGRES_WAL_LEVEL: logical | |
POSTGRES_LOCALE: "pt_BR.utf8" | |
POSTGRES_TIMEZONE: "America/Sao_Paulo" | |
LANG: "pt_BR.UTF-8" | |
POSTGRES_REPLICATION_MODE: streaming | |
POSTGRES_REPLICATION_USER: finisa | |
POSTGRES_REPLICATION_PASSWORD: 8Fp2Ks9jE | |
POSTGRES_PRIMARY_HOST: postgres-primary | |
POSTGRES_PRIMARY_PORT: 5432 | |
command: | |
- "postgres" | |
- "-c" | |
- "shared_buffers=2GB" | |
- "-c" | |
- "work_mem=128MB" | |
- "-c" | |
- "maintenance_work_mem=1GB" | |
- "-c" | |
- "effective_cache_size=4GB" | |
- "-c" | |
- "max_connections=100" | |
- "-c" | |
- "autovacuum_vacuum_scale_factor=0.2" | |
- "-c" | |
- "autovacuum_analyze_scale_factor=0.1" | |
- "-c" | |
- "autovacuum_vacuum_cost_limit=-1" | |
- "-c" | |
- "max_wal_senders=4" | |
- "-c" | |
- "max_replication_slots=4" | |
ports: | |
- "5433:5432" | |
volumes: | |
- postgres-data-replica:/var/lib/postgresql/data | |
networks: | |
- mynetwork | |
restart: always | |
volumes: | |
postgres-data-primary: | |
postgres-data-replica: | |
networks: | |
mynetwork: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment