postgres15
Implement automatic primary and standby
Primary
Example compose.yaml for primary instance.
services:
db:
image: pendragon.zone/docker/postgres15replicate
restart: unless-stopped
shm_size: 128mb
environment:
POSTGRES_PASSWORD: ${DB_ROOT_PASSWORD}
REPLICATOR_PASSWORD: ${REPLICATOR_PASSWORD}
MAX_CONNECTIONS: "400"
network_mode: bridge
ports:
- 5432:5432
volumes:
- data:/var/lib/postgresql/data
- /docker/postgres_wal:/wal_archive
volumes:
data:
-
Volume
/wal_archivemust be mapped to a location available by all replication participants. -
DB_ROOT_PASSWORDrequired, must be the same for all replication participants. -
REPLICATOR_PASSWORDrequired, must be the same for all replication participants. -
UPSTREAMmust not be set for primary instance. -
WAL_ARCHIVEdefault:/wal_archiveuse different location for write-ahead-logs. -
TRIGGER_FILEdefault:i_am_primary, name of the file that promotes a standby instance to primary instance, if it exists in directory/var/lib/postgresql/data. -
WAL_KEEP_SIZEdefault:1GB -
REPLICATOR_NAMEdefault:replicatorname of user for replication. -
MAX_CONNECTIONSoptional, change default value ofmax_connectionsconfiguration value.
Standby
Example compose.yaml for standby instance.
services:
db:
image: pendragon.zone/docker/postgres15replicate
restart: unless-stopped
shm_size: 128mb
environment:
POSTGRES_PASSWORD: ${DB_ROOT_PASSWORD}
REPLICATOR_PASSWORD: ${REPLICATOR_PASSWORD}
UPSTREAM: ${UPSTREAM}
network_mode: bridge
ports:
- 5432:5432
volumes:
- data:/var/lib/postgresql/data
- /docker/postgres_wal:/wal_archive
volumes:
data:
-
Volume
/wal_archivemust be mapped to a location available by all replication participants. -
DB_ROOT_PASSWORDrequired, must be the same for all replication participants. -
REPLICATOR_PASSWORDrequired, must be the same for all replication participants. -
UPSTREAMrequired, name of the node to replicate from. Can either be primary or a different standby instance.