Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Ent package auto migration error: "dial tcp 127.0.0.1:5432: connect: connection refused"

I'm fairly new GCP and cloud SQL and I am having trouble understanding the error I am receiving. I am trying to connect to a cloud sql instance using a cloud sql proxy sidecar. Configurations for cloud sql proxy seems correct, and I am listening on the proper ports. IAM service accounts have cloud sql client connect permissions and etc. 

Within application, connection refusal happens during auto migration, when pods are restarted. 

 

    if err := client.Schema.Create(context.Background()); err != nil {
  logger.Error("error", err)
}

To which I see this error in logs 

{error: dial tcp 127.0.0.1:5432: connect: connection refused, level: error, msg: database error}
 
I can really use some insight; I can provide any other information needed to discuss this issue further. 
0 1 868
1 REPLY 1

Hi @nicolette1,

Welcome to Google Cloud Community!

 

It looks like the connection to the database is being attempted through a loopback address (127.0.0.1). This usually means that the connection is being attempted on the same machine as the application, rather than over the network.
 
There are a few things you can check:
  1. Make sure that the Cloud SQL Proxy is running and is listening on the correct port.
  2. Check the connection string being used by the application to connect to the database. It should specify the hostname or IP address of the Cloud SQL instance, as well as the correct port.
  3. Verify that the IAM service account being used by the application has the correct permissions to connect to the Cloud SQL instance.
  4. Check the network configuration of the application and the Cloud SQL instance to ensure that they can communicate with each other.
It's also possible that the problem could be related to the Cloud SQL instance itself. You can check the Cloud SQL instance's logs for more information about the connection failure.
 
Thank you