gcp cloudsql sqlproxy - ghdrako/doc_snipets GitHub Wiki

gcloud sql instances describe <INSTANCE_NAME> --format='value(connectionName)'

For connectivity over TCP, you must specify a tcp port as part of the instance string. For example, the following example opens a loopback TCP socket on port 3306, which will be proxied to connect to the instance 'my-instance' in project 'my-project'. To listen on other interfaces than localhost, a custom bind address (e.g., 0.0.0.0) may be provided. For example:

        -instances=my-project:my-region:my-instance=tcp:3306
or
        -instances=my-project:my-region:my-instance=tcp:0.0.0.0:3306
When connecting over TCP, the `-instances` parameter is required.
psql "host=127.0.0.1 sslmode=disable dbname=DB_NAME user=USERNAME"

Unix Socket

psql "sslmode=disable host=/cloudsql/INSTANCE_CONNECTION_NAME dbname=DB_NAME user=USERNAME"
cloud_sql_proxy -instances=<PROJECT_ID>:us-central1:staging=tcp:5432
  • -instances: Support comma-separated list of instances which can be exposed via TCP port or renaming the default Unix Domain Sockets.
  • -ip_address_types: A comman-delimited of preferred IP types for connecting to an instance. Like in our use-case we require CloudSQL Auth Proxy to connect to CloudSQL instances using private IP only.
  • -use_http_health_check: Instead of probing the TCP port on which CloudSQL proxy is listening, one can enable HTTP health checks for the proxy, including startup, liveness and readiness probing. Default health check port is 8090 but same can be configured using -health_check_port flag.
⚠️ **GitHub.com Fallback** ⚠️