Skip to content

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

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

Yoshiofthewire merged 2 commits into
masterfrom
chore/postgres-18

Conversation

@Yoshiofthewire

@Yoshiofthewire Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

In one line: Matrix's database now runs PostgreSQL 18.7, and an existing 17 stack upgrades by itself on its next docker compose up -d. Its 17 data stays untouched for a rollback.

What changed

  • On the next up, a new one-shot postgres-17-dump (17.12 image, no network, read-only root) dumps the 17 data (pgdata/ in matrix-postgres) once. Postgres 18 restores that dump into 18/docker on the same volume, then starts normally. Nothing deletes or rewrites the 17 data.
  • Fresh installs: nothing to dump, so 18 runs a plain initdb with matrix-init's SQL.
  • The app image moves to postgresql18-client, so backups use pg_dump/pg_restore 18. Capsules taken on 17 still restore (tested).
  • scripts/postgres-17-to-18.sh is the suite's kit, vendored byte for byte (kit v2, sha256 29926441…), and check-compose-matrix.sh enforces that. It also holds the new layout and the locked-down one-shot.
  • New CI job PostgreSQL 17 to 18 upgrade (Matrix Compose) runs scripts/test-postgres-17-to-18.sh on real 17 data. It is added to release-image.yml's REQUIRED list.
  • scripts/matrix-acceptance.sh copies the kit into its scratch project directory, beside compose/. Compose resolves ./scripts/postgres-17-to-18.sh from there, so without the copy every acceptance leg and the KyCalendar suite failed at stack ("bind source path does not exist").
  • Operator note: docs/CHAT-SETUP.md "PostgreSQL 18". It covers disk (about 2× the database), time, rollback and the optional manual clean-up.

Review this

  • docker-compose.matrix.yml, the postgres-17-dump and postgres services. This is what runs on every operator's next up. The dump mounts the volume at /v (OLD=/v/pgdata NEW=/v); 18 mounts it at /var/lib/postgresql with no PGDATA.
  • scripts/test-postgres-17-to-18.sh is the proof. Its password checks connect from a separate container on matrix-db, because the stock image trusts 127.0.0.1 inside the server's own container. I reported that gap in the kit's own test on the suite board.
  • Safe to skim: docs, genpins, the probe.sh mount, the CHANGELOG.

