Skip to content

Upgrade DB images to PostgreSQL 18 / PostGIS 3.7 + upgrade runbook - #2964

Open
atalyaalon wants to merge 26 commits into
new-cbs-formatfrom
claude/gallant-archimedes-nwlpao
Open

atalyaalon wants to merge 26 commits into
new-cbs-formatfrom
claude/gallant-archimedes-nwlpao

Conversation

@atalyaalon

@atalyaalon atalyaalon commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Please review the code and the runbook. Merging this changes no running DB. dfc-iac pins PIN_DB_IMAGE / PIN_DB_BACKUP_IMAGE by hand, and the server migration follows docs/POSTGRES_18_UPGRADE.md, on dfc2 only.

Tasks

dfc2 is production. Since dfc-iac b144ce7 (6 Nov), anyway.co.il and www.anyway.co.il resolve to dfc2. www answers 308 → https://anyway.co.il/, except API and login paths (dfc-iac#33). The site and API read dfc2's DB; this was checked with dig and curl on 2026-11-30. Nobody relies on the old dfc server's Airflow, Reports or DB any more, and dfc-iac#28 shuts it down. So the old dfc DB is not migrated. Which hostnames to keep long-term is a DNS question for dfc-iac#28 (asked here); it doesn't change this PR.

#2965 is merged (2026-11-30, merge commit a620ba63), so this PR's diff now shows only its own changes, and no rebase is needed. It merges cleanly into new-cbs-format, which is now anyway's default branch. Merging this PR redeploys dfc2's app, which is normal and harmless: a deploy never changes the DB images.

Merge order

