I'm trying to deploy a Symfony App using Doctrine ORM, that should connect to a Cloud SQL instance based on PostgreSQL. I would also like to make migrations during the deploy. Unfortunately, the deploy fails because it seems that the app is not able to connect. I already added the necessary permissions to the service account, but I would like to know if there is a way to test if the connection is actually possible from a specific service in App Engine.
This would help me to understand whether the issue is in the connection string/Doctrine configuration, or in the permission/authorization side in GCP.
Thank you
Hi @giangian,
There are a few reasons why you might be unable to connect to Cloud SQL. Here are some common issues and how to troubleshoot them:
Expired SSL/TLS certificates - If your instance is configured to use SSL, go to the Cloud SQL Instances page in the Google Cloud console and open the instance. Open its Connections page, select the Security tab and make sure that your server certificate is valid. If it has expired, you must add a new certificate and rotate to it.
Cloud SQL Auth Proxy version - If you are connecting using the Cloud SQL Auth Proxy, make sure you are using the most recent version. For more information, see Keeping the Cloud SQL Auth Proxy up to date.
Not authorized to connect - If you try to connect to an instance that does not exist in that project, the error message only says that you are not authorized to access that instance.
Can't create a Cloud SQL instance - If you see the Failed to create subnetwork. Router status is temporarily unavailable. Please try again later. Help Token: [token-ID]
error message, try to create the Cloud SQL instance again.
The following only works with the default user ('postgres'): gcloud sql connect --user
- If you try to connect using this command with any other user, the error message says FATAL: database 'user' does not exist. The workaround is to connect using the default user ('postgres'), then use the "\c"
psql command to reconnect as the different user.
PostgreSQL connections hang when IAM db proxy authentication is enabled. - When the Cloud SQL Auth Proxy is started using TCP sockets and with the -enable_iam_login
flag, then a PostgreSQL client hangs during TCP connection. One workaround is to use sslmode=disable
in the PostgreSQL connection string. For example:
psql "host=127.0.0.1 dbname=postgres user=me@google.com sslmode=disable"
Another workaround is to start the Cloud SQL Auth Proxy using Unix sockets. This turns off PostgreSQL SSL encryption and lets the Cloud SQL Auth Proxy do the SSL encryption instead.
You may also see the Debugging connection issues page or the Connectivity section in the troubleshooting page for help with connection problems.
Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.