diff --git a/README.md b/README.md index 77588d3..437bbcd 100644 --- a/README.md +++ b/README.md @@ -91,45 +91,66 @@ docker run --name "postgis" -p 25432:5432 -d -t kartoza/postgis ## Environment variables -You can also use the following environment variables to pass a +#### Basic configuration + +You can use the following environment variables to pass a user name, password and/or default database name(or multiple databases comma separated). -* -e POSTGRES_USER= -* -e POSTGRES_PASS= -* -e POSTGRES_DBNAME= -* -e POSTGRES_MULTIPLE_EXTENSIONS=postgis,hstore,postgis_topology +* `-e POSTGRES_USER=` +* `-e POSTGRES_PASS=` +* `-e POSTGRES_DBNAME=` +* `-e POSTGRES_MULTIPLE_EXTENSIONS=postgis,hstore,postgis_topology` You can pass as many extensions as you need. -* -e SSL_CERT_FILE=/your/own/ssl_cert_file.pem -* -e SSL_KEY_FILE=/your/own/ssl_key_file.key -* -e SSL_CA_FILE=/your/own/ssl_ca_file.pem -* -e DEFAULT_ENCODING="UTF8" -* -e DEFAULT_COLLATION="en_US.UTF-8" -* -e DEFAULT_CTYPE="en_US.UTF-8" +* `-e SSL_CERT_FILE=/your/own/ssl_cert_file.pem` +* `-e SSL_KEY_FILE=/your/own/ssl_key_file.key` +* `-e SSL_CA_FILE=/your/own/ssl_ca_file.pem` +* `-e DEFAULT_ENCODING="UTF8"` +* `-e DEFAULT_COLLATION="en_US.UTF-8"` +* `-e DEFAULT_CTYPE="en_US.UTF-8"` -Specifies whether extensions will also be installed in template1 database. -* -e POSTGRES_TEMPLATE_EXTENSIONS=true +#### Specifies whether extensions will also be installed in template1 database. +* `-e POSTGRES_TEMPLATE_EXTENSIONS=true` + +#### Configures archive mode + +This image uses the initial PostgreSQL values which disables the archiving option by default. +When `ARCHIVE_MODE` is changed to `on`, the archiving command will copy WAL files to `/opt/archivedir` + +[More info: 19.5. Write Ahead Log](https://www.postgresql.org/docs/12/runtime-config-wal.html) + +* `-e ARCHIVE_MODE off` +* `-e ARCHIVE_COMMAND "test ! -f /opt/archivedir/%f && cp %p /opt/archivedir/%f"` +[More info](https://www.postgresql.org/docs/12/continuous-archiving.html#BACKUP-ARCHIVING-WAL) +* `-e ARCHIVE_CLEANUP_COMMAND 'cp /opt/archivedir/%f "%p"'` +* `-e RESTORE_COMMAND 'pg_archivecleanup /opt/archivedir %r'` + +#### Configure WAL level +* `-e WAL_LEVEL=replica` +[More info](https://www.postgresql.org/docs/12/runtime-config-wal.html) Maximum size to let the WAL grow to between automatic WAL checkpoints. -* -e WAL_SIZE=4GB - -* -e MIN_WAL_SIZE=2048MB -* -e WAL_SEGSIZE=1024 -* -e MAINTAINANCE_WORK_MEM=128MB +* `-e WAL_SIZE=4GB` +* `-e MIN_WAL_SIZE=2048MB` +* `-e WAL_SEGSIZE=1024` +* `-e MAINTAINANCE_WORK_MEM=128MB` +#### Configure networking You can open up the PG port by using the following environment variable. By default the container will allow connections only from the docker private subnet. -* -e ALLOW_IP_RANGE=<0.0.0.0/0> By default +* `-e ALLOW_IP_RANGE=<0.0.0.0/0> By default` Postgres conf is setup to listen to all connections and if a user needs to restrict which IP address PostgreSQL listens to you can define it with the following environment variable. The default is set to listen to all connections. -* -e IP_LIST=<*> +* `-e IP_LIST=<*>` + +#### Additional configuration You can also define any other configuration to add to `postgres.conf`, separated by '\n' e.g.: -* -e EXTRA_CONF="log_destination = 'stderr'\nlogging_collector = on" +* `-e EXTRA_CONF="log_destination = 'stderr'\nlogging_collector = on"` ## Docker secrets diff --git a/env-data.sh b/env-data.sh index 4276c5d..9f9640a 100644 --- a/env-data.sh +++ b/env-data.sh @@ -88,6 +88,31 @@ if [ -z "${MAINTAINANCE_WORKERS}" ]; then MAINTAINANCE_WORKERS=2 fi +if [ -z "${ARCHIVE_MODE}" ]; then + # https://www.postgresql.org/docs/12/runtime-config-wal.html + ARCHIVE_MODE=off +fi + +if [ -z "${ARCHIVE_COMMAND}" ]; then + # https://www.postgresql.org/docs/12/continuous-archiving.html#BACKUP-ARCHIVING-WAL + ARCHIVE_COMMAND="test ! -f ${WAL_ARCHIVE}/%f && cp %p ${WAL_ARCHIVE}/%f" +fi + +if [ -z "${RESTORE_COMMAND}" ]; then + # https://www.postgresql.org/docs/12/runtime-config-wal.html + RESTORE_COMMAND="cp ${WAL_ARCHIVE}/%f \"%p\"" +fi + +if [ -z "${ARCHIVE_CLEANUP_COMMAND}" ]; then + # https://www.postgresql.org/docs/12/runtime-config-wal.html + ARCHIVE_CLEANUP_COMMAND="pg_archivecleanup ${WAL_ARCHIVE} %r" +fi + +if [ -z "${WAL_LEVEL}" ]; then + # https://www.postgresql.org/docs/12/runtime-config-wal.html + WAL_LEVEL=replica +fi + if [ -z "${WAL_SIZE}" ]; then WAL_SIZE=4GB fi @@ -100,7 +125,6 @@ if [ -z "${WAL_SEGSIZE}" ]; then WAL_SEGSIZE=1024 fi - if [ -z "${CHECK_POINT_TIMEOUT}" ]; then CHECK_POINT_TIMEOUT=30min fi diff --git a/setup-conf.sh b/setup-conf.sh index abe9cf0..a20f594 100644 --- a/setup-conf.sh +++ b/setup-conf.sh @@ -17,12 +17,16 @@ cat $CONF.template > $CONF # This script will setup necessary configuration to optimise for PostGIS and to enable replications cat >> $CONF <