Fix Prisma P1001: 'Can't reach database server at host:port'
Troubleshoot network connectivity, SSL certificates, wrong port mappings, and environment variable issues with Prisma ORM.
PrismaClientInitializationError: Can't reach database server at `localhost`:`5432` (P1001)
# Test TCP port connection: nc -zv db 5432 # If using Docker Compose, ensure both services share the same network: # services: # web: # environment: # - DATABASE_URL=postgresql://user:pass@db:5432/production_db?schema=public # depends_on: # db: # condition: service_healthy
Root Cause & Mechanism Analysis
Why does this error occur?
Database container is not running, incorrect hostname (using `localhost` instead of Docker container name or `host.docker.internal`), or missing SSL flags (`sslmode=require`).
Frequently Asked Questions
How to connect from Docker container to host machine?
Related Developer Error Solutions
Browse All 35 GuidesPostgreSQL: Remaining Connection Slots Reserved
Resolve PostgreSQL connection exhaustion caused by connection leaks or missing pooling with PgBouncer / Prisma Accelerate.
Docker: Bind for 0.0.0.0:Port Failed
Identify and terminate conflicting host processes or adjust Docker port mapping to resolve port bind collisions.
SQLite: Database is Locked (SQLITE_BUSY)
Resolve SQLite file lock contention during concurrent write transactions by enabling Write-Ahead Logging (WAL) and setting busy_timeout.