#!/usr/bin/env bash source /scripts/env-data.sh create_dir ${EXTRA_CONF_DIR} create_dir ${CONF_LOCKFILE_DIR} create_dir ${SCRIPTS_LOCKFILE_DIR} SETUP_LOCKFILE="${CONF_LOCKFILE_DIR}/.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 postgres_ssl_setup cat > ${ROOT_CONF}/streaming_replication.conf <> ${ROOT_CONF}/streaming_replication.conf <> $CONF fi if [[ ! -f ${ROOT_CONF}/extra.conf ]]; then # If it doesn't exists, copy from ${EXTRA_CONF_DIR} directory if exists if [[ -f ${EXTRA_CONF_DIR}/extra.conf ]]; then cp -f ${EXTRA_CONF_DIR}/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 # Timescale default tuning # TODO If timescale DB accepts reading from include directory then refactor code to remove line 97 - 112 (https://github.com/timescale/timescaledb-tune/issues/80) if [[ $(dpkg -l | grep "timescaledb") > /dev/null ]] && [[ ${ACCEPT_TIMESCALE_TUNING} =~ [Tt][Rr][Uu][Ee] ]] ;then over_write_conf echo -e "\e[1;31m Time scale config tuning values below" # TODO Add logic to find defaults memory, CPUS as these can vary from defaults on host machine and in docker container timescaledb-tune -yes -quiet "${TIMESCALE_TUNING_PARAMS}" --conf-path="${ROOT_CONF}"/postgresql.conf echo -e "\033[0m Time scale config tuning values set in ${ROOT_CONF}/postgresql.conf" elif [[ ${ACCEPT_TIMESCALE_TUNING} =~ [Tt][Rr][Uu][Ee] ]]; then echo -e "\e[1;31m Time scale config tuning values below" timescaledb-tune -yes -quiet "${TIMESCALE_TUNING_PARAMS}" --conf-path="${ROOT_CONF}"/time_scale_tuning.conf echo -e "\033[0m Time scale config tuning values set in ${ROOT_CONF}/time_scale_tuning.conf" 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}