From e8e506dc4d54fc78a6f6574b197fad0648d8ccc4 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 29 Jul 2026 07:21:34 -0700 Subject: [PATCH] =?UTF-8?q?add:=20post=5Finit=5Fwrapper.sh=20to=20work=20a?= =?UTF-8?q?round=20Spilo's=20hardcoded=20'postgres'=20role=20name=20assump?= =?UTF-8?q?tion=20in=20post=5Finit.sh.=20Does=20not=20fork/modify=20Spilo'?= =?UTF-8?q?s=20script=20=E2=80=94=20creates=20missing=20role=20then=20exec?= =?UTF-8?q?s=20the=20original=20unchanged.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- postgresql/cutover/post_init_wrapper.sh | 42 +++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 postgresql/cutover/post_init_wrapper.sh diff --git a/postgresql/cutover/post_init_wrapper.sh b/postgresql/cutover/post_init_wrapper.sh new file mode 100644 index 0000000..248402a --- /dev/null +++ b/postgresql/cutover/post_init_wrapper.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# ───────────────────────────────────────────────────────────────────────── +# postgresql/cutover/post_init_wrapper.sh +# +# Wraps Spilo's own /scripts/post_init.sh to work around a hardcoded +# assumption in that (unmodified, upstream) script: it contains the line +# ALTER VIEW public.failed_authentication_${i} OWNER TO postgres; +# with "postgres" as a literal, non-parameterized role name. This fails +# with "role postgres does not exist" whenever PGUSER_SUPERUSER is set to +# anything other than "postgres" — which we do (PGUSER_SUPERUSER=PGadmin, +# to match this environment's actual production superuser name). +# +# This wrapper is invoked in place of /scripts/post_init.sh via the +# SPILO_CONFIGURATION override (bootstrap.post_init), which Spilo's +# configure_spilo.py deep-merges on top of its own generated Patroni +# config, with user-supplied values taking precedence. Spilo's real +# post_init.sh is NOT modified or forked — this script only ensures a +# "postgres" role exists first, then hands off to the original script +# unchanged, with its original arguments intact. +# +# Arguments (passed through from Patroni's bootstrap.post_init call, +# unchanged): $1 = HUMAN_ROLE (e.g. "zalandos"), $2 = database name to +# connect to for the initial connection (see Spilo's own post_init.sh +# usage for exact semantics — not altered here). +# ───────────────────────────────────────────────────────────────────────── +set -euo pipefail + +echo "post_init_wrapper: ensuring role 'postgres' exists before running Spilo's post_init.sh" + +psql -d "$2" -v ON_ERROR_STOP=1 <<'SQL' +DO $$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM pg_catalog.pg_roles WHERE rolname = 'postgres') THEN + CREATE ROLE postgres; + END IF; +END; +$$; +SQL + +echo "post_init_wrapper: role check complete, handing off to Spilo's post_init.sh" + +exec /scripts/post_init.sh "$1" "$2"