010: fix verification - compare pg_settings raw values, not SHOW output

SHOW() pretty-renders units (60s -> '1min'), which broke the post-up
check after a successful apply. Compare pg_settings.setting (base-unit
raw values) instead - rendering-proof.
This commit is contained in:
wan
2026-08-31 22:24:38 +09:00
parent 08c585d048
commit ff3f6732e9
+13 -8
View File
@@ -23,14 +23,19 @@ PGBIN=/etc/postgresql/18/main
CONF=$PGBIN/conf.d/010-tune-postgres.conf CONF=$PGBIN/conf.d/010-tune-postgres.conf
CLUSTER=$(pg_lsclusters --no-header | awk 'NR==1{print $1"/"$2}') 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=( WANT=(
'max_connections 30' 'max_connections 30'
'effective_cache_size 768MB' 'effective_cache_size 98304' # 768MB
'work_mem 4MB' 'work_mem 4096' # 4MB
'statement_timeout 30s' 'statement_timeout 30000' # 30s
'idle_in_transaction_session_timeout 60s' 'idle_in_transaction_session_timeout 60000' # 60s
'temp_file_limit 2GB' 'temp_file_limit 2097152' # 2GB
) )
pg() { runuser -u postgres -- psql -d postgres -v ON_ERROR_STOP=1 -tAc "$1"; } pg() { runuser -u postgres -- psql -d postgres -v ON_ERROR_STOP=1 -tAc "$1"; }
@@ -63,7 +68,7 @@ case "${1:-}" in
fi fi
for kv in "${WANT[@]}"; do for kv in "${WANT[@]}"; do
read -r guc want <<<"$kv" 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; } [[ $got == "$want" ]] || { echo "FATAL: $guc is '$got', expected '$want'" >&2; exit 1; }
done done
echo " ${#WANT[@]} memory/stability settings active" echo " ${#WANT[@]} memory/stability settings active"
@@ -81,7 +86,7 @@ case "${1:-}" in
bad=() bad=()
for kv in "${WANT[@]}"; do for kv in "${WANT[@]}"; do
read -r guc want <<<"$kv" 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)") [[ $got == "$want" ]] || bad+=("$guc=$got(want $want)")
done done
if ((${#bad[@]})); then echo "DRIFT ${bad[*]}"; exit 1; fi if ((${#bad[@]})); then echo "DRIFT ${bad[*]}"; exit 1; fi