Skip to content

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

Merged
Yoshiofthewire merged 5 commits into
mainfrom
chore/postgres-18
Nov 26, 2026
Merged

Yoshiofthewire merged 5 commits into
mainfrom
chore/postgres-18

Conversation

@Yoshiofthewire

@Yoshiofthewire Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Supersedes #734.

In one line: the replica overlay's database is now PostgreSQL 18. An install on 17 moves by itself on the next up, and its 17 volume is kept for rollback.

What changed

  • On the next up, a one-shot postgres-17-dump (17 image, no network) dumps kypost_pgdata once into the new kypost_postgres volume. The 18 postgres service restores that dump, renames it into place and starts. Nothing deletes or writes the 17 data.
  • Fresh installs skip the dump and initialise 18 directly.
  • The script is the shared Ky kit, vendored byte for byte as scripts/postgres-17-to-18.sh. It is mounted from the checkout, as every other overlay file is.
  • New scripts/test-postgres-17-to-18.sh, run in ci-docker. It drives the real compose files on real 17 data: the move, rollback, a rerun, a bad dump, the documented clean-up and a fresh install.
  • check-replicas-compose.py now pins both images, the mounts, the one-shot and the kit's SHA-256.
  • CI's Postgres service moves to postgres:18.7-trixie. Dependabot now ignores postgres major versions.
  • Operators get a PostgreSQL 18 section in docs/RUNNING.md: what happens, disk (about 2× the data), time, rollback and manual clean-up.

