Skip to content

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

Open
Yoshiofthewire wants to merge 2 commits into
masterfrom
chore/postgres-18
Open

Yoshiofthewire wants to merge 2 commits into
masterfrom
chore/postgres-18

Conversation

@Yoshiofthewire

@Yoshiofthewire Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

In one line: KyMessages' Matrix Postgres (Docker) and the replicated KyIdentity's database pod (Kubernetes) move to PostgreSQL 18. A 17 install moves itself on its next deploy and keeps the 17 data. CloudNativePG clusters stay on 17.

What changed

  • Automatic move. Both moves are a dump and restore with the suite's kit v4, vendored byte for byte (scripts/postgres-17-to-18.sh, sha256 195ae86…). A 17.12 one-shot dumps the old data once, and 18 restores it beside the old data. The 17 data is only read, so the previous release still starts on it.
  • Safe return after a rollback (kit v4, head 02e5c57). If 17 ran after the move, the next deploy of 18 refuses instead of starting the older 18 without 17's new writes. The message offers two choices: move again (rename 18/), or keep 18 (delete 18/moved-from-17.checkpoint). Removing upgrade-from-17/ stays safe. This fixes the Guide's "Stale Migration".
  • One-shots in health (fixes e2e (kube-message-apply)). A one-shot that exited 0 counts as done everywhere. On Docker, one that exited non-zero fails apply/start/health at once, with its last 40 log lines. On Kubernetes, health's reason quotes the dump init container's termination message.
  • kymessage gets a one-shot and the kit. The new one-shot is postgres-17-dump (no network, restart: "no"), and postgres waits for it. ./pgdata is now mounted at /var/lib/postgresql. The kit ships as a catalog file (pg-upgrade/). This is the same shape as KyMessage-Server fe88a59 (chore(deps): Bump github.com/Busnes-app/ky-primitives from 0.10.0 to 0.10.1 in the ky-primitives group #152).
  • Backup first, or acknowledge. New manifest rule upgrade.move, keyed on the target's data layout, not on versions. An install that has not moved is backed up first (kyquickstart backup) when the target has a destination. If that backup fails, nothing is deployed. Without a destination, the deploy refuses (ack_required) until --acknowledge-no-backup.
  • Catalog support for one-shots. A service that others wait for with service_completed_successfully is now "Once": it is labelled and run by up, and health never asks it to be running. Apps without native mail may now bind files/.
  • KyIdentity database pod. New init container postgres-17-dump (17 image). The kit runs inline in the pod spec, the claim is mounted at /var/lib/postgresql (the private subPath), and the termination grace is 120 s.
  • CNPG postgres_cluster stays 17.12. KyQuickStart has no backup of a Cluster to take before CloudNativePG's major upgrade. Posted as BLOCKED to the owner on the board (ky-postgres-18).

Review this

  • Merge order. The catalog's kymessage image (0.6.1) ships postgresql17-client. Its console pg_dump refuses an 18 server, so the console's own Matrix backups break if this merges before the catalog pins a KyMessage-Server release that contains fe88a59. No such release exists yet (latest is v0.6.1.1).
  • internal/cli/suite.go moveGate: decides backup, refusal or acknowledgement.
  • internal/catalog/catalog.go checkCompose: the Once classification. A wrongly classified service would be skipped by health.
  • internal/dockerhost/health.go failedOnce/upFailed: a failed one-shot now ends health and up without waiting for the timeout.

Checked

  • scripts/test-postgres-17-to-18.sh PASS on Major. It renders kymessage from the previous catalog (950c3f8) and from this one, then covers: up -d over the running 17; a refused dump beside a live 17 that writes nothing; rows, C collation and checksums; passwords checked from another container, with a wrong password refused; rollback to 17 with a write on 17; a refused return to 18 ("has run on … since it was moved to 18", PostgreSQL not started); move again (row on 18, 18.replaced kept); keep 18 (accepted twice); removing upgrade-from-17/ and then starting again, followed by a rollback that is still refused; a no-op rerun; a bad dump that never yields a cluster; a fresh install; a 17 backup restored on 18 with the manifest's restore_command.

  • Mutations of that test fail as they should: a plain image bump fails with "no such service: postgres-17-dump"; the pre-v2 kit fails with "dump ran beside a live 17". With kit v2 as the new side: "18 started after 17 ran since the move". With kit v3: "18 did not start after the dump was removed".

  • scripts/test-postgres-17-to-18-pod.sh PASS. It runs the rendered previous and new pod specs in Docker as a kubelet would: subPath mounts, read-only root, uid 70, fsGroup. It covers the live-17 refusal, the move, the password checks, rollback, the same v4 return, move-again, keep-18 and clean-up cases, a rerun and a fresh claim. A plain image bump fails it, kit v2 fails with "dump accepted a 17 that ran since the move", and kit v3 with "source-checkpoint: No such file or directory".

  • One-shot health: TestOnceExitCode (dockerhost) and TestHealthReportsFailedDump (kube). Reverting either fix fails its test.

  • Unit tests for the gate (move_test.go):

    • with a destination, the backup runs before the deploy;
    • a failed backup leaves the old files deployed;
    • without a destination it refuses, and --acknowledge-no-backup lets it proceed;
    • once the data has moved, there is no gate.

    Disabling moveGate fails them.

  • Full required checks at 02e5c57, on Major because every K host was busy: go mod tidy -diff, gofmt, go vet (with and without e2e,goolm), go test -race ./..., notes-check, shellcheck. All exit 0. Both upgrade tests PASS on kit v4. Earlier (at 3b89e5a): actionlint, make workflow-lint, mdbook. This head touches no workflows.

Not checked

  • TestKubernetesKyMessage was not run locally (Docker address pools on Major are nearly exhausted). Its stackHealthy fix only compiles here; CI's kube-message-apply shard must prove it.
  • Real Kubernetes for the database pod is unproven (the test above is Docker).
  • Rootless/Podman is unproven.
  • TestApply (dumpdemo, now on 18) runs only in CI.

Decided for you

  • The confirmation flag is the existing --acknowledge-no-backup (your "--yes").
  • The KyIdentity database pod move is not gated: the installer has no backup of that database, and the 17 data stays as the way back.
  • The kit reaches the pod as a container argument, not a ConfigMap.

You need to: merge only after KyMessage-Server cuts a release containing fe88a59 and the catalog follows it. Decide the CNPG path (board ky-postgres-18).

Detail
  • Operator notes are in docs/guided-setup.md, in the KyMessages "PostgreSQL 18" bullet and in the replicas database section. They cover the next up, the space needed (about 2× the data), how long the move takes, rollback, and the way back to 18 after a rollback, and the manual clean-up: upgrade-from-17/ is safe to remove; removing pgdata/pgdata (17) is separate and ends the way back.
  • The script reaches the containers this way: Compose writes catalog files/ into the app directory (./pg-upgrade/postgres-17-to-18.sh, bound read-only), because KyQuickStart ships its own template. Kubernetes gets the kit embedded in the binary, as the pod command's argument.
  • TestPostgresKitIsVendoredByteForByte checks that scripts/ (mode 755) and the catalog copy match kit v4. The kube test checks that the pod's arguments equal scripts/postgres-17-to-18.sh.
  • The kymessage health wait stays at 10 minutes. A longer restore fails that apply, and a rerun waits again.
  • dependabot.yml needs no change: no configured ecosystem sees a Postgres image.
  • docs/release-candidate-*.json and euro-office's PG16 are untouched.
  • The test-only dumpdemo moved to 18 on a fresh volume at /var/lib/postgresql.

🤖 Generated with Claude Code

… from 17

KyMessages' Matrix Postgres (Docker) and the replicated KyIdentity's database
pod (Kubernetes) move to 18.7, pinned by digest. A 17 install moves on its
next deploy by dump and restore with the suite's kit v2
(scripts/postgres-17-to-18.sh, byte for byte, sha256 2992644...): a 17.12
one-shot dumps the old data once, 18 restores it beside it, and the 17 data
is only read, so the previous release still starts on it.

- kymessage: postgres-17-dump one-shot (no network, restart "no") that
  postgres waits for; ./pgdata mounted at /var/lib/postgresql; the kit is
  a catalog file (pg-upgrade/). Its testdata copy of KyMessage's compose
  is fe88a59's.
- Catalog: services others wait for with service_completed_successfully
  are Once: labelled, run by up, never asked to be running or healthy.
  Plain apps may bind files/.
- upgrade.move gates on the target's layout, not versions: an unmoved
  install is backed up first where kyquickstart backup can, else needs
  --acknowledge-no-backup.
- KyIdentity database pod: init container postgres-17-dump (17), the kit
  inline in the pod spec, claim at /var/lib/postgresql, 120 s grace.
- CloudNativePG clusters stay on 17: there is no installer backup of a
  Cluster to take before its major upgrade.
- scripts/test-postgres-17-to-18.sh (rendered kymessage Compose) and
  test-postgres-17-to-18-pod.sh (rendered pod spec in Docker), CI job
  "PostgreSQL 17 to 18 upgrade", required by release-image.yml.

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-kyquickstart-216, 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

Kit v4 (sha256 195ae86..., byte for byte in scripts/, kymessage's
pg-upgrade/ and internal/kube/): after a rollback that ran 17, a return
to 18 refuses instead of silently starting the older 18; the marker
sits at 18/moved-from-17.checkpoint, so removing upgrade-from-17/ is safe.

- dockerhost: a Once service that exited non-zero fails health, up and
  start at once with its last logs; one that exited 0 is done.
- kube: the database pod's dump init container keeps its last lines as
  its termination message, and health's reason quotes it.
- e2e stackHealthy: expects the catalog's services plus its one-shots,
  accepts Exited (0) and fails with logs on any other exit (the
  kube-message-apply failure at 3b89e5a).
- Both upgrade tests gain: write on 17 after a rollback, refused return,
  move again (row on 18, replaced 18 kept), keep 18, and the dump
  clean-up followed by a refused rollback. The Compose test's cleanup
  now passes KYQ_UID, so it no longer leaks networks.
- docs/guided-setup.md: the way back to 18 and the safe clean-up.

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

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

Fixed in 02e5c57. A return to 18 after 17 has run now refuses instead of starting the older 18. This is kit v4 (sha256 195ae86…), vendored in all three copies.

  • How it detects a rollback: after its clean stop of 17, the dump records 17's latest checkpoint in 18/moved-from-17.checkpoint. Any later 17 start writes a new checkpoint. If 17's checkpoint no longer matches the file, the dump exits 1, and postgres (service_completed_successfully) does not start.
  • What the operator sees: apply now shows the one-shot's logs when it fails.
  • Kubernetes: the init container refuses in the same way.

New case in scripts/test-postgres-17-to-18.sh: roll back with the previous catalog, write a row on 17, switch back. Output on Major:

refused as documented: postgres-17-to-18: PostgreSQL 17 has run on /v/pgdata since it was moved to 18, so 18 lacks what 17 wrote since then. To move 17 again: stop everything, rename /v/18 (and /v/upgrade-from-17, if it is there) with a suffix such as .replaced (nothing is deleted), then start again. To keep 18 as it is: delete /v/18/moved-from-17.checkpoint, then start again.
PASS: kymessage PostgreSQL 17 to 18 (up over running 17, live-17 refusal, passwords, rollback, refused return after 17 ran, move again, keep 18, dump clean-up, rerun, bad dump, fresh, 17 backup on 18)

The pod test runs the same cases:

PASS: database pod PostgreSQL 17 to 18 (live-17 refusal, move, passwords, rollback, refused return after 17 ran, move again, keep 18, dump clean-up, rerun, fresh claim); Kubernetes itself unproven

Each follow-up case is checked as well:

  • Move again: the row written on 17 reaches 18, and 18.replaced is kept.
  • Keep 18: accepted, and it sticks.
  • After rm -r upgrade-from-17: 18 still starts, and a later rollback is still refused.

Run with kit v2 on the new side, the case fails with "18 started after 17 ran since the move".

Yoshiofthewire added a commit that referenced this pull request Nov 26, 2026
…-18-cnpg

Conflicts in AGENTS.md and CHANGELOG.md only: kept #216's rollback text and
#217's CloudNativePG entries, and dropped "CloudNativePG clusters stay on 17".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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