Add option to auto tune postgresql config using timescale-db tune (#348)

* Add option to auto tune postgresql config using timescale-db tune
pull/356/head
mazano 2021-12-03 19:08:00 +02:00 zatwierdzone przez GitHub
rodzic 94cda98542
commit 2c4a732b78
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 45 dodań i 0 usunięć

Wyświetl plik

@ -298,6 +298,18 @@ need to escape it ie `$$`
* `-e DEFAULT_CTYPE="en_US.UTF-8"`
* `-e POSTGRES_TEMPLATE_EXTENSIONS=true`
* `-e ACCEPT_TIMESCALE_TUNING=TRUE` Useful to tune PostgreSQL conf based on
[timescaledb-tune](https://github.com/timescale/timescaledb-tune). Defaults to FALSE.
* `-e TIMESCALE_TUNING_PARAMS` Useful to configure none default settings to use when
running `ACCEPT_TIMESCALE_TUNING=TRUE`. This defaults to empty so that we can use the
default settings provided by the `timescaledb-tune`. Example
```bash
docker run -it --name timescale -e ACCEPT_TIMESCALE_TUNING=TRUE -e POSTGRES_MULTIPLE_EXTENSIONS=postgis,hstore,postgis_topology,postgis_raster,pgrouting,timescaledb -e TIMESCALE_TUNING_PARAMS="-cpus=4" kartoza/postgis:14-3.1
```
**Note:** `ACCEPT_TIMESCALE_TUNING` environment variable will overwrite all configurations based
on the timescale configurations
Specifies whether extensions will also be installed in template1 database.

Wyświetl plik

@ -276,6 +276,14 @@ if [ -z "${FORCE_SSL}" ]; then
FORCE_SSL=FALSE
fi
if [ -z "${ACCEPT_TIMESCALE_TUNING}" ]; then
ACCEPT_TIMESCALE_TUNING=FALSE
fi
if [ -z "${TIMESCALE_TUNING_PARAMS}" ]; then
TIMESCALE_TUNING_PARAMS=
fi
# Compatibility with official postgres variable
# Official postgres variable gets priority
if [ -n "${POSTGRES_PASSWORD}" ]; then

Wyświetl plik

@ -91,6 +91,31 @@ if [[ ! -f ${ROOT_CONF}/extra.conf ]]; then
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 [[ ${ACCEPT_TIMESCALE_TUNING} =~ [Tt][Rr][Uu][Ee] ]];then
if [[ -f ${ROOT_CONF}/postgis.conf ]];then
sed -i '/postgis.conf/d' "${ROOT_CONF}"/postgresql.conf
cat "${ROOT_CONF}"/postgis.conf >> "${ROOT_CONF}"/postgresql.conf
fi
if [[ -f ${ROOT_CONF}/logical_replication.conf ]];then
sed -i '/logical_replication.conf/d' "${ROOT_CONF}"/postgresql.conf
cat "${ROOT_CONF}"/logical_replication.conf >> "${ROOT_CONF}"/postgresql.conf
fi
if [[ -f ${ROOT_CONF}/streaming_replication.conf ]];then
sed -i '/streaming_replication.conf/d' "${ROOT_CONF}"/postgresql.conf
cat "${ROOT_CONF}"/streaming_replication.conf >> "${ROOT_CONF}"/postgresql.conf
fi
if [[ -f ${ROOT_CONF}/extra.conf ]];then
sed -i '/extra.conf/d' "${ROOT_CONF}"/postgresql.conf
cat "${ROOT_CONF}"/extra.conf >> "${ROOT_CONF}"/postgresql.conf
fi
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"
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