#!/usr/bin/env bash source /scripts/env-data.sh SETUP_LOCKFILE="${ROOT_CONF}/.postgresql.conf.lock" if [ -f "${SETUP_LOCKFILE}" ]; then return 0 fi # Refresh configuration in case environment settings changed. cat $CONF.template > $CONF # Reflect DATA DIR location # Delete any data_dir declarations sed -i '/data_directory/d' $CONF # Create a config to optimise postgis cat > ${ROOT_CONF}/postgis.conf <> $CONF # Create a config for logical replication if [[ "${REPLICATION}" =~ [Tt][Rr][Uu][Ee] && "$WAL_LEVEL" == 'logical' ]]; then cat > ${ROOT_CONF}/logical_replication.conf <> $CONF fi # Create a config for streaming replication if [[ "${REPLICATION}" =~ [Tt][Rr][Uu][Ee] && "$WAL_LEVEL" == 'replica' ]]; then cat > ${ROOT_CONF}/streaming_replication.conf <> $CONF fi if [[ ! -f ${ROOT_CONF}/extra.conf ]]; then # If it doesn't exists, copy from /settings directory if exists if [[ -f /settings/extra.conf ]]; then cp -f /settings/extra.conf ${ROOT_CONF}/extra.conf echo "include 'extra.conf'" >> $CONF else # default value if [[ -n "$EXTRA_CONF" ]]; then echo -e $EXTRA_CONF >> ${ROOT_CONF}/extra.conf echo "include 'extra.conf'" >> $CONF fi fi fi # Optimise PostgreSQL shared memory for PostGIS # shmall units are pages and shmmax units are bytes(?) equivalent to the desired shared_buffer size set in setup_conf.sh - in this case 500MB echo "kernel.shmmax=543252480" >> /etc/sysctl.conf echo "kernel.shmall=2097152" >> /etc/sysctl.conf # Put lock file to make sure conf was not reinitialized touch ${SETUP_LOCKFILE}