Cloud SQL

Create a PostgreSQL Instance

Example

gcloud sql instances create shop-db \
  --database-version=POSTGRES_16 \
  --region=asia-south1 \
  --tier=db-custom-1-3840 \
  --availability-type=REGIONAL \
  --backup-start-time=02:00
gcloud sql databases create shop --instance=shop-db
gcloud sql users create app --instance=shop-db --password=change-me

Example output

Creating Cloud SQL instance for POSTGRES_16...done.
NAME     DATABASE_VERSION  LOCATION       TIER              PRIMARY_ADDRESS  STATUS
shop-db  POSTGRES_16       asia-south1-a  db-custom-1-3840  34.93.10.20      RUNNABLE

Connecting Securely

  • From Cloud Run: --add-cloudsql-instances shop-prod-1234:asia-south1:shop-db, then connect through the Unix socket /cloudsql/<connection-name>.
  • From your laptop: the Cloud SQL Auth Proxy handles IAM authentication and encryption.
  • Prefer a private IP in your VPC over a public IP with authorized networks.
  • REGIONAL availability adds a standby in another zone with automatic failover.

Note: Cloud SQL is billed while the instance runs, even when idle. Stop dev instances you are not using.