Postgres connection refused
Applies to: core
Symptom
Starting pnpm --filter @hivecfm/web dev or running PrismaPrismaThe TypeScript ORM HiveCFM uses to talk to Postgres. The schema lives at packages/database/schema.prisma. against the dev database fails with:
Error: P1001: Can't reach database server at `localhost:5433`Error: connect ECONNREFUSED 127.0.0.1:5433Likely cause
One of three:
- Postgres container is not running.
docker compose up -dwas never issued, or the container exited. - Dev-ports override missing. The default
docker-compose.ymlonly exposes Postgres inside thehivecfm-networkbridge. Port5433on the host is only mapped whendocker-compose.dev-ports.ymlis layered on top. DATABASE_URLpoints at the wrong port..env.localshould uselocalhost:5433;.envinside the Docker stack usespostgres:5432.
Fix
Confirm the container state
cd /home/ubuntu/AG-DEV/hivecfm-core
docker compose psLook for a hivecfm-postgres row in state running / healthy. If it is missing or exited, go to step 2. If it is running, skip to step 3.
Start Postgres with the dev-ports override
docker compose -f docker-compose.yml -f docker-compose.dev-ports.yml up -d postgresThis layers the override that maps the container’s 5432 to 127.0.0.1:5433 on the host.
Check the connection string
Open hivecfm-core/.env.local and confirm:
DATABASE_URL=postgresql://postgres:postgres@localhost:5433/hivecfm?schema=publicIf you edited it to something else (wrong port, wrong host), put it back. .env (not .env.local) uses the in-network hostname postgres:5432 and is only read by containers.
Test connectivity directly
docker exec -it hivecfm-postgres pg_isready -U postgres
psql "postgresql://postgres:postgres@localhost:5433/hivecfm" -c "select 1;"Verify
pnpm --filter @hivecfm/database db:migrate:dev # applies migrations, exits 0
pnpm --filter @hivecfm/web dev # boots without P1001Prevent
- Always start the stack with the dev-ports override when running native dev:
docker compose -f docker-compose.yml -f docker-compose.dev-ports.yml up -d - Do not edit
DATABASE_URLin.env.localaway fromlocalhost:5433unless you actually moved Postgres elsewhere. - If the container keeps crashing on boot, see Docker volumes — a dirty
hivecfm-postgres-datavolume is the usual cause.
Was this page helpful?