Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to GCP Cloud SQL using cloud sql proxy

I am following this guide to connect to my GCP Cloud Postgresql - I have a private IP only. When I run

./cloud_sql_proxy -instances=<Instance connection name>=tcp:5432

I get the following (actual references replaced by <Instance connection name>)

2019/04/01 11:46:45 failed to setup file descriptor limits: failed to set rlimit {&{8500 4096}} for max file descriptors: invalid argument
2019/04/01 11:46:45 Listening on 127.0.0.1:5432 for <Instance connection name>
2019/04/01 11:46:45 Ready for new connections
2019/04/01 11:47:28 New connection for <Instance connection name>
2019/04/01 11:49:38 couldn't connect to <Instance connection name>: dial tcp 172.27.160.3:3307: connect: connection timed out

If I run

psql "host=127.0.0.1 sslmode=disable dbname=<db> user=<user> password=<password>"

then I get the following

psql: FATAL:  password authentication failed for user "prodigy"

If run the same psql command from a VM instance on the same network as my cloud SQL then connection is just fine.

like image 260
mr.bjerre Avatar asked Feb 12 '26 15:02

mr.bjerre


2 Answers

Your Cloud SQL instance needs to be in the same client's network in order to connect using its private IP.

It will not be possible to connect Cloud SQL (as is) through its private IP outside of the Google Cloud Platform network. In such a case, you could try Cloud Interconnect [2] in order to extend your on-premise network to Google's network so that you can try your connections and see if that works for you.

On the other hand, when using the Cloud SQL Proxy, you need to state being using private IP [3]. If not specified, the proxy will look for the public IP by default.

Let me know how it goes.


[1] https://cloud.google.com/sql/docs/mysql/private-ip

[2] https://cloud.google.com/interconnect/docs/

[3] https://cloud.google.com/sql/docs/postgres/sql-proxy#private-ip

like image 77
Fabián García Avatar answered Feb 15 '26 06:02

Fabián García


The connection to a Cloud SQL instance using cloud_proxy can happen only if Cloud SQL and cloud_proxy belong the same VPC network [1].

Otherwise cloud_proxy cannot reach Cloud SQL

[1] https://github.com/GoogleCloudPlatform/cloudsql-proxy/issues/164

like image 41
yiorgos Avatar answered Feb 15 '26 04:02

yiorgos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!