Connect to Cloud SQL (IAM + Cloud SQL Auth Proxy)
This guide explains how to connect to the commercial Cloud SQL database using IAM with the Cloud SQL Auth Proxy.
Prerequisites
- Local tools:
- Google Cloud SDK (
gcloud) installed and logged in:gcloud auth login gcloud config set project cred-1556636033881 -
Cloud SQL Auth Proxy installed:
brew install cloud-sql-proxycurl -o cloud-sql-proxy https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.19.0/cloud-sql-proxy.darwin.arm64 chmod +x cloud-sql-proxycurl -o cloud-sql-proxy https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.19.0/cloud-sql-proxy.linux.amd64 chmod +x cloud-sql-proxy -
Database client
psqlor a GUI (TablePlus, DataGrip, Navicat)
Start the proxy (examples)
Pick your environment and run the proxy in a dedicated terminal:
cloud-sql-proxy cred-dev-data:us-central1:cred-api-commercial-dev \
--auto-iam-authn \
--port 5433
cloud-sql-proxy cred-dev-data:us-central1:cred-api-commercial-staging \
--auto-iam-authn \
--port 5434
cloud-sql-proxy cred-1556636033881:us-central1:cred-api-commercial-prod \
--auto-iam-authn \
--port 5435
You can run multiple proxies at the same time; just use different local ports. Match your client port to the proxy you started (e.g., use port=5434 for staging).
Connect with DataGrip or psql
Passwordless with IAM
When prompted for a password, press Enter and leave it empty. The proxy uses a shortβlived IAM token, so you donβt need to remember or store database passwords.
Steps (DataGrip):
1. New β Data Source β PostgreSQL
2. Host 127.0.0.1, Port for your env (e.g., 5434 for staging)
3. User your.user@credinvestments.com
4. Database <DB_NAME>
5. Leave password empty β Test Connection β OK
Steps (psql):
- Using psql with IAM DB auth:
- Connect with:
psql "host=127.0.0.1 port=5433 dbname=<DB_NAME> user='your.user@credinvestments.com' sslmode=disable"