Skip to content

chore(deps): PostgreSQL 18 with an automatic, non-destructive upgrade from 17 - #126

Merged
Yoshiofthewire merged 4 commits into
masterfrom
chore/postgres-18
Nov 25, 2026
Merged

Yoshiofthewire merged 4 commits into
masterfrom
chore/postgres-18

Conversation

@Yoshiofthewire

@Yoshiofthewire Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

In one line: The bundled PostgreSQL is now 18. An existing 17 database upgrades itself on the next docker compose up, and the 17 volume is kept for rollback.

What changed

  • The base --profile postgres service and the replica overlay run postgres:18.7-alpine3.24, pinned by digest. Before, the base file used an unpinned 17-alpine. Data now lives in a new volume mounted at /var/lib/postgresql: postgres, or postgres-replicas with the overlay.
  • A new one-shot service, postgres-17-dump, runs once on up. It uses the 17 image, has no network, and dumps the old pgdata or pgdata-replicas volume. The 18 service then restores that dump before its first start. The cluster only appears once the restore has finished. Nothing deletes or rewrites the 17 volume.
  • Both steps are the shared Ky kit, copied byte for byte into scripts/postgres-17-to-18.sh. The compose files mount it from the checkout, the same way the overlay already mounts deploy/replicas/haproxy.cfg.
  • New CI job postgres-upgrade, added to publish.needs. It runs scripts/test-postgres-17-to-18.sh base and replicas, which create real 17 data with the previous commit's compose files and then run the current ones.
  • The Go PostgreSQL job now runs on 18.7, pinned by digest.
  • check-replicas-compose.py now pins the 18 and 17 digests, the /var/lib/postgresql mount, the one-shot's settings, and the kit's checksum and mode 755.
  • Dependabot ignores PostgreSQL major bumps for docker and github-actions.
  • New docs: an operator note in docs/REPLICAS.md#postgresql-18-upgrade (what happens, disk space, time, rollback, manual clean-up), plus a README pointer and CHANGELOG notes.

Review this

  • docker-compose.yml (postgres-17-dump and postgres, lines 86–131): the order of the upgrade and which volume each service mounts. A wrong mount here is what could reach user data.
  • docker-compose.replicas.yml (lines 40–71): the overlay resets the one-shot's profile and swaps in its own volumes. The healthcheck gets start_period: 1h so a long restore doesn't fail the stack.
  • docs/REPLICAS.md, the Rollback bullet: if 17 takes writes after a rollback, the 18 volume has to be removed by hand before upgrading again.
  • Safe to skip: scripts/postgres-17-to-18.sh. It is kit v2 verbatim, sha256 29926441…5ea2b571, and the guard enforces that.

Checked: see Kit v2 below for what ran at the new head. The replica e2e suite and the smoke test run in CI only.
Not checked: a large real database (restore time is measured only on 50,000 rows), Docker setups other than local volumes, and whether stop_grace_period: 2m ever matters in practice (see Kit v2).

Decided for you

  • Used a bind mount of ./scripts/postgres-17-to-18.sh rather than a compose configs: entry. Operators already run compose from a checkout, and the overlay already bind-mounts the HAProxy config.
  • The upgrade test takes its "previous compose files" from commit fed0fb3 (PREV), the last master commit that ran 17. It doesn't use origin/master, because after the merge that would point at the 18 files.
  • The test resets the postgres host port, so a shared host where 5432 is taken can still run it.

Kit v2 (bug fix pushed to this PR after it went green)

Kit v1, which the first head (0be0bb9) vendored, had a real bug. Its dump could start a second postmaster on 17 data that another container was still running. PostgreSQL's own lock check misses this: postmaster.pid names PID 1 of the other container's PID namespace, and inside the dump container that PID looks like the dump's own grandparent. Two postmasters on one data directory can corrupt the 17 data, which this PR promises never to touch. Because this is a bug fix, it goes on this PR rather than a stacked one.

  • scripts/postgres-17-to-18.sh is re-vendored as kit v2, sha256 2992644109716cd34297fbcb76eba8907f4a5e3031a12c05aade010e5ea2b571. The one-shot now refuses while postmaster.pid exists. Kit v2 carries its own # shellcheck source=/dev/null, so the repo .shellcheckrc is deleted.
  • The postgres service and postgres-17-dump get stop_grace_period: 2m. If Compose SIGKILLs a 17 halfway through shutdown, postmaster.pid stays behind and v2 refuses the dump. check-replicas-compose.py asserts the 2m on both services, for the base profile and for the overlay.
  • Changes to the upgrade test:
    • Passwords are now checked from a second container over the compose network, and a wrong password must be refused. Before, the check ran inside the server container, where loopback is trusted, so the first head's password check proved nothing.
    • A new first step runs docker compose run --rm --no-deps postgres-17-dump while 17 is still up. It must refuse with the postmaster.pid message and write no dump.
    • The upgrade runs up -d against the running 17 stack, with no down first. The test asserts that 17 was running, that the one-shot logged dumped, and that 18 restored the rows.
  • docs/REPLICAS.md and the CHANGELOG describe the refusal, how to recover after a crash, and the stop grace period.
  • Branch: chore/postgres-18 was fast-forwarded to plover's 698049d (re-vendor plus password fix), with cf40705 (stop grace, running-stack assertions, docs) on top. The branch already contains master at fed0fb3.
