Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ARG PG_MAJOR_PREVIOUS=14
ARG PG_MAJOR=15

FROM timescaledev/timescaledb-ha:pg15-multi as trimmed
MAINTAINER [email protected]
LABEL org.opencontainers.image.authors="[email protected]"

USER root

Expand Down Expand Up @@ -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
Expand Down
44 changes: 0 additions & 44 deletions Dockerfile.alpine

This file was deleted.

19 changes: 19 additions & 0 deletions docker-entrypoint-initdb.d/010_or_set_vacuum_parameters.sh
Original file line number Diff line number Diff line change
@@ -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 "-----------------------------------------------------------------------------------"
Comment on lines +1 to +19
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this now I don't see value in having this init script and the logic in the entrypoint, the entrypoint logic should be sufficient I think

48 changes: 48 additions & 0 deletions or-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check OR_AUTOVACUUM_VACUUM_SCALE_FACTOR is set if not then leave this setting alone (just in case DBA has configured this manually)

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check OR_AUTOVACUUM_VACUUM_SCALE_FACTOR is set if not then leave this setting alone (just in case DBA has configured this manually)

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
########################################################################################
Expand Down