Skip to content

GCP CloudSQL database connection

Introduction

This document contain information how to connect to GCP Cloud SQL


Use CloudSQL proxy to connect to databases: https://cloud.google.com/sql/docs/postgres/sql-proxySee also Connecting to a database (https://app.clickup.com/2496230/docs/2c5q6-69975/2c5q6-213921)

There is a helper script to set up environment:https://github.com/Attracs/attracs-linux-playbooks/blob/master/gcp/database_access/configure_local_env.yml

"Start CloudSQLproxy with 'connect-cloudsql.sh and it will forward following localhost ports to instances:"
"127.0.0.1:55432 = > attracs-services-195009:attracs-postgre"
"127.0.0.1:33306 = > attracs-services-195009:attracs-sql"
"127.0.0.1:55433 = > att-nightly:attracs-postgre-nightly"
"127.0.0.1:33307 = > att-nightly:attracs-sql-nightly"
"If playbook was successfull, you should have PGAdmin4 with ready made profiles set up."
"Once cloudsqlproxy is up, postgres connection requires *no password authentication*."
"For mysqlworkbench the import is difficult so you need to manually configure connection:"
"1) Use localhost connection from above"
"2) Enable cleartext-plugin "
"3) Run gcloud auth print-access-token to get access token and save it to connection"
"4) Sometimes workbench gives out system error 11, but it might work after restart"
" - "
"IAM authentication tokes are valid for one hour. CloudSQL connector automatically renew token"
"for postgres, but not for MySQL, so token must be recreated manually"
" - "
"To start cloudsqlproxy, enter:"
"connect-cloudsql.sh"