Can't connect to Cloud SQL Postgres using socket
See original GitHub issueBug description
According to some other issues, (#1508) and (#8638) there was some issue when trying to connect with sockets and it was changed at least for MySQL.
In our case we use CloudSQL Postgres and configuring Cloud Run to connect to this instance using Cloud Proxy where it creates a socket usually in /cloudsql
folder by creating a new folder inside with the resource link in the format of <project>:<region>:<instance>
and then a file inside .s.PGSQL.5432
.
We set the DATABASE_URL
following all rules, something in the lines of:
postgresql://<USER>:<PASSWORD>@localhost/<DATABASE>?host=/cloudsql/<CLOUDSQL_INSTANCE_RESOURCE_NAME>&schema=public
We tried several combinations but without any success and the error we found was:
Can't reach database server at `/cloudsql/<CLOUDSQL_INSTANCE_RESOURCE_NAME>`:`5432`
Looking at the code it seems to be forcing a TLS connection instead of allowing socket like it does for MySQL.
For now the workaround we are working with is (For anyone facing this issue):
- Enabling Private IP in our CloudSQL instances
- Created a Serverless VPC Connector (with extra charges =/ )
- Attaching our Cloud Run service to this VPC connector and using the private IP
How to reproduce
Configure any socket connection for Postgres and try to connect using this socket.
Expected behavior
Be able to connect to a Postgres instance through UNIX socket connection.
Prisma information
prisma:client clientVersion: 2.29.1
Environment & setup
- Database: Postgres
- Node.js version: 14.17.5
Prisma Version
2.29.1
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (2 by maintainers)
Top GitHub Comments
for my case I am using Nest.js + Prisma, I am not sure it is caused by Prisma or Cloud Run, it only affects some modules. So when I try to call my API that uses Prisma, it throws the
Invalid invocation
but it works on other APIs.So I can say that the error thrown is not really valid because Prisma actually can connect to the DB for different tables.
What I mean is the error happens to a certain table, not all prisma.
@yoshitamagoshi Yes… that was missing… Due to the error message I didn’t think about permissions =/
Thanks for pointing it out!