post image :date_long | 1 min Read

Connecting to PostgreSQL via Cloud SQL Proxy

**Download a postgresql cloud sql proxy binary''

https://cloud.google.com/sql/docs/postgres/connect-admin-proxy?authuser=1&_ga=2.119700096.-903944264.1624478760

wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy
chmod +x cloud_sql_proxy

**Open this tunnel in one terminal window''

GOOGLE_APPLICATION_CREDENTIALS=/home/jantoth/.google-cloud-keys/wadzpay-dev-cdb0bf1613d2.json

./cloud_sql_proxy  -credential_file=$GOOGLE_APPLICATION_CREDENTIALS -instances=wadzpay-dev:europe-west3:wadzpay-dev-eu-tf=tcp:0.0.0.0:5432

**Connect to SQL instance (with private IP only) from your local''

psql -h 127.0.0.1 --username=postgres --port=5432 --dbname=postgres

**New Firewall rule (default allow) is necessary If having a dedicated VPC''

gcloud compute --project=wadzpay-dev firewall-rules create wadzpat-dev-private-allow-internal --direction=INGRESS --priority=65535 --network=wadzpay-dev-private --action=ALLOW --rules=tcp:0-65535,udp:0-65535,icmp --source-ranges=10.128.0.0/9
author image

Jan Toth

I have been in DevOps related jobs for past 6 years dealing mainly with Kubernetes in AWS and on-premise as well. I spent quite a lot …

comments powered by Disqus