2018-03-21 20:53:39 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2020-04-14 17:00:36 +00:00
|
|
|
source /scripts/env-data.sh
|
2018-03-21 20:53:39 +00:00
|
|
|
|
2019-02-01 14:16:59 +00:00
|
|
|
SETUP_LOCKFILE="${ROOT_CONF}/.postgresql.conf.lock"
|
|
|
|
if [ -f "${SETUP_LOCKFILE}" ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2020-01-25 15:06:05 +00:00
|
|
|
list=(`echo ${POSTGRES_DBNAME} | tr ',' ' '`)
|
|
|
|
arr=(${list})
|
|
|
|
SINGLE_DB=${arr[0]}
|
2018-03-21 20:53:39 +00:00
|
|
|
# This script will setup necessary configuration to enable replications
|
|
|
|
|
|
|
|
# Refresh configuration in case environment settings changed.
|
|
|
|
cat $CONF.template > $CONF
|
|
|
|
|
2020-04-08 08:15:45 +00:00
|
|
|
# Reflect DATADIR loaction
|
|
|
|
# Delete any data_dir declarations
|
|
|
|
sed -i '/data_directory/d' $CONF
|
|
|
|
echo "data_directory = '${DATADIR}'" >> $CONF
|
|
|
|
|
2019-01-25 12:57:23 +00:00
|
|
|
# This script will setup necessary configuration to optimise for PostGIS and to enable replications
|
2018-03-21 20:53:39 +00:00
|
|
|
cat >> $CONF <<EOF
|
2020-02-12 09:34:49 +00:00
|
|
|
archive_mode = ${ARCHIVE_MODE}
|
|
|
|
archive_command = '${ARCHIVE_COMMAND}'
|
|
|
|
restore_command = '${RESTORE_COMMAND}'
|
|
|
|
archive_cleanup_command = '${ARCHIVE_CLEANUP_COMMAND}'
|
|
|
|
wal_level = ${WAL_LEVEL}
|
2019-02-20 10:28:14 +00:00
|
|
|
max_wal_senders = ${PG_MAX_WAL_SENDERS}
|
|
|
|
wal_keep_segments = ${PG_WAL_KEEP_SEGMENTS}
|
|
|
|
superuser_reserved_connections= 10
|
2020-02-12 09:34:49 +00:00
|
|
|
min_wal_size = ${MIN_WAL_SIZE}
|
|
|
|
max_wal_size = ${WAL_SIZE}
|
2018-03-21 20:53:39 +00:00
|
|
|
hot_standby = on
|
2019-01-25 12:57:23 +00:00
|
|
|
listen_addresses = '${IP_LIST}'
|
|
|
|
shared_buffers = 500MB
|
|
|
|
work_mem = 16MB
|
2019-09-06 11:47:42 +00:00
|
|
|
maintenance_work_mem = ${MAINTAINANCE_WORK_MEM}
|
2019-01-25 12:57:23 +00:00
|
|
|
wal_buffers = 1MB
|
|
|
|
random_page_cost = 2.0
|
|
|
|
xmloption = 'document'
|
2019-08-23 13:43:58 +00:00
|
|
|
max_parallel_maintenance_workers = ${MAINTAINANCE_WORKERS}
|
|
|
|
max_parallel_workers = ${MAX_WORKERS}
|
|
|
|
checkpoint_timeout = ${CHECK_POINT_TIMEOUT}
|
2019-11-25 12:47:29 +00:00
|
|
|
primary_conninfo = 'host=${REPLICATE_FROM} port=${REPLICATE_PORT} user=${REPLICATION_USER} password=${REPLICATION_PASS} sslmode=${PGSSLMODE}'
|
|
|
|
recovery_target_timeline=${TARGET_TIMELINE}
|
|
|
|
recovery_target_action=${TARGET_ACTION}
|
|
|
|
promote_trigger_file = '${PROMOTE_FILE}'
|
2020-04-14 17:00:36 +00:00
|
|
|
shared_preload_libraries = '${SHARED_PRELOAD_LIBRARIES}'
|
2020-01-25 15:06:05 +00:00
|
|
|
cron.database_name = '${SINGLE_DB}'
|
2020-05-01 05:33:49 +00:00
|
|
|
password_encryption= '${PASSWORD_AUTHENTICATION}'
|
2020-06-14 16:22:13 +00:00
|
|
|
timezone='${TIMEZONE}'
|
2018-03-21 20:53:39 +00:00
|
|
|
EOF
|
2019-01-25 12:57:23 +00:00
|
|
|
|
2019-11-25 12:47:29 +00:00
|
|
|
|
|
|
|
|
2019-10-25 12:43:15 +00:00
|
|
|
echo -e $EXTRA_CONF >> $CONF
|
|
|
|
|
2019-01-25 12:57:23 +00:00
|
|
|
# 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
|
|
|
|
|
2019-02-01 14:16:59 +00:00
|
|
|
# Put lock file to make sure conf was not reinitialized
|
|
|
|
touch ${SETUP_LOCKFILE}
|