From 65ee08e68b814196fed41da2ff180dbf7e4443d4 Mon Sep 17 00:00:00 2001 From: Sunnatulla <264337176+atokim4@users.noreply.github.com> Date: Wed, 2 Dec 2026 12:12:58 +0500 Subject: [PATCH 1/7] docs(setup): check PG_VERSION before upgrading a 2.x relay (#928) (cherry picked from commit ac5eb86fbe7e1672b1e5d8f98e308ab130363e5e) --- docs/SETUP.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/SETUP.md b/docs/SETUP.md index 6487f36af..b37d5a77b 100644 --- a/docs/SETUP.md +++ b/docs/SETUP.md @@ -483,6 +483,30 @@ sudo docker compose logs -f --tail=100 nostream ### Updating the Relay When a new nostream version is released: +> **Coming from 2.x? Check the database version first.** Before 3.0 the compose file used the untagged `postgres` image, so `.nostr/data` was created by whatever major was `latest` at the time: 16, 17 or 18. 3.x pins `nostream-db` to `postgres:15`, and PostgreSQL can't open a data directory made by a newer major: `nostream-db` exits with `FATAL: database files are incompatible with server` and `nostream-migrate` and `nostream` wait on it. Look before you recreate anything: +> +> ```bash +> sudo cat /opt/nostream/.nostr/data/PG_VERSION +> ``` +> +> `15` needs nothing. For any other number, keep running that major with a `docker-compose.override.yml` next to `docker-compose.yml`. `docker compose` in `/opt/nostream` reads it on its own (as long as no `-f` is passed), and `bootstrap.sh` leaves it alone: +> +> ```yaml +> services: +> nostream-db: +> image: postgres:17-bookworm # the number PG_VERSION printed +> ``` +> +> For 16 or 17 use the `-bookworm` variant: the old untagged image was built on Debian 12, and keeping the same C library keeps text indexes sorted the same way. For 18 use `postgres:18` and also set `PGDATA`, because the 18 image looks for its data in `/var/lib/postgresql/18/docker` and refuses to start with a mount at `/var/lib/postgresql/data`: +> +> ```yaml +> services: +> nostream-db: +> image: postgres:18 +> environment: +> PGDATA: /var/lib/postgresql/data +> ``` + 1. Update your repository clone: ```bash cd ~/nostream From b241b7a5aa5bc46a12ef3ed5311629ae09c1d509 Mon Sep 17 00:00:00 2001 From: Sunnatulla <264337176+atokim4@users.noreply.github.com> Date: Wed, 2 Dec 2026 12:13:30 +0500 Subject: [PATCH 2/7] chore(changeset): empty changeset for the #928 docs note (cherry picked from commit c463a355133a72428c2e56ee6f107650ed6a8eee) --- .changeset/docs-setup-pg-version-check.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .changeset/docs-setup-pg-version-check.md diff --git a/.changeset/docs-setup-pg-version-check.md b/.changeset/docs-setup-pg-version-check.md new file mode 100644 index 000000000..4473faad8 --- /dev/null +++ b/.changeset/docs-setup-pg-version-check.md @@ -0,0 +1,4 @@ +--- +--- + +docs: check PG_VERSION before upgrading a 2.x relay From 1ac42ede11f37ff8fb7a5b2d2074d60c121baf40 Mon Sep 17 00:00:00 2001 From: chappie-daemon Date: Wed, 2 Dec 2026 09:00:18 -0500 Subject: [PATCH 3/7] docs(setup): find the 2.x data directory, not only /opt/nostream The version check read /opt/nostream/.nostr/data/PG_VERSION, but a 2.x install ran from the clone and mounted ${PWD}/.nostr/data, so an upgrading operator would have read a path that does not exist and moved on. Name both layouts, say to read whichever exists, and stop when neither does. Also name the commands that read the override and the one that does not: recreate-relay.sh changes into the directory and runs a bare docker compose, while the step 5 helper passes -f docker-compose.yml. Refs #928. --- docs/SETUP.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/SETUP.md b/docs/SETUP.md index b37d5a77b..e03bcf390 100644 --- a/docs/SETUP.md +++ b/docs/SETUP.md @@ -486,10 +486,12 @@ When a new nostream version is released: > **Coming from 2.x? Check the database version first.** Before 3.0 the compose file used the untagged `postgres` image, so `.nostr/data` was created by whatever major was `latest` at the time: 16, 17 or 18. 3.x pins `nostream-db` to `postgres:15`, and PostgreSQL can't open a data directory made by a newer major: `nostream-db` exits with `FATAL: database files are incompatible with server` and `nostream-migrate` and `nostream` wait on it. Look before you recreate anything: > > ```bash -> sudo cat /opt/nostream/.nostr/data/PG_VERSION +> # the directory your compose file mounts at /var/lib/postgresql/data +> sudo cat /opt/nostream/.nostr/data/PG_VERSION # 3.x layout +> sudo cat ~/nostream/.nostr/data/PG_VERSION # a 2.x install that ran from the clone > ``` > -> `15` needs nothing. For any other number, keep running that major with a `docker-compose.override.yml` next to `docker-compose.yml`. `docker compose` in `/opt/nostream` reads it on its own (as long as no `-f` is passed), and `bootstrap.sh` leaves it alone: +> Read whichever of those exists; if neither does, find where the old stack kept its data before you recreate anything, and stop if `PG_VERSION` is missing rather than updating blind. `15` needs nothing. For any other number, keep running that major with a `docker-compose.override.yml` next to `docker-compose.yml`. `docker compose` in `/opt/nostream` reads it on its own, `deploy/recreate-relay.sh` changes into the directory and runs a bare `docker compose` so it reads it too, and `bootstrap.sh` leaves it alone — but a command that names the file with `-f docker-compose.yml`, like the `compose` helper in step 5, does not: > > ```yaml > services: From b59dcd5945b9c49b113dd804a38b05d0e16dc323 Mon Sep 17 00:00:00 2001 From: chappie-daemon Date: Wed, 2 Dec 2026 09:02:14 -0500 Subject: [PATCH 4/7] docs(setup): start the database under the override, and match its C library Two review findings on the 2.x note. The note said to write an override but left it inert: the update steps recreate only nostream and nostream-migrate with --no-deps, and a restart never applies a new image, so a database stopped on the incompatible image stays stopped and the migrate job has nothing to connect to. It now says to bring nostream-db up under the override and wait for pg_isready first. The variant advice assumed the untagged image was Debian 12. PG_VERSION records the major and nothing else, and an untagged pull made after latest moved to Trixie gives a Trixie-based cluster, so -bookworm is not automatically the match; the note now says to read the old image's os-release, names both variant families, and falls back to dump/restore when the base cannot be established. Refs #928. --- docs/SETUP.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/SETUP.md b/docs/SETUP.md index e03bcf390..29a00fd29 100644 --- a/docs/SETUP.md +++ b/docs/SETUP.md @@ -499,7 +499,7 @@ When a new nostream version is released: > image: postgres:17-bookworm # the number PG_VERSION printed > ``` > -> For 16 or 17 use the `-bookworm` variant: the old untagged image was built on Debian 12, and keeping the same C library keeps text indexes sorted the same way. For 18 use `postgres:18` and also set `PGDATA`, because the 18 image looks for its data in `/var/lib/postgresql/18/docker` and refuses to start with a mount at `/var/lib/postgresql/data`: +> For 16 or 17 keep the C library the cluster was created with, because a changed one can invalidate collation-dependent indexes: `PG_VERSION` records the major and nothing else, so check the old image itself before choosing the variant — `sudo docker run --rm --entrypoint cat /etc/os-release` names the Debian release, and `postgres:16-bookworm`/`17-bookworm` (Debian 12) and `postgres:16-trixie`/`17-trixie` (Debian 13) both exist. An untagged pull made after `latest` moved to Trixie gives a Trixie-based cluster, so the older `-bookworm` is not automatically the match; when the image is gone and the base cannot be established, keep the major and dump/restore into a fresh `postgres:15` cluster instead of opening the old directory under a different libc. For 18 use `postgres:18` and also set `PGDATA`, because the 18 image looks for its data in `/var/lib/postgresql/18/docker` and refuses to start with a mount at `/var/lib/postgresql/data`: > > ```yaml > services: @@ -508,6 +508,15 @@ When a new nostream version is released: > environment: > PGDATA: /var/lib/postgresql/data > ``` +> +> Writing the override changes nothing on its own: start the database under it before the migrations in step 4 run, and wait until it accepts connections. +> +> ```bash +> cd /opt/nostream && sudo docker compose up -d nostream-db +> sudo docker compose exec nostream-db pg_isready +> ``` +> +> The update steps below recreate `nostream` and `nostream-migrate` only — `recreate-relay.sh` passes `--no-deps` — and a `restart` never applies a new image, so a database left stopped on the incompatible image stays stopped and the migrate job has nothing to connect to. 1. Update your repository clone: ```bash From 034cd0117e89c5b3ccd8565c761f580c8d4b9df3 Mon Sep 17 00:00:00 2001 From: chappie-daemon Date: Wed, 2 Dec 2026 09:08:31 -0500 Subject: [PATCH 5/7] docs(setup): move the 2.x cluster, and never restore a dump into 15 Three more review findings, all accepted. Reading PG_VERSION under ~/nostream does not move the cluster: /opt/nostream mounts its own .nostr/data and bootstrap creates it empty, so the new project would initialise a fresh database. The note now stops the 2.x stack and moves the directory before starting anything. The database-start step sat before step 2, which is what creates /opt/nostream; it now says to start it once step 2 has run. The dump/restore fallback said to restore into postgres:15, which is wrong: a 17 dump carries settings 15 rejects, and PostgreSQL does not promise a newer dump restores into an older server. It says same major now. Refs #928. --- docs/SETUP.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/SETUP.md b/docs/SETUP.md index 29a00fd29..36154f727 100644 --- a/docs/SETUP.md +++ b/docs/SETUP.md @@ -499,7 +499,7 @@ When a new nostream version is released: > image: postgres:17-bookworm # the number PG_VERSION printed > ``` > -> For 16 or 17 keep the C library the cluster was created with, because a changed one can invalidate collation-dependent indexes: `PG_VERSION` records the major and nothing else, so check the old image itself before choosing the variant — `sudo docker run --rm --entrypoint cat /etc/os-release` names the Debian release, and `postgres:16-bookworm`/`17-bookworm` (Debian 12) and `postgres:16-trixie`/`17-trixie` (Debian 13) both exist. An untagged pull made after `latest` moved to Trixie gives a Trixie-based cluster, so the older `-bookworm` is not automatically the match; when the image is gone and the base cannot be established, keep the major and dump/restore into a fresh `postgres:15` cluster instead of opening the old directory under a different libc. For 18 use `postgres:18` and also set `PGDATA`, because the 18 image looks for its data in `/var/lib/postgresql/18/docker` and refuses to start with a mount at `/var/lib/postgresql/data`: +> For 16 or 17 keep the C library the cluster was created with, because a changed one can invalidate collation-dependent indexes: `PG_VERSION` records the major and nothing else, so check the old image itself before choosing the variant — `sudo docker run --rm --entrypoint cat /etc/os-release` names the Debian release, and `postgres:16-bookworm`/`17-bookworm` (Debian 12) and `postgres:16-trixie`/`17-trixie` (Debian 13) both exist. An untagged pull made after `latest` moved to Trixie gives a Trixie-based cluster, so the older `-bookworm` is not automatically the match; when the image is gone and the base cannot be established, dump and restore into a fresh cluster of the same major, not into 15 — a 17 dump carries settings 15 rejects and PostgreSQL does not promise a newer dump restores into an older server. For 18 use `postgres:18` and also set `PGDATA`, because the 18 image looks for its data in `/var/lib/postgresql/18/docker` and refuses to start with a mount at `/var/lib/postgresql/data`: > > ```yaml > services: @@ -509,7 +509,15 @@ When a new nostream version is released: > PGDATA: /var/lib/postgresql/data > ``` > -> Writing the override changes nothing on its own: start the database under it before the migrations in step 4 run, and wait until it accepts connections. +> Writing the override changes nothing on its own, and reading `PG_VERSION` under `~/nostream` does not put that cluster where the new project looks either: `/opt/nostream` mounts its own `.nostr/data`, which bootstrap creates empty, so the database would initialise a fresh one. Stop the old stack and move the cluster across first: +> +> ```bash +> cd ~/nostream && sudo docker compose down +> sudo mkdir -p /opt/nostream/.nostr +> sudo mv ~/nostream/.nostr/data /opt/nostream/.nostr/data +> ``` +> +> Then, once step 2 has refreshed `/opt/nostream`, start the database under the override before step 4's migrations run, and wait until it accepts connections: > > ```bash > cd /opt/nostream && sudo docker compose up -d nostream-db From d67061965ed926f7089e1d606f347de1adf93bb1 Mon Sep 17 00:00:00 2001 From: chappie-daemon Date: Wed, 2 Dec 2026 09:15:28 -0500 Subject: [PATCH 6/7] docs(setup): a move that lands cleanly, a cache, and the cluster's own password Four review findings, all accepted. mv onto a .nostr/data bootstrap already created drops the cluster into data/data, where PostgreSQL finds no PG_VERSION: the move now refuses a non-empty destination and proves itself by cat-ing PG_VERSION afterwards. settings.yaml was left behind, so a paid relay would come up on image defaults with payments disabled; it is copied and re-owned with the move. down stops the cache as well, and every later step is --no-deps, so the relay could never become ready: the start now brings nostream-cache up too. An existing cluster keeps the password it was created with and POSTGRES_PASSWORD does not change it, so DB_PASSWORD has to be that password (2.x used nostr_ts_relay) or ALTER ROLE has to run first. Refs #928. --- docs/SETUP.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/SETUP.md b/docs/SETUP.md index 36154f727..60caac8c9 100644 --- a/docs/SETUP.md +++ b/docs/SETUP.md @@ -509,22 +509,30 @@ When a new nostream version is released: > PGDATA: /var/lib/postgresql/data > ``` > -> Writing the override changes nothing on its own, and reading `PG_VERSION` under `~/nostream` does not put that cluster where the new project looks either: `/opt/nostream` mounts its own `.nostr/data`, which bootstrap creates empty, so the database would initialise a fresh one. Stop the old stack and move the cluster across first: +> Writing the override changes nothing on its own, and reading `PG_VERSION` under `~/nostream` does not put that cluster where the new project looks either: `/opt/nostream` mounts its own `.nostr/data`, and bootstrap creates it empty, so the database would initialise a fresh one. Stop the old stack and move the cluster across first — but only onto an empty destination, because `mv` onto a directory that already holds files puts the cluster one level too deep and the database will not find `PG_VERSION`: > > ```bash > cd ~/nostream && sudo docker compose down > sudo mkdir -p /opt/nostream/.nostr +> sudo ls -A /opt/nostream/.nostr/data 2>/dev/null # must print nothing; stop and inspect if it does +> sudo rmdir /opt/nostream/.nostr/data 2>/dev/null > sudo mv ~/nostream/.nostr/data /opt/nostream/.nostr/data +> sudo cat /opt/nostream/.nostr/data/PG_VERSION # the move is done only when this prints +> sudo cp -a ~/nostream/.nostr/settings.yaml /opt/nostream/.nostr/settings.yaml 2>/dev/null +> sudo chown 1000:1000 /opt/nostream/.nostr/settings.yaml 2>/dev/null +> sudo chmod 600 /opt/nostream/.nostr/settings.yaml 2>/dev/null > ``` > -> Then, once step 2 has refreshed `/opt/nostream`, start the database under the override before step 4's migrations run, and wait until it accepts connections: +> The moved cluster keeps the database password it was created with, and setting `POSTGRES_PASSWORD` does not change it: whatever `DB_PASSWORD` you give `/opt/nostream/.env` has to be that password (2.x used `nostr_ts_relay`), or set the stored one with `ALTER ROLE` before the migrations run. `settings.yaml` is not optional either — bootstrap leaves it out when it is absent, and the relay then runs on image defaults, so a paid relay comes up with payments disabled. +> +> Then, once step 2 has refreshed `/opt/nostream`, bring up the database under the override **and the cache**, because `down` stopped both and step 4 recreates only the relay and the migrate job: > > ```bash -> cd /opt/nostream && sudo docker compose up -d nostream-db +> cd /opt/nostream && sudo docker compose up -d nostream-db nostream-cache > sudo docker compose exec nostream-db pg_isready > ``` > -> The update steps below recreate `nostream` and `nostream-migrate` only — `recreate-relay.sh` passes `--no-deps` — and a `restart` never applies a new image, so a database left stopped on the incompatible image stays stopped and the migrate job has nothing to connect to. +> `recreate-relay.sh` passes `--no-deps` and a `restart` never applies a new image, so a service left stopped on the incompatible image stays stopped and the migrate job has nothing to connect to. 1. Update your repository clone: ```bash From 2032c9b1546b16fcbe511860c77e19300c9ba5a2 Mon Sep 17 00:00:00 2001 From: chappie-daemon Date: Wed, 2 Dec 2026 09:23:14 -0500 Subject: [PATCH 7/7] docs(setup): an in-place cluster, a copy that must succeed, and the old env Three review findings. A cluster already at /opt/nostream/.nostr/data is where it belongs, and the empty-destination check would have told that operator to stop; the note now says to skip the move in that case. The settings copy swallowed its errors with 2>/dev/null, so a failed cp left a paid relay running on image defaults with payments disabled. The commands now report, and the note says to fix a failure before continuing. A fresh /opt/nostream/.env comes from deploy/env.example, whose values are placeholders, so the note now says to carry the variables the 2.x .env actually set - the payment credentials included - with the database password as the one exception that must match the moved cluster. Refs #928. --- docs/SETUP.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/SETUP.md b/docs/SETUP.md index 60caac8c9..7e2a27a2c 100644 --- a/docs/SETUP.md +++ b/docs/SETUP.md @@ -509,21 +509,23 @@ When a new nostream version is released: > PGDATA: /var/lib/postgresql/data > ``` > -> Writing the override changes nothing on its own, and reading `PG_VERSION` under `~/nostream` does not put that cluster where the new project looks either: `/opt/nostream` mounts its own `.nostr/data`, and bootstrap creates it empty, so the database would initialise a fresh one. Stop the old stack and move the cluster across first — but only onto an empty destination, because `mv` onto a directory that already holds files puts the cluster one level too deep and the database will not find `PG_VERSION`: +> Writing the override changes nothing on its own, and reading `PG_VERSION` under `~/nostream` does not put that cluster where the new project looks either: `/opt/nostream` mounts its own `.nostr/data`, and bootstrap creates it empty, so the database would initialise a fresh one. If the `PG_VERSION` you read was already under `/opt/nostream/.nostr/data`, the cluster is where it belongs and this move is unnecessary. Otherwise stop the old stack and move the cluster across — onto a destination that is empty, because `mv` onto a directory that already holds files puts the cluster one level too deep and the database will not find `PG_VERSION`: > > ```bash > cd ~/nostream && sudo docker compose down > sudo mkdir -p /opt/nostream/.nostr > sudo ls -A /opt/nostream/.nostr/data 2>/dev/null # must print nothing; stop and inspect if it does -> sudo rmdir /opt/nostream/.nostr/data 2>/dev/null +> sudo test -d /opt/nostream/.nostr/data && sudo rmdir /opt/nostream/.nostr/data > sudo mv ~/nostream/.nostr/data /opt/nostream/.nostr/data > sudo cat /opt/nostream/.nostr/data/PG_VERSION # the move is done only when this prints -> sudo cp -a ~/nostream/.nostr/settings.yaml /opt/nostream/.nostr/settings.yaml 2>/dev/null -> sudo chown 1000:1000 /opt/nostream/.nostr/settings.yaml 2>/dev/null -> sudo chmod 600 /opt/nostream/.nostr/settings.yaml 2>/dev/null +> sudo cp -a ~/nostream/.nostr/settings.yaml /opt/nostream/.nostr/settings.yaml +> sudo chown 1000:1000 /opt/nostream/.nostr/settings.yaml +> sudo chmod 600 /opt/nostream/.nostr/settings.yaml > ``` > -> The moved cluster keeps the database password it was created with, and setting `POSTGRES_PASSWORD` does not change it: whatever `DB_PASSWORD` you give `/opt/nostream/.env` has to be that password (2.x used `nostr_ts_relay`), or set the stored one with `ALTER ROLE` before the migrations run. `settings.yaml` is not optional either — bootstrap leaves it out when it is absent, and the relay then runs on image defaults, so a paid relay comes up with payments disabled. +> The copy has to succeed: `settings.yaml` is not optional, bootstrap leaves it out when it is absent, and the relay then runs on image defaults — a paid relay comes up with payments disabled. If `cp` reports an error, fix it before going on rather than continuing without the file. +> +> The relay's own environment carries over too. A fresh `/opt/nostream/.env` comes from `deploy/env.example`, whose values are placeholders, so copy every variable your 2.x `.env` actually set — `ZEBEDEE_API_KEY` and the other payment credentials among them — rather than trusting the defaults. The database is the one variable that works the other way round: the moved cluster keeps the password it was created with, and setting `POSTGRES_PASSWORD` does not change it, so `DB_PASSWORD` has to be that password (2.x used `nostr_ts_relay`), or set the stored one with `ALTER ROLE` before the migrations run. > > Then, once step 2 has refreshed `/opt/nostream`, bring up the database under the override **and the cache**, because `down` stopped both and step 4 recreates only the relay and the migrate job: >