0

I'm trying to deploy a Springboot application on Cloud Run and running into the issue of connection not getting connected for Prostgres Cloud SQL. I tried everything possible that I know of including the guide here but still get this error

unable to obtain isolated JDBC connection [The connection attempt failed.] 

Can someone please help me here?

Here is my config file

spring:
  cloud:
    gcp:
      project-id: my_project_id
      secretmanager:
        enabled: true
      sql:
        instance-connection-name:  ${INSTANCE_UNIX_SOCKET}
        database-name: ${DB_NAME}
        enabled: true
  datasource:
    # url: ${JDBC_DB_URL}
    # driverClassName: org.postgresql.Driver
    username: ${JDBC_DB_USERNAME}
    password: ${JDBC_DB_PASSWORD}
    initialization-mode: always

2 Answers 2

1

Your config is not configured correctly I believe:

spring:
  cloud:
    gcp:
      project-id: my_project_id
      secretmanager:
        enabled: true
      sql:
        instance-connection-name:  ${INSTANCE_UNIX_SOCKET}

As per the Spring GCP Cloud SQL documentation the instance connection name should take the format of my-project:my-region:my-instance.

Sign up to request clarification or add additional context in comments.

Comments

0

I think I’m having a similar issue with the golang sample. Using the Unix socket results in auth failure and I need to use the first party cloud SQL connector: https://github.com/GoogleCloudPlatform/golang-samples/blob/main/cloudsql/mysql/database-sql/connect_connector.go

In the past Unix socket connections have worked but within the last three or so months it seems to have stopped working.

A work around I found is to login to the DB manually using either the cloud shell or the sql auth proxy https://cloud.google.com/sql/docs/mysql/connect-auth-proxy And then redeploy the app and it seems to connect then.

3 Comments

the Unix socket example should still work... that is strange and I would love to hear more about your use-case. What database version are you using?
you can also open an issue on the github.com/GoogleCloudPlatform/golang-samples repo with more detail and I will investigate it for you :)
looks like you are using caching_sha2_password auth, this is currently not supported via the Proxy with Unix sockets unfortunately. We are working to fix this, in the meantime using the Go Connector or any of the other language Connectors is a great alternative.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.