4.2 KiB
Postgres image with PostGIS and pg_auto_failover extensions that allows running a high-availability Postgres cluster with query load-balancing.
How to use this image
The expected configuration is at least two worker nodes with one monitor node. The container is expected to have one or more peer configuration containers that implement query load balancing (activated using AUTOCONFIG_LOCAL_PEER and/or AUTOCONFIG_REMOTE_PEERS). One of such implementations is docker-pgpool that implements read-only/read-write splitting and load balancing using pgpool. Another is docker-pgtraefik that load balances all traffic to the primary node.
The configuration peers act as servers and this image connects to them. They can run either locally communicating over a socket or remotely over HTTP.
Environmental variables
General
-
AUTOCONFIG_LOG_LEVELLog level of the application that manages the execution (one oftrace,debug,info,warn,error,fatal). Defaultinfo. Optional. -
AUTOCONFIG_MODEDetermines the role of the container. Either- empty/not set to get the behaviour of plain Postgres image
monitorthis container becomes a monitor (only one container should have this set)postgresthis container becomes a worker (usually at least two containers have this)
No default. Required
-
AUTOCONFIG_FORMATIONName of the pg_auto_failover formation. Defaultdefault. Optional -
AUTOCONFIG_MONITOR_HOSTHostname of the monitor node. Default none. Required. -
AUTOCONFIG_MONITOR_PORTPostgres port on the monitor node. DefaultPGPORTand if not set5432. Optional. -
AUTOCONFIG_LOCAL_PEERTrue if configuration peer container is running locally and is reachable over a socket. Defaultfalse. Optional. -
AUTOCONFIG_SOCKETPath to the socket of the locally run peer configuration container. Default/var/run/pg_autoconfig.sock. Optional. -
AUTOCONFIG_REMOTE_PEERSHostnames with remote configuration peers separated by comma. Each hostname has formathostname[:port](default port 5420). Default none. Optional.
Security
AUTOCONFIG_MONITOR_PASSWORDorAUTOCONFIG_MONITOR_PASSWORD_FILEpassword (resp. path to file with the password) that is set on the monitor node for the userautoctl_nodeand worker nodes use it to report their status in pg_auto_failover. Default none. Required.AUTOCONFIG_REPLICATION_PASSWORDorAUTOCONFIG_REPLICATION_PASSWORD_FILEpassword (resp. path to file with the password) that is set on the worker nodes for the userpgautofailover_replicatorthat allows other nodes to fetch state from the currently primary nodePOSTGRES_USERNAMEPostgres admin user namePOSTGRES_PASSWORDorPOSTGRES_PASSWORD_FILEpassword (resp. path to file with the password) that is set for the user Postgres admin userAUTOCONFIG_LINK_HBA_CONFpath topg_hba.conffile that shall be linked to after the Postgres storage gets initialized (Postgres refuses to initialize non-empty directory withpg_hba.confvolume-binded from docker host). Default none. Optional.
This image does not deploy nor touch the Postgres file pg_hba.conf. You are expected to deploy it by whatever tools you have for it into some directory outside of PGDATA. However following rules are required for pg_auto_failure to work on monitor:
local all allhost pg_auto_failover autoctl_node <worker ip address> scram-sha-256(for each worker)
on worker:
local all allhost all pgautofailover_monitor <monitor ip address> trusthost replication pgautofailover_replicator <worker ip address> scram-sha-256(for each oher worker)
pg_auto_failover
XDG_CONFIG_HOMEPersistent storage for pg_auto_failover configurationXDG_DATA_HOMEPersistent state of pg_auto_failover
See others in the pg_auto_failover documentation.
Postgres
PGDATApath to Postgres persistent storage.PGPORTport for Postgres to listen on. Default 5432. Optional.POSTGRES_USERNAME(see above)POSTGRES_PASSWORDorPOSTGRES_PASSWORD_FILE(see above)
See others in postgres docker image documentation.
Runtime status
You can check the state of the cluster by executing pg_autoctl show state --formation <formation name ie. default> in the container.