# PR What Status / why at this point
✅ data-for-change/dfc-iac#27 Deploy workflows only from main Merged 2026-11-30. Manual "Run workflow" runs are also limited to main (job-level if: added in dfc-iac#24).
✅ data-for-change/dfc-iac#24 Monthly dumps, 1-year S3 expiry, thinning of daily dumps Merged and done 2026-11-30: the 1-year expiry rules are applied, and the thinning deleted 155.4 GB. For any later terraform apply, use Terraform 1.17.2 (dfc-iac#34) and targeted applies only.
✅ data-for-change/dfc-iac#30 (replaced #25) Uptime and backup monitors Merged and done 2026-11-30: the monitors run, and the paid Route53 health checks, their alarms and the SNS topic are removed.
✅ data-for-change/dfc-iac#33, #34, #35, #37, #38, #41 www API/login without redirect; Terraform 1.17.2; workflow keepalive; Airflow log and Docker image cleanup; pinned checkout; DKIM records Merged 2026-11-30. No effect on this PR, except that #37 frees disk space on dfc2 (see runbook step 1, "Disk").
✅ data-for-change/dfc-iac#39 (replaced #29) dfc2's unused 500 GB data disk removed Done 2026-11-30. On dfc2, /data was always on the 100 GB root disk, so the migration's disk space comes from there. Runbook step 1 measures it; grow the root disk only if short.
✅ #2965, #2966, #2967, #2968 Newest complete dump for local restores; CORS for https://anyway.co.il; deploy images to ghcr.io; CI actions pinned Merged 2026-11-30 into new-cbs-format. #2965 is deployed to dfc2: the app and nginx were recreated, and the DB container wasn't touched. #2967 still publishes ghcr.io/data-for-change/anyway/db:sha-<7> and db_backup:sha-<7>.
1 data-for-change/dfc-iac#42 Backup image hasadna → data-for-change/anyway/db_backup:sha-a2e64b9 (still PG 15) Any time before runbook step 3, which later changes the same PIN_DB_BACKUP_IMAGE line to this PR's PG 18 tag.
2 1 Dec backup First monthly dump Wait for it and check it on dfc2 before any DB step. Don't merge anything around 00:10 server time.
3 This PR (#2964) PG 18 images, the migration fix, the runbook Changes no DB: no new alembic revision, and deploys never touch PIN_DB_*. After merging, note the db:sha-<7> / db_backup:sha-<7> tags, then close #2961 (see Tasks).
4 dfc-iac PRs from the runbook (steps 3, 4, 7) The actual PG 18 migration, on dfc2 only After the 1 Dec backup is checked and this PR is merged.
5 data-for-change/dfc-iac#28 Shut down the old dfc server (move Vault, Redash, the state DB and DNS to dfc2) After PG 18. It adds Vault, Redash and state DB data to dfc2's root disk.
6 data-for-change/dfc-iac#26 dfc2 instance type → t3a.large Last, and never between the step 5 rehearsal and the step 6 window.

The same table is in the runbook, under "Merge order".

Why

Changes

  • db_docker/Dockerfile: postgis/postgis:18-3.7 pinned by digest (PostgreSQL 18.7, PostGIS 3.7.0, Debian 13 trixie).
  • db_docker/backup.Dockerfile: postgres:18-trixie pinned by digest. The bullseye ca-certificates bootstrap is removed.
  • db_docker/install-aws-cli.sh: the bullseye archive sed lines are removed. They would fail on trixie, which has no /etc/apt/sources.list.
  • db_docker/restore_db.sh:
    • DBRESTORE_SKIP=yes skips the restore. The production migration needs this, so a new empty data dir doesn't auto-restore a partial dump.
    • Missing AWS creds now skip with a warning instead of exit 1. Before, the exit 1 aborted the first start, and CI and local dev only came up because of restart: always.
    • Without DBRESTORE_FILE_NAME, it restores Restore the latest available partial DB dump instead of today's #2965's newest complete partial dump: the newest date with both _anyway_partial and _anyway_partial_schema files, each at least 200 bytes. On top of Restore the latest available partial DB dump instead of today's #2965, this PR only changes exit 1 to return 0 when there's no complete dump, so the DB starts empty with a warning. This file is sourced by the postgres entrypoint, and exit would abort it.
    • psql errors are collected and printed with a count (from workaround due to Bullseye's long-term support ended on 2026-08-31. #2961). The restore still doesn't fail on SQL errors in the dumps, because some are expected.
    • The last step (setting the anyway role password) now reports its errors. It runs with ON_ERROR_STOP, and its stderr goes into the same summary. So if it fails, for a connection error or an SQL error (no anyway role, a quote in the password), the error is counted in the summary and the script prints failed. Errexit doesn't stop the script before the summary.
    • After a successful restore, the exported AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY and the helper function are unset, because the entrypoint sources this file.
    • A header comment documents an old behavior: a failed restore leaves an empty DB after the container restarts.
  • alembic/versions/a1b2c3d4e5f6_add_safety_data_user_system.py: the "drop all non-PK constraints" loop now also skips NOT NULL constraints (contype NOT IN ('p', 'n')). PG 18 stores NOT NULL as named constraints, so on a fresh 18 DB the loop tried to drop users.id's NOT NULL and failed with column "id" is in a primary key. On older versions the behavior is unchanged. Production already ran this migration.
  • docker-compose.yml, docker-compose-tests.yml:
    • Volumes are mounted at /var/lib/postgresql. The PG 18 image refuses a mount at /var/lib/postgresql/data.
    • The volumes are renamed db_data_pg18 / db_tests_data_pg18, so nobody mounts an old PG 15 volume.
  • docs/DOCKER.md: new volume name, and how to switch from the old PG 15 setup.
  • docs/TESTS.md: the steps match CI's (Tests.yml) and the PG 18 test volume. Two waits avoid a race:
    • DB wait over TCP (psql -h 127.0.0.1). Over the unix socket it also succeeded against the temporary server the image runs during init.
    • Wait for the app container (port 5000 inside anyway-tests) before the init steps. Its entrypoint already runs alembic upgrade head, and a manual one at the same time made one of the two fail. The manual line stays as a no-op, to match CI.
  • docs/POSTGRES_18_UPGRADE.md: step-by-step migration runbook for dfc2 (production), covering this repo and dfc-iac. Five independent reviews' findings are applied:
    • Old server access: dump from it with the backup password (DBDUMP_PASSWORD), and re-hash MD5 roles on the 15 server before any dump.
    • Tiger: filtered out of pg_restore and out of the row-count check.
    • cbs DAG: don't dump while it runs, including the manual backups in steps 3 and 8.
    • Error checks: stricter (grep -i, pg_restore exit code).
    • Backups: run them by hand instead of waiting for the monthly schedule. Wait for and check the 1 Dec backup before any DB step.
    • Disk (after dfc-iac#39): on dfc2, /data is on the 100 GB root disk. Step 1 measures free space: the DB data dir is about 22 GB, and the migration needs about 35 GB free (the new data dir, the dump and a margin). That should fit after dfc-iac#37's cleanup; grow the root disk only if short. The step 6 EBS snapshot is of dfc2's root volume.
    • Step 3 test restore: it uses the image's own restore_db.sh, with the S3 reader credentials from secrets/db.env. The quotes are stripped, because docker run --env-file keeps them.
      • The data directory and /tmp are bind-mounted from /data/anyway/pg18test and /data/anyway/pg18test-tmp, with --shm-size=1g, so nothing lands in an anonymous Docker volume that's hard to find and clean up.
      • The /tmp directory needs chmod 1777, because the restore runs as the postgres user.
      • Clean-up is docker rm -fv pg18test and sudo rm -rf of the two literal paths.
    • Step 7 db service: it has no :latest fallback, so a missing PIN_DB_IMAGE fails instead of pulling an old image.
    • Uptime monitor: pause it during the window (dfc-iac#30), then resume it.
    • dfc2 instance type: don't change it (dfc-iac#26) between the rehearsal and the window.
    • Final dump: the pre-pg18-final_ dump expires after 365 days under dfc-iac#24.
    • dfc2 = production: the migration is done only on dfc2. The old dfc server isn't migrated, and dfc-iac#28 shuts it down. Step 10 now says this.
    • Wording: what this PR changes on top of Restore the latest available partial DB dump instead of today's #2965; the Ubuntu 20.04 / psycopg2==2.8.5 follow-up applies to master only (new-cbs-format already has python:3.10-slim-bookworm and psycopg2 2.9).

Things to know

  • PostGIS 3.7 dropped postgis_tiger_geocoder. Old DBs have it, because the 15-3.3 image installed it. Restoring a dump therefore logs tiger errors, which can be ignored. The app doesn't use tiger: geocoding is through Google Maps. The runbook's production restore filters tiger out of pg_restore.
  • Local dev: after pulling, run docker compose build db. Your DB then starts fresh in a new volume, restored from the newest complete partial dump if your .env has the DBRESTORE_AWS_* keys. docker volume rm anyway_db_data removes the old volume.
  • anyway-etl needs no change. It's only a DB client, and its libraries support PG 18.

Testing

  • CI: green on PG 18.7 / PostGIS 3.7 on the previous heads: Tests (alembic upgrade head, data load, pytest), Black and Pylint. Some runs failed in process cities because the public OSM Overpass API returned 429 or couldn't be reached, which is unrelated to this PR; re-runs passed. The latest commits change only docs.
  • Sandbox tests:
    • Start with no AWS creds: the restore is skipped, there's no restart loop, and the DB comes up on PG 18.7 with postgis and postgis_topology 3.7.0.
    • Old mount at /var/lib/postgresql/data: refused by the image, as expected.
    • DBRESTORE_SKIP=yes: skips the restore even with creds set.
    • Automatic restore: a PG 15.1 / PostGIS 3.3 DB with tiger was dumped with pg_dump 18, the same way as dumpdb.sh, then restored by restore_db.sh. Data and views came over. The tiger errors were listed in the summary.
    • Newest-complete-dump selection (Restore the latest available partial DB dump instead of today's #2965's logic plus return 0), with a fake S3 in the PG 18 image:
      • The newest partial has no schema file → the previous complete date is used, and users/roles/organization are restored.
      • The newest dump is complete → it's used.
      • The newest schema file is 783 bytes → accepted, and its tables are restored.
      • The newest schema file is an empty gzip → rejected; the previous complete date is used.
      • A stray … copy key for the newest date → ignored, and the previous complete date is used.
      • Empty bucket → warning, empty DB.
      • Failed listing → AWS's error plus the warning.
      • No case caused a restart.
    • Failing last step, in the real PG 18 image:
      • A password containing a quote → the error is in the summary, failed is printed, and the container exits 1.
      • No anyway role → role "anyway" does not exist is in the summary, and failed is printed.
      • A normal password → it's set, and the DB starts.
    • Step 3 test restore: run with bind mounts and --shm-size=1g. With chmod 1777 on the /tmp directory, the restore completes and no anonymous volume is created.
    • TESTS.md DB wait: during init, the unix-socket check succeeded while the TCP check failed. The TCP check succeeded only after "init process complete".
    • TESTS.md app wait: not run. The app image needs apt, which is blocked in the sandbox. The commands were checked against docker-compose-tests.yml, the Dockerfile and docker-entrypoint.sh.
    • Step 7 compose snippet: docker compose config with ${PIN_DB_IMAGE:?…} fails clearly when the pin is unset.
    • Runbook restore: the pg_dump -Fd / pg_restore -L path, with tiger filtered out, gave zero errors. A second review re-ran it end to end, with MD5 roles, a GiST index and a materialized view, and got identical row counts.
    • Migration fix: reproduced the CI error on PG 18 and confirmed the fixed query.
  • Live checks, 2026-11-30:

Related: #2961, #2962, #2965, #2966, #2967, #2968, data-for-change/dfc-iac#24, #26, #27, #28, #30, #33, #34, #37, #39, #42

🤖 Generated with Claude Code

https://claude.ai/code/session_01XtN7GgrUR4pVhFnxNornau

DB dumps moved from daily to monthly (data-for-change/dfc-iac#24), so a
dump dated today usually won't exist. When DBRESTORE_FILE_NAME is not
set, list the bucket and restore the newest date that has both the
partial and the partial_schema dump, each at least 1 KB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GhfRRihvBTHsWxGZoV
@atalyaalon
atalyaalon force-pushed the claude/gallant-archimedes-nwlpao branch from 36a2cbc to 97fd68e Compare November 29, 2026 21:24
- '|| true' on the listing pipeline: a failed 'aws s3 ls' now reaches the
  'no complete partial dump found' message instead of stopping the sourced
  script silently under set -e / pipefail
- 'NF == 4' in awk: a key like '..._anyway_partial.pgdump.gz copy' no longer
  counts as a second file for that date

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GgrUR4pVhFnxNornau
@atalyaalon
atalyaalon force-pushed the claude/gallant-archimedes-nwlpao branch from 8ad202b to 098e3ca Compare November 29, 2026 23:41

Copy link
Copy Markdown
Collaborator Author

@ziv17, answers to your two questions:

1. Export and import instead of an in-place upgrade?

Yes. That's exactly what this plan does: pg_dump from the old PG 15 server, then pg_restore into a new, empty PG 18 one. We didn't pick pg_upgrade. It needs the old PostGIS 3.3 libraries inside the 18 image, and the base Debian version changes too, which would mean rebuilding text indexes.

Most of the runbook's length (docs/POSTGRES_18_UPGRADE.md) is about doing this safely:

  • Parallel db18 container: the restore goes into a second container next to the old one. We can rehearse on real data and time it with no downtime, and the old data directory stays untouched for rollback.
  • A few PG 18 / PostGIS 3.7 details:
    • the removed tiger geocoder;
    • the password the old server needs for the dump;
    • MD5 passwords;
    • running ANALYZE afterwards, because dumps don't carry planner statistics.

The bare-minimum version is:

  1. Stop the app and Airflow.
  2. pg_dump.
  3. Start the 18 image on a new directory.
  4. pg_restore.
  5. vacuumdb --analyze-in-stages.
  6. Start everything again.

That works too. You just get no timing rehearsal and no side-by-side check before cutting over.

2. Running the tests locally after the PRs merge

docs/TESTS.md was last updated in August 2022. I've updated it in this PR (commit 6118b507) to match what CI runs (.github/workflows/Tests.yml). I checked the steps against the repo and Tests.yml, but I haven't run them end to end locally. It uses the separate test environment, so your dev DB isn't touched:

docker compose -f docker-compose-tests.yml up -d --build
until docker exec db-tests psql -U anyway -d anyway -c "select 1" >/dev/null 2>&1; do sleep 5; done

docker exec anyway-tests alembic upgrade head
docker exec anyway-tests ./main.py process cities
docker exec anyway-tests ./main.py process streets
docker exec anyway-tests ./main.py process registered-vehicles
docker exec anyway-tests ./main.py process cbs --source local_dir_for_tests_only
docker exec anyway-tests ./main.py process road-segments
docker exec anyway-tests ./main.py process junctions

docker exec anyway-tests pip install -r ./test_requirements.txt
docker exec anyway-tests pytest -v tests -m "not browser"

Notes:

  • Fresh DB: after this PR, the test DB uses a new volume (db_tests_data_pg18) and starts empty. That's fine, since the steps above fill it. The old one can be removed with docker volume rm anyway_db_tests_data.
  • process cities: it calls the public OpenStreetMap Overpass API, which sometimes answers 429 Too Many Requests. If it fails, wait a bit and re-run it.
  • Twitter / Google Maps tests: they skip themselves when those keys aren't set, so they're optional.
  • One test: docker exec anyway-tests pytest -svv tests/test_flask.py::test_markers
  • Lint: docker exec anyway-tests bin/pylint.sh and docker exec anyway-tests bin/black.sh.

If something in TESTS.md doesn't work for you, please say so here and I'll fix it.


Generated by Claude Code

A valid schema dump of a few tables gzips to well under 1 KB (a realistic
6-table one is about 1.6 KB), so the 1 KB floor could reject a good dump and
fall back to an older date. 200 bytes still rejects an empty or cut-off
upload: a gzipped empty file is about 20 bytes. A header-only dump (about
400 bytes, no tables) also passes; it restores cleanly.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GgrUR4pVhFnxNornau
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GgrUR4pVhFnxNornau
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GgrUR4pVhFnxNornau
- db: postgis/postgis:18-3.7 (trixie), backup: postgres:18-trixie, both pinned by digest
- install-aws-cli.sh: drop bullseye archive workaround (not needed on trixie)
- restore_db.sh: DBRESTORE_SKIP switch, skip (not abort) on missing AWS creds,
  collect psql errors and print a summary (based on #2961)
- compose: mount volumes at /var/lib/postgresql (PG18 layout), rename volumes
- runbook: branch info, postgis_tiger_geocoder removal in PostGIS 3.7, filtered pg_restore

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GgrUR4pVhFnxNornau
PG18 stores NOT NULL constraints in pg_constraint (contype 'n'), so the
'drop all non-PK constraints' loop tried to drop users_id_not_null and failed
with 'column "id" is in a primary key'. Exclude 'n' too, which matches the
pre-18 behavior exactly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GgrUR4pVhFnxNornau
…sh roles

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GgrUR4pVhFnxNornau
…docs

- row-count check skips tiger tables (not restored on purpose)
- DROP DATABASE ... WITH (FORCE) in the migration window
- rollback: note that reverting also restarts the temporary db18 service
- document that a failed auto-restore leaves an empty DB after restart
- dev docs: rebuild the db image and drop the old PG15 volume

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GgrUR4pVhFnxNornau
- dump from the old server with DBDUMP_PASSWORD (POSTGRES_PASSWORD only applied at initdb)
- re-hash MD5 roles on the 15 server before any dump, so globals.sql carries SCRAM
- rehearsal: avoid/pause the weekly cbs DAG (TRUNCATE vs pg_dump locks)
- error checks: grep -i error + pg_restore exit code
- optional search_path cleanup (tiger schema gone), sudo rm for the cron file

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GgrUR4pVhFnxNornau
Backups may become monthly (dfc-iac #24), so after switching the backup
image (step 3) and after the cutover (step 8) run the backup job by hand
right away. The newest-complete-dump restore itself comes from #2965.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GgrUR4pVhFnxNornau
- restore_db.sh: use #2965's newest *complete* partial dump selection (both
  files >= 1 KB) instead of the newest partial alone; add '|| true' so a failed
  'aws s3 ls' prints the warning instead of silently aborting the entrypoint;
  if no complete dump is found, warn and start empty (return 0)
- runbook: merge order of all related PRs; cbs DAG warning for manual backups;
  remove the pg18test container; pause/resume the uptime monitor (dfc-iac #25)
  in the window; don't change dfc2's instance type (#26) between rehearsal and
  window; pre-pg18-final dump expires after 365 days (#24)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GgrUR4pVhFnxNornau
- restore_db.sh: skip S3 keys with spaces (NF == 4) in the newest-dump
  selection; keep errexit from stopping on a failed last step so the psql
  error summary still prints and the failure is reported
- runbook step 3: test-restore via the image's restore_db.sh with the S3
  reader creds from secrets/db.env (quotes stripped for docker --env-file)
- runbook step 7: no :latest fallback for PIN_DB_IMAGE (fail if unset)
- merge order: rebase note also covers rebase-merge, plus force-push

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GgrUR4pVhFnxNornau
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GgrUR4pVhFnxNornau
Adds the DB init steps CI runs (cities, streets, road-segments, junctions),
a wait loop, the new db_tests_data_pg18 volume, the Overpass 429 retry tip,
and that Twitter/Maps tests skip without keys. Checked against the repo and
Tests.yml, not run end to end locally.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GgrUR4pVhFnxNornau
…S.md waits

- restore_db.sh: take #2965's 200-byte minimum dump size. Run the password
  step with ON_ERROR_STOP and collect its stderr, so an SQL error there (no
  anyway role, a quote in the password) is counted in the summary and
  reported as failed. Unset the exported AWS keys and the helper function
  after a successful restore, because the entrypoint sources this file.
- runbook step 3: the test restore keeps its data dir and /tmp on /data
  (bind mounts, chmod 1777 for /tmp, --shm-size=1g) and cleans them up with
  docker rm -fv plus literal paths.
- runbook: rebase note uses #2965's new head e4d92d0 and git fetch first;
  wording fixes (what #2964 changes on top of #2965, the app image note
  applies to master only).
- docs/TESTS.md: wait for the DB over TCP, so the init-time temporary server
  doesn't count; wait for the app container before the init steps, because
  its entrypoint already runs alembic upgrade head.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GgrUR4pVhFnxNornau
@atalyaalon
atalyaalon force-pushed the claude/gallant-archimedes-nwlpao branch from 6118b50 to 1bd5141 Compare November 30, 2026 00:27
@atalyaalon
atalyaalon marked this pull request as ready for review November 30, 2026 00:35

Copy link
Copy Markdown
Collaborator Author

@tkalir @ziv17, a question before we plan the PostgreSQL 18 migration: which hostnames, and which server, do we want to keep? The answer decides which database we migrate. It also affects data-for-change/dfc-iac#28, which shuts down the old dfc server, and #29, which shrinks dfc2's disk.

Today, from dfc-iac main

Hostname Served by
anyway.co.il (apex), plus www.anyway.co.il → redirect to the apex (since dfc-iac b144ce7, 6 Nov) dfc2
safety-data.anyway.co.il dfc2
airflow.anyway.co.il, airflow-data.anyway.co.il, reports.anyway.co.il, ws.anyway.co.il old dfc
www.dfc2., airflow.dfc2., airflow-data.dfc2., reports.dfc2., safety-data.dfc2.anyway.co.il dfc2

Each server runs its own Airflow, ETL and DB. The public site reads dfc2's DB, while airflow.anyway.co.il still points at the old dfc server's Airflow, which writes to its own DB. dfc-iac#28 adds airflow, airflow-data and reports.anyway.co.il as extra names on dfc2, ahead of moving DNS.

Questions

  1. Long-term names: do we keep the original names (anyway.co.il, airflow.anyway.co.il, reports.anyway.co.il…) and drop the *.dfc2.anyway.co.il ones? The other way round? Or both, as aliases? And should the canonical site be the apex anyway.co.il or www.anyway.co.il?
  2. Which DB is authoritative now: is dfc2's DB the real production data? Does anything still use the old dfc server's DB or its Airflow: Redash, ETL alerts, people working in airflow.anyway.co.il?
  3. Old dfc server's DB: if it's no longer needed, the PG 18 migration would be done only on dfc2, and the old dfc server would simply be shut down by dfc-iac#28 without migrating its DB. Does that sound right?

What I'd suggest, if you agree

  • Treat dfc2 as production for the PG 18 runbook. The parallel db18 rehearsal on dfc2 (runbook step 5) is the real rehearsal.
  • Do the PG 18 migration before dfc-iac#29 shrinks /data. The migration needs room for the old and new data directories plus a dump at the same time.
  • Don't start any DB step until the 1 Dec monthly backup exists and has been checked.

I'll update the runbook once we agree.


Generated by Claude Code

- dfc2 serves anyway.co.il since 6 Nov (checked with dig/curl on 2026-11-30);
  nobody relies on the old dfc server's Airflow/Reports/DB, which dfc-iac #28
  shuts down, so the migration is done on dfc2 only
- wait for and check the first monthly backup (1 Dec) before any DB step
- merge order: dfc-iac #27, #24, #30, #33, #34 merged; add #28 and #29
  (after PG 18); #2966 independent; Terraform 1.17.2; --no-deploy on #2965
  only works with a squash merge

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GgrUR4pVhFnxNornau
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GgrUR4pVhFnxNornau
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GgrUR4pVhFnxNornau
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GgrUR4pVhFnxNornau
…measure free space before the migration

dfc-iac#29 is replaced by #39 (the unused data disk was removed). The
migration needs about data dir + compressed dump + margin (~35 GB), which
most likely fits after dfc-iac#37's cleanup; grow the root disk only if short.
The cutover snapshot is of the root volume.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GhfRRihvBTHsWxGZoV
… backup image

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GgrUR4pVhFnxNornau
@ziv17

ziv17 commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Regarding running the tests locally.
The issue I had is that the loading of the accidents (docker exec anyway-tests ./main.py process cbs --source local_dir_for_tests_only) was failing because accidents already existed in the database.

Can I just checkout the PR's branch and try running the tests? should it work?

@ziv17

ziv17 commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Regarding running the tests locally. The issue I had is that the loading of the accidents (docker exec anyway-tests ./main.py process cbs --source local_dir_for_tests_only) was failing because accidents already existed in the database.

Can I just checkout the PR's branch and try running the tests? should it work?
Hi @atalyaalon ,
Tests do run in my local environment. I do have one more question: Why Tests.yml (the action) loads less data than TESTS.md (e.g. cities, streets, etc.)?

…ment a clean restart

bin/init_test_db.sh CONTAINER runs the migrations and the 6 data loads. CI
(Tests.yml, container anyway) and docs/TESTS.md (anyway-tests) both call it,
so the two can't drift apart again. TESTS.md now says the loads need an empty
test DB and how to start clean (docker compose -f docker-compose-tests.yml down -v).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GhfRRihvBTHsWxGZoV
…moves to a stacked PR

Reverts 48be8ba's script and Tests.yml change (they move to their own PR on
top of this one) and keeps the docs/TESTS.md note on starting from an empty
test DB (docker compose -f docker-compose-tests.yml down -v).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GhfRRihvBTHsWxGZoV

Copy link
Copy Markdown
Collaborator Author

Thanks @ziv17, great that the tests run locally now.

Tests.yml vs TESTS.md: in this PR they load exactly the same data (cities, streets, registered-vehicles, cbs local_dir_for_tests_only, road-segments, junctions). Before this PR it was the other way round: the old docs/TESTS.md on new-cbs-format only loaded registered-vehicles and cbs, so it was out of date with CI.

To keep them from drifting apart again, #2972 (stacked on this PR) moves these steps into one script, bin/init_test_db.sh CONTAINER. CI runs it with anyway, and TESTS.md with anyway-tests. The same change already passed CI here (Tests green on 48be8ba).

"Accidents already exist": that happens when the loads run again on a test DB that already has data. This PR now documents a clean start in TESTS.md:

docker compose -f docker-compose-tests.yml down -v

It removes only the test environment's containers and its db_tests_data_pg18 volume, not your dev DB.


Generated by Claude Code

@ziv17

ziv17 commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Hi @atalyaalon , Thanks!
I waisted a lot of time on this...

@atalyaalon

Copy link
Copy Markdown
Collaborator Author

Hi @atalyaalon , Thanks! I waisted a lot of time on this...

@ziv17 Sorry about that!

Do you have any other thoughts / concerns about the plan?

This branch has not been deployed

No deployments
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.

3 participants