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:
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.
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.
Port test results:
Environment details:
OS: Windows 11
Framework: Node.js 20.x
ORM: Prisma @latest
Platform: Supabase hosted Postgres (US West region)
6 Replies
So you are not using the Supavisor 6543 port but PGbouncer 6543 port so are Pro?
You would be better off paying the extra $4 for IPv4 and using the directDB connection if IPv6 is the reason you are using the Supavisor port. edit... I would think the PGbouncer port would be IPv6 only too though in this case...
For your connection using 5432 are you adding your instance id to the user name?
Hey, thanks for the reply.
Yes, I am adding the instance ID to the username. I’m currently on the free plan, not Pro. Are you saying PGbouncer on port 6543 is only available to Pro users? Because in my case, that port connects fine.
The real issue is with the direct DB on port 5432 — it just won’t go through. I even tried pointing my DIRECT_URL to use 6543 for migrations as a workaround, but Prisma hangs and I’ve read in multiple places that running migrations over PGbouncer is not recommended.
For context, I’ve been using this database for a while and 5432 has always worked until today, so this feels like a new or developing issue. I’ve come up with a crude temporary solution, but I really need a proper fix or at least a reliable way around it.
If you are free then you are not using pgbouncer. You are probably using the Supavisor 6543 transaction port which is same setup as 5432 one.
So not sure what you are hitting if both are same address and user with instance id.
So not sure what you are hitting if both are same address and user with instance id.
Okay noted, so I might not know a lot about supabase, how would you suggest I go about solving this problem ?
If you used both the 5432 port with .co (just username) and .com (username and instance id) and got the same error then not likely a connection issue. More something in your Prisma SQL being run.
Any Postgres errors?
If you look in roles in the database tab of dashboard are you close to using all connections... although your error does not imply that.
If you look in roles in the database tab of dashboard are you close to using all connections... although your error does not imply that.
Thank you I will look deeply into this.