LMM
LMM

Reputation: 27

Cloud run failed to start because of invalid SQL Cloud configuration

I followed the documentation to enable SQL Cloud from a Cloud run. But according to the documentation:

Your container instances are now able to connect to Cloud SQL via the Cloud SQL proxy that is automatically activated and configured. In your code, you can connect to the Cloud SQL instance using the /cloudsql/[CONNECTION NAME] unix socket.

What does mean the last phrase?. Do I need to connect using the usual connection string like: jdbc:postgresql://localhost:5432/${DATABASE_NAME}

In my case this is what prevent the container to start. org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

Also I use the following command to "add" SQL cloud: gcloud beta run deploy --image gcr.io/[PROJECT_ID/[IMAGE_NAME]:[TAG] --add-cloudsql-instances [CONNECTION_NAME]

Upvotes: 0

Views: 831

Answers (1)

Noohone
Noohone

Reputation: 724

An example of connection statement is this one:

import pymysql
connection = pymysql.connect(unix_socket='/cloudsql/' + <INSTANCE_CONNECTION_NAME>,
                             user='<USER>',
                             password='<PASSWORD>',
                             db='<DATABASE>')

You can find more information about this in Google's documentation about connecting to Cloud SQL from external application which uses the Cloud Proxy also.

If you are using the Java. The documentation for the UNIX socket connection can be found here : Cloud SQL Socket Factory for JDBC drivers

Upvotes: 4

Related Questions