question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't connect to Cloud SQL Postgres using socket

See original GitHub issue

Bug 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):

  1. Enabling Private IP in our CloudSQL instances
  2. Created a Serverless VPC Connector (with extra charges =/ )
  3. 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:open
  • Created 2 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rained23commented, Jan 26, 2022

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.

1reaction
Verhaegcommented, Jan 25, 2022

@yoshitamagoshi Yes… that was missing… Due to the error message I didn’t think about permissions =/

Thanks for pointing it out!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Connect using Cloud SQL connectors
The Cloud SQL connectors are libraries that provide encryption and IAM-based authorization when connecting to a Cloud SQL instance. They can't provide a ......
Read more >
Missing socket for connection to Cloud SQL from Google ...
I am able to get the connection working with the following configuration: PROJECT=[[YOUR-PROJECT-ID]] REGION=europe-west3 INSTANCE=instance- ...
Read more >
Solved: Cannot connect Cloud Run application to Cloud SQL
The Cloud SQL database is a PostgreSQL db with only a private IP. ... I'm also using the Google Cloud SQL JDBC Socket...
Read more >
Unable to connect cloud SQL postgres
Hi Binya, You should connect either with a unix socket or a TCP connection, but not both. If you include `=tcp:5432` after the...
Read more >
Google Cloud SQL for PostgreSQL Setup Guide
Read step-by-step instructions on how to connect Google Cloud SQL PostgreSQL with your data warehouse using Fivetran connectors.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found