Skip to content

fix(node): store Postgres data in a named volume - #565

Merged
ltardivo merged 2 commits into
stagingfrom
fix/261-postgres-named-volume
Nov 19, 2026
Merged

ltardivo merged 2 commits into
stagingfrom
fix/261-postgres-named-volume

Conversation

@ClemensLey

Copy link
Copy Markdown
Contributor

Summary

  • Store Postgres data in a Docker volume named bcn-db-<chain>-<network> instead of bind-mounting chain-setup/<chain>/<network>/db-data.
  • npm run clean removes those volumes for every chain and network, and it succeeds when none exist.
  • The db healthcheck passes only when $POSTGRES_DB exists and "Output" is present, and only once pid 1 is postgres. bcn and sync wait for that check. They still wait for node to start.

Workspace issue: Bitcoin-Computer-Secrets/workspace#261

Why

On Docker Desktop, a fresh bind-mounted data directory is owned by the host user. Postgres init writes PG_VERSION, then the temporary server exits because the directory is not owned by the image user. The next start skips initialization, so database bcn and db/db_schema.sql never run. The node and sync containers restart, and the regtest wallet is never created.

A named volume is owned by the image user on Docker Desktop, root Docker, and rootless Docker, so each chain and network keeps its own database.

Tests

On macOS Docker Desktop (arm64), from packages/node with the LTC regtest env:

  • docker compose config resolves the volume to bcn-db-LTC-regtest.
  • npm run up created database bcn, loaded the schema, and created defaultwallet. POST /v1/LTC/regtest/rpc getwalletinfo returned that wallet.
  • Dropping database bcn made node-db-1 unhealthy. docker compose up -d bcn sync exited with container node-db-1 is unhealthy, and bcn and sync stayed stopped.
  • npm run clean removed bcn-db-LTC-regtest.

Not run here: Linux with Docker as root, rootless Docker, an Intel Mac, and EC2.

A bind-mounted data directory on Docker Desktop is owned by the host user, so Postgres init exits before it creates database bcn. A named volume is owned by the image user on every host.

The db healthcheck now requires that database and the Output table, and bcn and sync wait until the db container is healthy. npm run clean removes every bcn-db-<chain>-<network> volume.
The install note still said Postgres data lives under chain-setup. Blockchain data stays in that folder. The database is the bcn-db-<chain>-<network> volume.

@ltardivo ltardivo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@ltardivo
ltardivo merged commit 060d403 into staging Nov 19, 2026
1 check passed
@ltardivo
ltardivo deleted the fix/261-postgres-named-volume branch November 19, 2026 21: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.

2 participants