diff --git a/migrations/010-tune-postgres.sh b/migrations/010-tune-postgres.sh index dca711e..f079d85 100644 --- a/migrations/010-tune-postgres.sh +++ b/migrations/010-tune-postgres.sh @@ -23,14 +23,19 @@ PGBIN=/etc/postgresql/18/main CONF=$PGBIN/conf.d/010-tune-postgres.conf CLUSTER=$(pg_lsclusters --no-header | awk 'NR==1{print $1"/"$2}') -# desired state as "guc value" pairs; SHOW renders exactly these strings +# desired state as "guc raw_value" pairs, compared against pg_settings.setting +# (each GUC's base unit). Immune to SHOW()'s pretty unit rendering - +# SHOW renders 60000ms as '1min', 2097152kB as '2GB', etc. +# max_connections - effective_cache_size 8kB +# work_mem kB *_timeout ms +# temp_file_limit kB WANT=( 'max_connections 30' - 'effective_cache_size 768MB' - 'work_mem 4MB' - 'statement_timeout 30s' - 'idle_in_transaction_session_timeout 60s' - 'temp_file_limit 2GB' + 'effective_cache_size 98304' # 768MB + 'work_mem 4096' # 4MB + 'statement_timeout 30000' # 30s + 'idle_in_transaction_session_timeout 60000' # 60s + 'temp_file_limit 2097152' # 2GB ) pg() { runuser -u postgres -- psql -d postgres -v ON_ERROR_STOP=1 -tAc "$1"; } @@ -63,7 +68,7 @@ case "${1:-}" in fi for kv in "${WANT[@]}"; do read -r guc want <<<"$kv" - got=$(pg "SHOW $guc") + got=$(pg "SELECT setting FROM pg_settings WHERE name='$guc'") [[ $got == "$want" ]] || { echo "FATAL: $guc is '$got', expected '$want'" >&2; exit 1; } done echo " ${#WANT[@]} memory/stability settings active" @@ -81,7 +86,7 @@ case "${1:-}" in bad=() for kv in "${WANT[@]}"; do read -r guc want <<<"$kv" - got=$(q "SHOW $guc" 2>/dev/null) + got=$(q "SELECT setting FROM pg_settings WHERE name='$guc'" 2>/dev/null) [[ $got == "$want" ]] || bad+=("$guc=$got(want $want)") done if ((${#bad[@]})); then echo "DRIFT ${bad[*]}"; exit 1; fi