Kit v2 (bug fix on this PR, allowed past the green-PR freeze)

  • Kit v1, which this PR first shipped, could start a second postmaster in its dump step on a 17 data directory that another container still runs: PostgreSQL's own lock check cannot see across PID namespaces. scripts/postgres-17-to-18.sh is now kit v2, byte-identical (sha256 2992644109716cd34297fbcb76eba8907f4a5e3031a12c05aade010e5ea2b571; the guard pins it). v2 refuses while postmaster.pid exists and carries its own # shellcheck source=/dev/null, so CI's per-file SC1091 exclusion is gone: shellcheck is back to scripts/*.sh, as on main.
  • postgres and postgres-17-dump get stop_grace_period: 2m. Otherwise Compose SIGKILLs a 17 that is still shutting down, which leaves a postmaster.pid the dump then refuses. check-replicas-compose.py asserts this.
  • test-postgres-17-to-18.sh gains three things:
    • 1b: with 17 up, docker compose run --rm postgres-17-dump must fail, name postmaster.pid, write nothing into the 18 volume, and leave 17 serving;
    • 2: a plain up -d over the running 17 stack (no down) must log the dump and the restore;
    • password checks: these now run from a separate container on the database network (loopback inside the server container is trust in the stock image), and a wrong password for each role must be refused, on the move and on a fresh install.
  • docs/RUNNING.md says what the refusal means and what to do after a crash.
  • main is merged in (MH7: table-mode start checks and cross-host transport #738, ci: run CI and CodeQL on merge queue groups #740). The only conflict was CHANGELOG, where both entries are kept.

Kit v2 checks (Major, Docker 29.9.3, Compose v5.7.0, head after the merge)

  • test-postgres-17-to-18.sh passed all steps, 1b included, in 5m40s under kslot.
  • Mutations, each restored afterwards:
    • The kit v1 script fails the test at 1b ("the dump ran beside a live 17") and fails the guard ("differs from the shared Ky kit").
    • Adding POSTGRES_HOST_AUTH_METHOD: trust to the 18 service fails step 2 ("a wrong password logged in"). The old in-container loopback check could not catch this.
    • Dropping one stop_grace_period fails the guard.
  • Go on a throwaway postgres:18.7-trixie (CI's digest; C, UTF8, max_connections=400), -race -p 2: every stores-leg package and all of internal/api passed.
  • Full SQLite go vet ./... + go test ./... passed. kjob found every K host busy, so it ran locally under kslot.
  • Every ci-scripts step passed locally, including shellcheck scripts/*.sh and check-replicas-compose.py.
  • One test failed in both suites because of my environment: TestReceivingServerAnswersForwardedCommands hit the socket path length limit (bind: invalid argument). It passed on SQLite and on 18 with a shorter TMPDIR.
  • Not rerun locally: docker build and check-replica-cutover.sh. They passed on 18 at the first head; CI's ci-docker reruns them on this head.
  • Shellcheck on the PR's earlier per-file form is moot now that the exclusion is gone.

Kit v3 (bug fix on this PR, allowed past the green-PR freeze)

  • The bug in v2: after an upgrade, a rollback to 17 and new writes on 17, switching back to this compose file found 18/docker, said "already done" and started the older 18. What 17 wrote during the rollback stayed only in kypost_pgdata, invisible to the app.
  • The fix: scripts/postgres-17-to-18.sh is now kit v3, byte-identical (sha256 65632931413f9ddca0bce3ad5a13cd7db70860156c402c8d40c027f3c16abf15; the guard pins it). After its clean stop of 17, the dump records 17's latest checkpoint in upgrade-from-17/source-checkpoint. On a later up, if 17 has run since, it refuses and names two choices. Nothing is deleted either way. A v2 install with no checkpoint file takes the current checkpoint.
  • Upgrade test, new steps:
    • 3: after the rollback, a row is written on 17.
    • 3b: back on this compose file, up fails, the dump's log says 17 has run since the move, and postgres is not running.
    • 3c: "move 17 again", run with RUNNING.md's own compose run command (rename 18/ and upgrade-from-17/ to .replaced). The row reaches 18, and the replaced cluster and dump are still there.
    • 4b: start 17 again, and up refuses. "Keep 18" (RUNNING.md's rm of source-checkpoint) is accepted and still holds on the next up.
    • 7: takes the main project down first, which frees its database network (Major had run out of Docker address pools).
  • Docs: RUNNING.md replaces "remove the 18 volume first" with a "Back to 18 after a rollback" item: the refusal, the two choices and what each one loses. Clean-up mentions the .replaced directories, and an Exited (0) postgres-17-dump is described as its normal finished state. scripts/AGENTS.md is updated to match.

Kit v3 checks (Major, head 131a2e7)

  • test-postgres-17-to-18.sh passed every step in 1m21s under kslot.
    • The first two runs passed steps 1–6, then failed at step 7 on all predefined address pools have been fully subnetted. Other workers' networks held the pools. The step-7 down fixed it.
  • Mutations, each in a throwaway worktree:
    • kit v2 script: fails at 3b ("18 started without what 17 wrote after the move").
    • kit v2 with the 3b checks disabled: fails at 4b ("18 started after 17 ran again").
    • move-again with only 18/ renamed: fails at 3c ("18 did not start after moving again"). Both renames in the docs are needed.
  • These ci-scripts steps passed locally:
    • shell syntax;
    • shellcheck scripts/*.sh;
    • check-no-binaries.sh;
    • check-replicas-compose.py (with the v3 checksum);
    • docker compose config;
    • check-strong-crypto-compose.py.
  • Not rerun locally: the Go, frontend and relay suites, and docker build / check-replica-cutover.sh. No Go, frontend or relay file changed since e5c7434, where CI passed every job. CI reruns them all on this head.

Kit v4 (bug fix on this PR, allowed past the green-PR freeze)

  • The bug in v3: v3 kept its checkpoint in upgrade-from-17/source-checkpoint. After the documented clean-up (rm -r upgrade-from-17, with the 17 volume kept), every later start failed: the dump could not write the file into a directory that was gone.
  • The fix: scripts/postgres-17-to-18.sh is now kit v4, byte-identical (sha256 195ae8684e34dd515158a88b1f76b918cf6e3f3c854ce83fe4fb190a5178cf06; the guard pins it). The rollback refusal works as in v3, but the checkpoint is now 18/moved-from-17.checkpoint, beside the 18 cluster. Removing the dump keeps it, and renaming 18/ to move again takes it along.
  • Upgrade test:
    • 3c also checks that 18.replaced/moved-from-17.checkpoint is still there.
    • 4b uses the new path for "keep 18".
    • 6 (new): remove upgrade-from-17/ with the 17 volume kept, and 18 still starts.
    • 6b (new): roll back and write on 17. up then refuses with the rollback message and 18 stays down. "Keep 18" is accepted.
    • 6c: remove the 17 volume, and 18 keeps running (this was step 6).
  • Docs: RUNNING.md:
    • The refusal also holds after the dump clean-up.
    • "Move 17 again" leaves out the second mv once the dump is gone.
    • "Keep 18" deletes 18/moved-from-17.checkpoint.
    • Clean-up: removing the dump is safe and keeps rollback; removing the 17 volume is a separate step that ends it.
    • scripts/AGENTS.md matches.

Kit v4 checks (Major, head b624e4a)

  • test-postgres-17-to-18.sh passed every step in 3m44s under kslot.
  • Mutations: I swapped the vendored script and ran the test, sequentially and restoring v4 after each.
    • kit v2: fails at 3b ("18 started without what 17 wrote after the move").
    • kit v2, with 3b, 3c and 4b removed: fails at 6b ("18 started after a rollback that followed the dump clean-up").
    • kit v3: fails at 3c, because the replaced cluster has no checkpoint.
    • kit v3, with v3's paths in the test: fails at 6 ("18 did not start after removing upgrade-from-17"). This is the v3 bug.
  • Every ci-scripts step passed locally under kslot, including shellcheck scripts/*.sh, check-replicas-compose.py (with the v4 checksum) and both compose config steps.
  • Not rerun locally: the Go, frontend and relay suites, and docker build / check-replica-cutover.sh. No file they cover changed since e5c7434, and CI passed every job at 131a2e7. CI reruns them all on this head.
  • Both reviewers cleared 131a2e7 with no findings.

Review this

  • docker-compose.replicas.yml: the one-shot, the 18 entrypoint, depends_on and the 1 h start_period. A mistake here can start 18 empty or leave the stack unhealthy during a long restore.
  • docs/RUNNING.md, rollback and back to 18: after a rollback that ran on 17, the next up refuses until the operator chooses "move 17 again" (rename two directories) or "keep 18" (delete 18/moved-from-17.checkpoint). Check that the two commands and what each one loses read clearly. This is the one sharp edge for operators.
  • Safe to skip: the CONTRIBUTING and AGENTS wording changes.

Checked at the first head (a8bc990, kit v1; on Major, Docker 29.9.3, Compose v5.7.0)

  • test-postgres-17-to-18.sh passed all 7 steps (45 s), seeding 17 with cf5c3c80's compose files and leaving 17 running when the new up started.
  • check-replica-cutover.sh passed end to end on 18 with a locally built image (INSTALL_OLLAMA=false). This is the step chore(deps): bump postgres from 17-alpine to 18-alpine #734 failed (postgres-1 is unhealthy).
  • Mutations:
  • Go suites against a throwaway postgres:18.7-alpine3.24 (C, UTF8, max_connections=400) passed:
    • every package of the ci-backend-postgres stores leg;
    • all of internal/api.
  • Full go vet + go test -race ./... on SQLite passed, run locally under kslot because every K host was busy.
  • All ci-scripts steps passed locally, shellcheck included in the new per-file form.
  • Exactly 2 tests failed at first, both because of my environment, and passed on rerun:
    • TestReceivingServerAnswersForwardedCommands: my TMPDIR made the socket path too long (bind: invalid argument). Passed on both backends with a shorter TMPDIR.
    • TestNativeMailRelayCheckRuntime: hit its 30 s limit under load. Passed alone on 18.

Not checked

  • Compose versions older than v5.7.0 locally. CI runs the runner's Compose.
  • Restore time on large databases: unproven. It scales with the data.
  • Frontend and relay jobs: this PR doesn't touch them, so they are left to CI.

Decided for you

  • The kit's dump used to start a second postmaster beside a running 17. Kit v2 refuses instead (see Kit v2 above).
  • A re-upgrade after a rollback that ran 17 refuses instead of starting the older 18. The operator picks one of the two documented choices (see Kit v3 and v4 above).
  • Dependabot keeps postgres minor and digest bumps but ignores majors, for docker, docker-compose and github-actions.

You need to: nothing. Operators of the replica overlay need git pull before the next upgrade; the script is mounted from the checkout.

Detail

Images

Where Before After
docker-compose.replicas.yml postgres postgres:17-alpine@sha256:526f86d9… postgres:18.7-alpine3.24@sha256:0115267ab5a509022df9319c77be365cef335adb71556c75f60f5360ee247e71
postgres-17-dump (new) — postgres:17.12-alpine3.24@sha256:f9cf3e1f0066f0eb0c48707d864f0ac5941e9ff454a072077d97a4d278d07d73
CI ci-backend-postgres service postgres:17@sha256:3b0cda93… postgres:18.7-trixie@sha256:c699303802144847d238196173655dbbecf7a96aeca1565f2b02eb671a1f0b6b (resolved with docker buildx imagetools inspect)

Volumes

  • kypost_pgdata (17 data) is mounted only by the dump, at /var/lib/postgresql/data.
  • kypost_postgres (new) is mounted by 18 at /var/lib/postgresql, with no PGDATA, so the data lives in 18/docker. The dump mounts it at /pg18.

Upgrade test steps (scripts/test-postgres-17-to-18.sh)

  1. Seed 17 using git show cf5c3c80:docker-compose{,.replicas}.yml, fetched by SHA when missing. The seed is 50,000 rows, a second login role and C-ordered text.
    1b. With 17 up, a run of the dump refuses on postmaster.pid and writes nothing.
  2. Run the new up -d --wait postgres while 17 is still running (no down). Then check:
    • the server is 18;
    • all rows and checksums came across;
    • both roles' passwords work from another container, and wrong ones are refused;
    • B,a,é still sorts that way and the database is C,UTF8;
    • the data directory is /var/lib/postgresql/18/docker;
    • the 17 volume still says PG_VERSION=17;
    • the dump and the restore both ran.
  3. Rollback: the previous files start 17 on the kept volume, with every row, and a row is written on 17.
    3b. Back on the new files: up fails, the dump says 17 has run since the move, and 18 is not running.
    3c. "Move 17 again" via RUNNING.md's rename command: 18 has 50,001 rows, and 18.replaced and upgrade-from-17.replaced are kept.
  4. A second up: the dump says "already done" and nothing is dumped or restored again.
    4b. 17 runs again, so up refuses. "Keep 18" (rm of source-checkpoint) is accepted, and the next up still holds.
  5. A corrupt dump: 18 fails on two starts, never becomes healthy, and never creates 18/docker.
  6. The documented clean-up (docker volume rm …_kypost_pgdata, then rm -r of the dump): 18 restarts with every row.
  7. A fresh install: "nothing to move", and 18 initialises in 18/docker with the C locale.

PostgreSQL 18 behaviour changes: no Go code matches SQLSTATE 23503 and no schema declares RESTRICT foreign keys, so the 23001 change does not apply. No MD5 passwords, no COPY … CSV with \..

🤖 Generated with Claude Code

… from 17

The replica overlay's database moves to postgres:18.7-alpine3.24. Its 18
image refuses a mount at /var/lib/postgresql/data, which is why the plain
Dependabot bump (#734) never became healthy in ci-docker.

An install on 17 moves on the next `up`. A one-shot postgres-17-dump (17
image, no network) dumps the kept kypost_pgdata volume once into the new
kypost_postgres volume. The 18 service then restores that dump, renames
it into place and starts. Both steps are the shared Ky kit, vendored byte
for byte as scripts/postgres-17-to-18.sh. Nothing removes the 17 volume.

scripts/test-postgres-17-to-18.sh seeds 17 with the previous commit's
compose files, with 17 still running. It checks:
- rows, both roles' passwords and the C/UTF8 locale survive on 18;
- the previous compose files still start 17 on the kept volume;
- a rerun does nothing;
- a bad dump never yields a cluster;
- the documented clean-up keeps 18 running;
- a fresh install initialises.
It runs in ci-docker.

check-replicas-compose.py pins both images, the mounts, the one-shot and
the kit's SHA-256. CI's Postgres service moves to postgres:18.7-trixie.
Dependabot ignores postgres majors.

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: 4 🔵🔵🔵🔵⚪

🧪 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-kypost-server-739, 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 2 commits November 25, 2026 15:53
CHANGELOG.md: keep both new entries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kit v1's dump could start a second postmaster on a 17 data directory
another container still runs: PostgreSQL's own lock check cannot see
across PID namespaces. Kit v2 (sha256 29926441...) refuses while
postmaster.pid exists and carries its own shellcheck directive, so the
repo-side SC1091 exclusion goes.

Both PostgreSQL services get stop_grace_period: 2m, so Compose does not
SIGKILL a 17 mid-shutdown and leave a postmaster.pid the dump refuses.
check-replicas-compose.py asserts it and the new checksum.

test-postgres-17-to-18.sh now:
- checks passwords from another container on the database network,
  where pg_hba's scram line applies, and that wrong ones are refused;
- runs the dump beside the live 17 and asserts it refuses, naming
  postmaster.pid, and writes nothing;
- asserts the dump and restore ran on an `up -d` over the running 17.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yoshiofthewire and others added 2 commits November 25, 2026 18:12
Kit v2 started the older 18 after a rollback to 17 and back, without
what 17 wrote meanwhile. Kit v3 records 17's checkpoint at the dump
and refuses once 17 has run since, naming two choices: move 17 again
(rename 18/ and upgrade-from-17/) or keep 18 (delete
source-checkpoint).

The upgrade test now writes on 17 after a rollback and checks the
refusal, both documented choices and the replaced 18 being kept.
RUNNING.md describes the way back to 18 and that an exited
postgres-17-dump is its finished state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kit v3 kept its rollback checkpoint in upgrade-from-17/, so the documented
clean-up (rm -r upgrade-from-17) broke every later start. Kit v4 keeps it
at 18/moved-from-17.checkpoint, beside the 18 cluster.

- Re-vendor the kit byte for byte and pin its new SHA-256.
- The upgrade test uses the new marker for "keep 18", checks that the
  marker moves with 18.replaced, and gains steps 6 and 6b: after the dump
  is removed (17 kept), 18 still starts, and a rollback that writes on 17
  is still refused on the way back. Removing the 17 volume is step 6c.
- RUNNING.md: the new marker path; the dump clean-up is safe and keeps
  rollback; removing the 17 volume is a separate step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire
Yoshiofthewire added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit 928ba0b Nov 26, 2026
28 checks passed
@Yoshiofthewire
Yoshiofthewire deleted the chore/postgres-18 branch November 26, 2026 00:07
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