Checked (on Major, Docker 29 and Compose 5.7)

  • The upgrade test passes in 77 s.
  • Mutations fail it: a plain image bump fails the test ("18 did not start after the move") and the compose check. Master's 17 compose fails the check.
  • check-compose-matrix, -podman and -proxy and check-strong-crypto-compose.py pass. Dropping the kit bind's SELinux label fails the Podman check.
  • matrix-acceptance.sh against the real stack, stopped after kyidentity (KyIdentity at CI's pinned 8cf7cf9): PASS. Postgres 18 starts on a fresh volume through the kit, and Synapse, MAS and the app come up healthy. Without the copy, the same run fails at stack with CI's exact error.
  • shellcheck passes over scripts/*.sh with no exclusions.
  • go vet and go test -race pass on SQLite and on PostgreSQL 18.7, except TestInstallerLiveActivationRolesAndSignedRevocation, which failed only because of the long temp path on Major ("setup socket path exceeds the 107-byte Unix limit"). Rerun with a short TMPDIR: see below.

Not checked

  • matrix-acceptance after kyidentity, and the KyCalendar suite: this PR's CI runs them.
  • Rootless Podman at runtime: the overlay is only checked statically.
  • Kubernetes: ky-kubernetes owns those manifests.

Decided for you

  • The script reaches the containers by bind-mounting ./scripts/postgres-17-to-18.sh, because operators run Compose from a git checkout (INSTALL.md). The release workflow publishes images only, no Compose bundle, and the Compose files already bind ./compose/ and ./matrix/ from the checkout. So configs: would buy nothing. KyQuickStart ships its own template and must embed or carry the script.
  • Compose stops the old 17 container before the dump starts, so two servers never open the same data. The test asserts this from Docker events with 17 running. Kit v2 also refuses a dump while pgdata/postmaster.pid exists. The test shows a hand-run postgres-17-dump beside a live 17 is refused and writes nothing, and it fails with the earlier kit. Both Postgres services get stop_grace_period: 2m, so a clean stop removes that file.
  • Clean-up is manual: docker compose exec postgres rm -r /var/lib/postgresql/pgdata /var/lib/postgresql/upgrade-from-17. It is the same volume, so there is no docker volume rm.
  • .github/dependabot.yml is unchanged: no configured ecosystem sees a Postgres image. The docker entry reads only the Dockerfile, there is no docker-compose entry, and github-actions does not bump services: images.

You need to: nothing. The root thread merges once CI and the reviews are clean.

Detail

Images

  • 18: postgres:18.7-alpine3.24@sha256:0115267ab5a509022df9319c77be365cef335adb71556c75f60f5360ee247e71 (Compose and the CI service).
  • 17 (dump only): postgres:17.12-alpine3.24@sha256:f9cf3e1f0066f0eb0c48707d864f0ac5941e9ff454a072077d97a4d278d07d73.
  • The repo uses no Debian variant.

The upgrade test, step by step

  1. matrix-init's real init.sql and kybackup-role.sql on a 17 stack brought up with the Compose files of d83af54 (the last 17 master).
  2. 50,000 Synapse rows, plus a MAS pg_trgm index.
  3. A 17 backup taken the way internal/backup takes one (custom format, as kybackup).
  4. Switch to this checkout's files while 17 runs, then check:
    • 18 is serving from 18/docker with checksums on;
    • Synapse rows survive, with the C collation;
    • the mas trigram query works;
    • synapse, mas, kybackup and postgres log in with their passwords from another container, and a wrong password is refused;
    • kybackup cannot write;
    • pgdata/PG_VERSION is still 17.
  5. matrix-init re-run: kybackup-role.sql applies. Rotation: the new password is refused until role-passwords.sql is applied, then works.
  6. A forced re-create is a no-op ("already done", no restore).
  7. Rollback: master's files start 17 on the untouched data, without the row written on 18. Going forward again keeps that row.
  8. A dump made unrestorable: postgres retries, and 18/docker never appears.
  9. The documented clean-up runs, and 18 keeps starting.
  10. A fresh project: "nothing to move", plain initdb, roles log in.
  11. 18's pg_restore --list, a full read, and a restore with pgRestore's exact flags as the database owners all accept the 17 backup.

Socket-test rerun: TestInstallerLiveActivationRolesAndSignedRevocation passes with TMPDIR=$HOME/.kg on SQLite and on PostgreSQL 18.7 (ok internal/api). The full-suite failure was the 107-byte socket limit on Major only.

KyQuickStart (next worker): the Compose shape to copy.

  • postgres-17-dump:
    • image: the 17 digest; user: KY_MATRIX_UID:GID;
    • entrypoint: [bash, /ky/postgres-17-to-18.sh, dump], env OLD=/v/pgdata, NEW=/v;
    • network_mode: none, restart: "no", read_only, tmpfs /tmp, no-new-privileges, cap_drop ALL;
    • volumes: matrix-postgres:/v and the script read-only.
  • postgres:
    • image: the 18 digest; entrypoint: [bash, /ky/postgres-17-to-18.sh, restore], command: [postgres]; no PGDATA;
    • volumes: matrix-postgres:/var/lib/postgresql, ./matrix/postgres and the script;
    • depends_on: postgres-17-dump: service_completed_successfully; healthcheck start_period: 1h.
  • Under Podman, both services get keep-id and selinux: z on the script bind.

🤖 Generated with Claude Code

… from 17

Matrix's Postgres moves to 18.7 (pinned by digest). A 17 stack upgrades on
its next `docker compose up -d`: the one-shot postgres-17-dump (17.12 image,
no network, read-only root) dumps pgdata/ once into upgrade-from-17/, and the
postgres service restores it into 18/docker on the same volume before the
stock entrypoint runs. Both run scripts/postgres-17-to-18.sh, the suite's
kit v2, byte for byte; it refuses to dump while postmaster.pid exists, and
both services stop with a 2-minute grace so a clean stop removes it. The 17
data is never deleted or written; rolling back is the previous release's
Compose files.

- Dockerfile: postgresql18-client, so the app's pg_dump/pg_restore match.
- Health pins regenerated (postgres 18.7); CI's Postgres suite runs on 18.
- check-compose-matrix holds the layout, the one-shot, the kit's checksum
  and mode; the Podman overlay maps and labels the new bind.
- scripts/test-postgres-17-to-18.sh (CI job postgres-upgrade) seeds 17
  with the last 17 Compose files and proves the move with 17 running, a
  refused dump beside a live 17, passwords over the network, matrix-init
  re-runs and rotation, rerun, rollback, a bad dump, clean-up, a fresh
  install and a 17 backup restored on 18.
- Operator note in docs/CHAT-SETUP.md "PostgreSQL 18".

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-kymessage-server-152, 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

The harness runs Compose with its scratch dir as the project directory
and copied only compose/ and overrides/, so the kit bind
(./scripts/postgres-17-to-18.sh) had no source and every leg failed at
the stack step. Copy the script there too.

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