Google Cloud PostgreSQL Managed Instance with Cloud SQL Proxy
Google Cloud
6 August 2025

Google Cloud PostgreSQL Managed Instance with Cloud SQL Proxy

In this guide, we walk through how to securely connect to a Google Cloud PostgreSQL Managed Instance (Cloud SQL) using an authorize IP and Cloud SQL Proxy for your local development environment.

Google Cloud SQL doesn’t allow raw TCP connections to a managed database instance for local connection even if you enable an external internet-accessible IP address and authorize your network. You must use the Cloud SQL Proxy, which handles connection encryption with IAM authentication.

Please note that

  • I'm using Cloud SQL (Managed PostgreSQL) in this guide, not installing a VM with PostgreSQL.
  • I'm running this on macOS, but the steps are similar for Linux/Windows.
  • I already enable an external internet-accessible IP address and authorize my network in the Cloud SQL instance settings.
  • I have the gcloud command-line tool installed and configured.

1. Install the Cloud SQL Proxy (macOS)

brew install cloud-sql-proxy

2. Authenticate with GCP

gcloud auth application-default login

This will open a browser window to authenticate your GCP account and set up application default credentials.

3. Start the Cloud SQL Auth Proxy

Run the proxy to expose your Cloud SQL instance at localhost:5432:

cloud-sql-proxy \
  --port=5432 \
  YOUR_PROJECT_ID:REGION:INSTANCE_NAME

Example:

cloud-sql-proxy \
  --port=5432 \
  syaeful-web-210801:asia-southeast2:test-postgre-syaeful

Example expected output:

2025/08/06 12:49:53 Authorizing with Application Default Credentials
2025/08/06 12:49:53 [syaeful-web-210801:asia-southeast2:test-postgre-syaeful] Listening on 127.0.0.1:5432
2025/08/06 12:49:53 The proxy has started successfully and is ready for new connections!

4. Connect to PostgreSQL using psql

psql -h 127.0.0.1 -p 5432 -U postgres

Enter your PostgreSQL password when prompted.