Check (Major, Docker Compose v5.7.0) Result
scripts/test-postgres-17-to-18.sh base PASS (base): live 17 refused, upgrade over a running 17, rollback to 17, rerun, bad dump, fresh install
scripts/test-postgres-17-to-18.sh replicas PASS (replicas): … (same cases)
Mutation: kit v1 (a800e026…) FAIL (base): dump ran beside a live 17 server
Mutation: password checked inside the server container FAIL (base): a wrong password logged in: the password checks prove nothing
Mutation: stop_grace_period: 1m guard: a SIGKILLed 17 leaves postmaster.pid, which the dump refuses
Mutation: stop_grace_period: 0s, upgrade test still PASS. With 50,000 rows, 17 stops well within any grace period, so no test shows that the 2m matters. Only the static guard covers it
check-replicas-compose.py, shellcheck scripts/*.sh pass
Go -race -p 2 -count=1, SQLite (kjob on k80) exit 0, every package ok
Go -race -p 2 -count=1 and GODEBUG=fips140=on, on a throwaway postgres:18.7-alpine3.24@sha256:0115… (server 18.7) exit 0 for both runs, every package ok
make ci (notes-check, tidy-check, lint, test-race, test-web, audit-web, smoke), Node 26.13.1 Local CI checks passed: 37 web tests, npm audit gate passed, smoke test passed. Some Go packages came from cache in its race run; the kjob and PG18 runs above used -count=1 on the same code

The running-stack case passes on v1 and on v2. It cannot fail on v1, because Compose stops 17 before the dump with either kit. Its job is to prove that v2's new refusal does not block the normal up path for this repo's files.

You need to: nothing before merging. Operators pick up the upgrade on their next up. Removing the 17 volume afterwards is their choice and is documented.

Detail

Verification at the first head

All runs are on Major, at head 0be0bb9cd3a4 (kit v1). The current head's results are in Kit v2 above.

Check Result
scripts/test-postgres-17-to-18.sh base PASS (base): upgrade, rollback to 17, rerun, bad dump, fresh install (22 s)
scripts/test-postgres-17-to-18.sh replicas PASS (replicas): …
Mutation: old base compose with only the image bumped to 18 FAIL (base): 18 did not start after the restore; the guard fails too
Mutation: the same plain bump on base + replicas FAIL (replicas): 18 did not start after the restore
Mutation: no restore entrypoint FAIL (base): no restore ran; guard: PostgreSQL does not restore a 17 dump first
Mutation: kit edited by one line, or mode 644 guard: differs from the upgrade kit / is not mode 755
Go: gofmt, tidy, go mod verify, vet, build, go test -race -p 2 + GODEBUG=fips140=on (SQLite) pass, 12/12 packages both runs, coverage 57.0%. kjob: every K host was busy, so it fell back to Major (exit 0)
Go: same suite on a throwaway postgres:18.7-alpine3.24@sha256:0115… pass, 12/12 packages, race and FIPS (PostgreSQL 18.7 on x86_64-pc-linux-musl)
Replica e2e (KY_E2E_COMPOSE=1 go test ./e2e) CI Compose replicas and failover: pass (4m2s). The local run on Major could not create its replica network: another project's network holds 172.31.0.0/16. PostgreSQL 18 had initialised before that point
CI at this head every job green, including PostgreSQL 17 to 18 upgrade (Compose) (PASS (base) and PASS (replicas) in its log) and Go tests (PostgreSQL 18)
Local smoke test queued on Major past its time limit; CI End-to-end smoke test passed
Web (Node 26.13.1): npm ci, npm test, npm run build, git diff --exit-code web/dist, npm run audit pass: 37 tests, web/dist clean, audit gate passed
shellcheck, test_ky_init.py, check-no-binaries.sh, check-strong-crypto-compose.py, check-replicas-compose.py, make notes-check, reuse lint pass

What the upgrade test does

  1. It runs git show fed0fb3:docker-compose.yml (and docker-compose.replicas.yml for the replicas run), starts 17, and seeds:
    • a second login role and a C-locale database;
    • 50,000 rows with a unique index and jsonb;
    • pgcrypto and a large object.
  2. (v2) A hand-run one-shot beside the live 17 must refuse and write nothing. Then it switches to the current files and runs up -d postgres over the running 17. The one-shot dumps, then 18 restores. It then checks:
    • the server is 18;
    • rows, the large object and the extension survived;
    • checksums are on;
    • data_directory=/var/lib/postgresql/18/docker;
    • both passwords work from a second container over the network, a wrong password is refused, and the C collation order is B,a,é. At the first head this check ran inside the server container and proved nothing; kit v2's test fixes it;
    • the 17 volume still reads PG_VERSION=17.
  3. Rollback: it starts the previous files on the kept volume and counts 50,000 rows.
  4. Rerun: the one-shot logs already done and nothing is restored again.
  5. It corrupts the dump: postgres fails and restarts twice or more, and no 18/docker ever appears.
  6. Fresh install, after down -v: the one-shot logs nothing to move and 18 runs a plain initdb.

PostgreSQL 18 behaviour changes checked

No Go code matches SQLSTATE 23503/23001. No migration declares RESTRICT, sets an MD5 password or uses COPY … CSV, so the 18 incompatibility list does not apply.

Not changed

  • The Dockerfile and app image (no PostgreSQL client in it).
  • SQLite deployments and the schema.
  • External PostgreSQL servers.
  • Dependabot has no docker-compose ecosystem here, so it does not touch the compose pins.

🤖 Generated with Claude Code

… from 17

The bundled PostgreSQL (base postgres profile and the replica overlay) moves to
18.7, pinned by digest, on a new volume mounted at /var/lib/postgresql. On the
next `docker compose up`, a networkless postgres-17-dump one-shot (17 image)
dumps the old volume once and the 18 service's entrypoint restores it before
its first start; the 17 volume is kept for rollback. Both steps are the shared
Ky kit, vendored byte for byte as scripts/postgres-17-to-18.sh.

CI runs the Go suite on PostgreSQL 18 and gains postgres-upgrade, which seeds
real 17 data with the previous compose files and proves the upgrade, rollback,
rerun, a bad dump and a fresh install. The replica guard pins the images, the
mounts, the one-shot and the kit's checksum. Dependabot ignores postgres major
bumps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 5 🔵🔵🔵🔵🔵

🧪 PR contains tests

⚡ No major issues detected


Advisory only: this comment never gates the pull request.
gpt-6.1-sol using pr-agent on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Security review - cleared

Detail withheld: this repository is public, and posting an unfixed finding here would be public disclosure. The full report was posted to the hand-off board at https://myslop.urlxl.us/f/pr-reviewer-busnes-app-ky-server-base-126, where it is readable by the operator and expires seven days after the last post.


gpt-6.1-sol using security-audit on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Autonomous review - 1/1 personas cleared

  • security: cleared

Merging remains a human decision; this bot never approves.


gpt-6.1-sol using security-audit on behalf of Yoshi

Yoshiofthewire and others added 3 commits November 25, 2026 15:12
…utside

Re-vendors the shared upgrade kit (sha256 29926441...): the dump one-shot now
refuses while postmaster.pid is in the 17 data, because PostgreSQL's own lock
check cannot see a 17 server in another container and would let a second
postmaster start on the data. The kit also carries its own shellcheck source
directive, so the repo .shellcheckrc goes.

The upgrade test now checks passwords from a second container (inside the
server initdb trusts 127.0.0.1, so a wrong password passed) and requires a
wrong one to be refused; upgrades over the running 17 as an operator would;
and requires a hand-run one-shot beside a live 17 to refuse and write nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A 17 that Compose SIGKILLs mid-shutdown leaves postmaster.pid, which kit v2's
dump now refuses. Both PostgreSQL services get stop_grace_period: 2m, and the
compose guard asserts it for the base profile and the replica overlay.

The upgrade test now asserts 17 is still running when `up -d` starts and that
the one-shot logged its dump, so the running-stack path is proven for this
repo's files, not just inferred from the restore. Docs and CHANGELOG name the
grace period.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The ruleset requires a check by that exact name; renaming the job to
"Go tests (PostgreSQL 18)" left the required check unreported, so the PR
could never merge. The version lives in the pinned image, not the name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire
Yoshiofthewire merged commit eceb24e into master Nov 25, 2026
17 checks passed
@Yoshiofthewire
Yoshiofthewire deleted the chore/postgres-18 branch November 25, 2026 22:18
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