Skip to content

Splice user_hba.conf by data directory major for PG 16-18 - #76

Merged
souravbiswassanto merged 1 commit into
masterfrom
pg-hba-version-aware
Nov 26, 2026
Merged

souravbiswassanto merged 1 commit into
masterfrom
pg-hba-version-aware

Conversation

@souravbiswassanto

Copy link
Copy Markdown
Member

Problem

PG 16–18 role scripts write include_if_exists "/etc/config/user_hba.conf" into pg_hba.conf unconditionally. A major upgrade from 15 restarts the pod on the 16 image before pg_upgrade runs. The 16 start script then rewrites the 15 data directory's pg_hba.conf with that include, and the 15 server cannot parse it:

FATAL:  could not load pg_hba.conf
CONTEXT:  line 11 of configuration file "/var/pv/data/pg_hba.conf"

Observed live: 15.12-bookworm → 16.12-bookworm fails in pg_upgrade. 16.x→17.x and 17.x→18.x succeed, since the old server is 16+.

Change

Each affected script gets a kubedb_write_user_hba helper that chooses the form from $PGDATA/PG_VERSION:

  • version 16 or newer: keep include_if_exists (live reload, unchanged behaviour)
  • older data directory: splice /etc/config/user_hba.conf in with cat, as the 15 scripts already do
  • missing PG_VERSION (fresh data directory): use this image's major, so fresh pods behave as before

Touched: 16|17|18 × primary/start.sh, standby/run.sh, standby/remote-replica.sh (9 files, 45 call sites). The 15 and older scripts are unchanged.

Testing

  • bash -n passes on all 9 files.
  • The helper was run in isolation for majors 16, 17 and 18 against four data-directory states: no PG_VERSION, PG_VERSION=15, PG_VERSION equal to the image major, and PG_VERSION=15 with no user rules. All outputs as expected.
  • Not yet run: a pod start on the new image, a live 15→16 upgrade, or the e2e suites.

Rollout / not included

  • Needs a new init image, and the 16/17/18 PostgresVersion initContainer entries pointed at it. This PR does not change the catalog.
  • postgres hbaIncludeSupported() still keys off the CR version. It is consistent at steady state; the restart at the end of a major upgrade re-runs the splice.
  • Existing DBs stuck after a failed 15→16 upgrade (e.g. with the include already in pg_hba.conf) need manual recovery.

PostgreSQL 16+ scripts wrote `include_if_exists "/etc/config/user_hba.conf"`
into pg_hba.conf unconditionally. A major upgrade from 15 restarts the pod on
the 16 image before pg_upgrade runs, so the 16 start script rewrote the 15 data
directory's pg_hba.conf with that include. The 15 server cannot parse it, and
pg_upgrade failed with "could not load pg_hba.conf".

Choose the form from $PGDATA/PG_VERSION: 16 or newer keeps the live include,
older data directories get the file spliced in with cat, as the 15 scripts
already do. A missing PG_VERSION (fresh data directory) uses the image major.

Signed-off-by: souravbiswassanto <saurov@appscode.com>
@souravbiswassanto
souravbiswassanto merged commit 1a0fca2 into master Nov 26, 2026
5 checks passed
@souravbiswassanto
souravbiswassanto deleted the pg-hba-version-aware branch November 26, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant