diff --git a/Dockerfile b/Dockerfile index 1d5780d..2d88266 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ ARG PG_MAJOR_PREVIOUS=14 ARG PG_MAJOR=15 FROM timescaledev/timescaledb-ha:pg15-multi as trimmed -MAINTAINER support@openremote.io +LABEL org.opencontainers.image.authors="support@openremote.io" USER root @@ -78,7 +78,9 @@ ENV PGROOT=/var/lib/postgresql \ OR_REINDEX_COUNTER=${OR_REINDEX_COUNTER} \ OR_DISABLE_REINDEX=${OR_DISABLE_REINDEX:-false} \ POSTGRES_MAX_CONNECTIONS=${POSTGRES_MAX_CONNECTIONS:-50} \ - OR_DISABLE_AUTO_UPGRADE=${OR_DISABLE_AUTO_UPGRADE:-false} + OR_DISABLE_AUTO_UPGRADE=${OR_DISABLE_AUTO_UPGRADE:-false} \ + OR_AUTOVACUUM_VACUUM_SCALE_FACTOR=${OR_AUTOVACUUM_VACUUM_SCALE_FACTOR:-0.2} \ + OR_AUTOVACUUM_ANALYZE_SCALE_FACTOR=${OR_AUTOVACUUM_ANALYZE_SCALE_FACTOR:-0.1} WORKDIR /var/lib/postgresql EXPOSE 5432 8008 8081 diff --git a/Dockerfile.alpine b/Dockerfile.alpine deleted file mode 100644 index 404ecd7..0000000 --- a/Dockerfile.alpine +++ /dev/null @@ -1,44 +0,0 @@ -# ----------------------------------------------------------------------------------------------- -# POSTGIS and TimescaleDB (inc. toolkit for hyperfunctions) image built for aarch64 support -# using alpine base image. -# -# timescale/timescaledb-ha image is ubuntu based and only currently supports amd64; they are -# working on ARM64 support in timescaledev/timescaledb-ha see: -# -# https://github.com/timescale/timescaledb-docker-ha/pull/355 -# -# See this issue for POSTGIS base image aarch64 support discussion: -# -# https://github.com/postgis/docker-postgis/issues/216 -# ------- ---------------------------------------------------------------------------------------- - -# We get POSTGIS and timescale+toolkit from this image -FROM timescaledev/timescaledb-ha:pg15-multi as timescale-ha - - -# This base image is alpine based - timescale toolkit requires glibc 2.3+ so we install it into alpine image -# This still doesn't work as timescale code is compiled against glibc and some references don't match with gcompat - -FROM timescale/timescaledb:latest-pg15 -MAINTAINER support@openremote.io - -ENV GLIBC_VERSION 2.35-r0 -ENV TZ ${TZ:-Europe/Amsterdam} -ENV PGTZ ${PGTZ:-Europe/Amsterdam} -ENV POSTGRES_DB ${POSTGRES_DB:-openremote} -ENV POSTGRES_USER ${POSTGRES_USER:-postgres} -ENV POSTGRES_PASSWORD ${POSTGRES_PASSWORD:-postgres} - -# Add glibc -RUN apk add gcompat - - -COPY --from=timescale-ha /usr/lib/postgresql/15/lib/bitcode/postgis-3/ /usr/local/lib/postgresql/bitcode/ -COPY --from=timescale-ha /usr/lib/postgresql/15/lib/postgis* /usr/local/lib/postgresql/ -COPY --from=timescale-ha /docker-entrypoint-initdb.d/010_install_timescaledb_toolkit.sh /docker-entrypoint-initdb.d/010_install_timescaledb_toolkit.sh -COPY --from=timescale-ha /usr/lib/postgresql/15/lib/timescaledb* /usr/local/lib/postgresql/ -COPY --from=timescale-ha /usr/bin/timescale* /usr/local/bin/ -COPY --from=timescale-ha /usr/share/postgresql/15/extension/postgis* /usr/local/share/postgresql/extension/ -COPY --from=timescale-ha /usr/share/postgresql/15/extension/timescale* /usr/local/share/postgresql/extension/ - -HEALTHCHECK --interval=3s --timeout=3s --start-period=2s --retries=30 CMD pg_isready diff --git a/docker-entrypoint-initdb.d/010_or_set_vacuum_parameters.sh b/docker-entrypoint-initdb.d/010_or_set_vacuum_parameters.sh new file mode 100755 index 0000000..fba9203 --- /dev/null +++ b/docker-entrypoint-initdb.d/010_or_set_vacuum_parameters.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -e + +echo "-------------------------------------------------------------------------------------" +echo "Setting autovacuum parameters during initialization..." +echo "-------------------------------------------------------------------------------------" + +# Set vacuum parameters +psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL + ALTER SYSTEM SET autovacuum_vacuum_scale_factor = $OR_AUTOVACUUM_VACUUM_SCALE_FACTOR; + ALTER SYSTEM SET autovacuum_analyze_scale_factor = $OR_AUTOVACUUM_ANALYZE_SCALE_FACTOR; + SELECT pg_reload_conf(); +EOSQL + +echo "-----------------------------------------------------------------------------------" +echo "Autovacuum parameters set: " +echo " - autovacuum_vacuum_scale_factor = $OR_AUTOVACUUM_VACUUM_SCALE_FACTOR" +echo " - autovacuum_analyze_scale_factor = $OR_AUTOVACUUM_ANALYZE_SCALE_FACTOR" +echo "-----------------------------------------------------------------------------------" diff --git a/or-entrypoint.sh b/or-entrypoint.sh index 5cb8eeb..e3d96ad 100644 --- a/or-entrypoint.sh +++ b/or-entrypoint.sh @@ -59,6 +59,54 @@ if [ -n "$DATABASE_ALREADY_EXISTS" ]; then echo "timescaledb.telemetry_level=off" >> "$PGDATA/postgresql.conf" fi + # Check and update autovacuum_vacuum_scale_factor if needed + echo "--------------------------------------------------------------------" + echo "Checking autovacuum_vacuum_scale_factor setting..." + echo "--------------------------------------------------------------------" + + # Extract current setting if it exists (commented or uncommented) + CURRENT_AUTOVAC_SETTING=$(grep -E "^[#]*autovacuum_vacuum_scale_factor" "$PGDATA/postgresql.conf" | grep -oE "[0-9]\.[0-9]+" || echo "") + + if [ -z "$CURRENT_AUTOVAC_SETTING" ] || [ "$CURRENT_AUTOVAC_SETTING" != "$OR_AUTOVACUUM_VACUUM_SCALE_FACTOR" ]; then + echo "------------------------------------------------------------------------" + echo "Setting autovacuum_vacuum_scale_factor to $OR_AUTOVACUUM_VACUUM_SCALE_FACTOR" + echo "------------------------------------------------------------------------" + + # Remove any existing setting (commented or uncommented) + sed -i "/^[#]*autovacuum_vacuum_scale_factor/d" "$PGDATA/postgresql.conf" + + # Add the new setting + echo "autovacuum_vacuum_scale_factor = $OR_AUTOVACUUM_VACUUM_SCALE_FACTOR" >> "$PGDATA/postgresql.conf" + else + echo "-----------------------------------------------------------------------" + echo "autovacuum_vacuum_scale_factor already set to $CURRENT_AUTOVAC_SETTING" + echo "-----------------------------------------------------------------------" + fi + + # Check and update autovacuum_analyze_scale_factor if needed + echo "--------------------------------------------------------------------" + echo "Checking autovacuum_analyze_scale_factor setting..." + echo "--------------------------------------------------------------------" + + # Extract current setting if it exists (commented or uncommented) + CURRENT_AUTOVAC_ANALYZE_SETTING=$(grep -E "^[#]*autovacuum_analyze_scale_factor" "$PGDATA/postgresql.conf" | grep -oE "[0-9]\.[0-9]+" || echo "") + + if [ -z "$CURRENT_AUTOVAC_ANALYZE_SETTING" ] || [ "$CURRENT_AUTOVAC_ANALYZE_SETTING" != "$OR_AUTOVACUUM_ANALYZE_SCALE_FACTOR" ]; then + echo "------------------------------------------------------------------------" + echo "Setting autovacuum_analyze_scale_factor to $OR_AUTOVACUUM_ANALYZE_SCALE_FACTOR" + echo "------------------------------------------------------------------------" + + # Remove any existing setting (commented or uncommented) + sed -i "/^[#]*autovacuum_analyze_scale_factor/d" "$PGDATA/postgresql.conf" + + # Add the new setting + echo "autovacuum_analyze_scale_factor = $OR_AUTOVACUUM_ANALYZE_SCALE_FACTOR" >> "$PGDATA/postgresql.conf" + else + echo "------------------------------------------------------------------------" + echo "autovacuum_analyze_scale_factor already set to $CURRENT_AUTOVAC_ANALYZE_SETTING" + echo "------------------------------------------------------------------------" + fi + ######################################################################################## # Do upgrade checks - Adapted from https://github.com/pgautoupgrade/docker-pgautoupgrade ########################################################################################