Cannot connect to database on port 5432 – P1001 error and psql connection closed unexpectedly
I’m trying to run Prisma migrations and connect to my Supabase Postgres database, but the direct connection (port 5432) is failing consistently with the following error:
psql: error: connection to server at "aws-0-us-west-1.pooler.supabase.com" (52.8.172.168), port 5432 failed: server closed the connection unexpectedly
psql: error: connection to server at "aws-0-us-west-1.pooler.supabase.com" (52.8.172.168), port 5432 failed: server closed the connection unexpectedly
This probably means the server terminated abnormally before or while processing the request. Port 6543 (pgbouncer) works fine for queries.
Port 5432 (direct) is not responding even via pg_isready.
Prisma throws Error: P1001: Can't reach database server at aws-0-us-west-1.pooler.supabase.com:5432.
Prisma throws Error: P1001: Can't reach database server at aws-0-us-west-1.pooler.supabase.com:5432.
What I’m trying to achieve: Run Prisma migrations using the DIRECT_URL as recommended. I need the direct connection for schema updates and for prisma migrate dev/reset.
What I’ve tried: Verified credentials and tenant ID in the connection string.
Tested multiple networks (WiFi, mobile hotspot, VPN off).
Used both aws-0-us-west-1.pooler.supabase.com and db.<project-ref>.supabase.co hosts.
Verified that the project is active in the dashboard.
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.