Skip to content

fix(dev): resolve postgres port conflict with local PostgreSQL installations#9

Open
deangoodmanson wants to merge 4 commits into
developfrom
fix/postgres-port-conflict
Open

fix(dev): resolve postgres port conflict with local PostgreSQL installations#9
deangoodmanson wants to merge 4 commits into
developfrom
fix/postgres-port-conflict

Conversation

@deangoodmanson
Copy link
Copy Markdown
Collaborator

@deangoodmanson deangoodmanson commented Feb 19, 2026

Summary

  • Changes Docker postgres port binding from 5432:5432 to ${POSTGRES_PORT:-5432}:5432 to allow overriding the host-side port via environment variable
  • Adds .env loading to scripts/test.sh so POSTGRES_PORT and POSTGRES_PASSWORD are picked up automatically
  • Updates .env.example to document how to use POSTGRES_PORT=5433 when a local PostgreSQL installation conflicts on port 5432
  • Adds troubleshooting docs for the local PostgreSQL port conflict scenario, including diagnosis and resolution steps

Problem

On developer machines with a local PostgreSQL installation, both the local server and Docker bind to port 5432. TCP connections from the host (used by cargo test and scripts/test.sh) silently hit the local server instead of Docker, causing role "kruxiaflow" does not exist errors.

This was discovered via lsof -i :5432 showing two processes on the same port.

Test plan

  • Start Docker postgres: docker-compose up -d postgres
  • Run tests: ./scripts/test.sh --skip-db-setup (with DATABASE_URL pointing to port 5432)
  • Or run full suite: ./scripts/test.sh
  • Confirm test_invalidate_cache_key_requires_auth and related cache handler tests pass
  • On a machine with local PostgreSQL: set POSTGRES_PORT=5433 in .env, restart the postgres container (docker-compose up -d postgres), run ./scripts/test.sh, confirm tests pass with no role "kruxiaflow" does not exist error

🤖 Generated with Claude Code

macOS developers with a local PostgreSQL installation experienced
"role kruxiaflow does not exist" errors when running tests, because
both the Docker container and the local server bound port 5432 and
host TCP connections landed on the local server.

Changes:
- docker-compose.yml: expose Docker postgres on ${POSTGRES_PORT:-5433}:5432
  so it no longer conflicts with a local postgres on 5432
- scripts/test.sh: load .env before setup so POSTGRES_PASSWORD and
  POSTGRES_PORT are available; use ${POSTGRES_PORT:-5433} for DB_PORT
- .env.example: document POSTGRES_PORT with updated default and rationale

Container-internal references (postgres:5432) are unchanged — those
communicate over Docker's internal network and are unaffected.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread docker-compose.yml Outdated
- "log_min_duration_statement=100"
ports:
- "5432:5432"
- "${POSTGRES_PORT:-5433}:5432"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd rather default to 5432 but I agree with having an override to other ports.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The defaults are now reset to 5432
The ports environment variable overrides are still included
The potential conflict between local and docker PostgreSQL is noted in the documentation

Per review feedback, 5432 is the standard port and should remain the
default. Developers with a local PostgreSQL installation can set
POSTGRES_PORT=5433 (or any free port) in their .env to avoid conflicts.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@deangoodmanson
Copy link
Copy Markdown
Collaborator Author

Updated in d7898d9 — reverted default back to 5432, kept the POSTGRES_PORT override. Updated the .env.example comment to explain the local-PG conflict scenario and how to opt in to using 5433.

deangoodmanson and others added 2 commits March 7, 2026 20:55
…ting

CI runners have no local PostgreSQL so the example should use the
standard 5432. Added a troubleshooting section explaining the port
conflict scenario and how to resolve it with POSTGRES_PORT.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@deangoodmanson
Copy link
Copy Markdown
Collaborator Author

Sonnet PR review 3/20/26:

PR #9 Review — fix(dev): resolve postgres port conflict with local PostgreSQL

Core fix is correct. The ${POSTGRES_PORT:-5432}:5432 approach in docker-compose and the .env loading in test.sh
work properly together. The main issues:

Medium

  1. POSTGRES_PORT format inconsistency — REDIS_PORT and KRUXIAFLOW_PORT accept host:port format (e.g.
    127.0.0.1:6379) to control interface binding. The old POSTGRES_PORT did too. This PR drops that, silently
    changing the default PostgreSQL bind from 127.0.0.1 to 0.0.0.0 (all interfaces). That's a mild security
    regression worth an explicit decision.

  2. Unannounced platform: linux/amd64 — The diff adds this to postgres, redis, and kruxiaflow services. Not
    mentioned in the PR description. On M-series Macs this forces Rosetta 2 emulation, silently degrading
    performance. Needs to be called out and justified.

Low

  1. Stale review thread — seanharrison's existing thread was substantively addressed (default is now 5432, not
  1. but not marked resolved.
  1. Troubleshooting docs incomplete — The new troubleshooting section tells developers to manually set
    DATABASE_URL, but test.sh auto-constructs it when running DB setup. Confusing for the --skip-db-setup case.

  2. Latent bug — If someone sets POSTGRES_PORT=127.0.0.1:5433 (copying the pattern from REDIS_PORT), test.sh would
    produce an invalid DATABASE_URL. Should guard against this or document clearly it's port-only.

Info

  • Pre-existing: docs/testing.md CI example references postgres:15 and actions/checkout@v3 while the actual
    workflow uses postgres:17-bookworm and v4.
  • Unrelated whitespace cleanup mixed into the diff adds noise.

The platform: linux/amd64 addition is the thing I'd push back on hardest before approving — it's the kind of
change that causes mysterious slowness on ARM machines with no obvious cause.

@deangoodmanson deangoodmanson added the help wanted Extra attention is needed label Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wanted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants