简体   繁体   中英

Connect Google Compute Engine to Cloud SQL

I have an ubunut Compute Engine instance and a postgres Cloud SQL instance, both part of the same project and both in the same zone. I want to connect to the Cloud SQL from the Compute Engine but am having some trouble

My postgres has the default user setup and a new DB added. I have reserved a static IP for my Compute Engine and added this IP to authorised list in postgres. I've tried connecting (from the cloud shell) both with a python script using psycopg2 and directly from bash using psql. The error messages I get in both cases:

Connection timed out
Is the server running on host "xx.xxx.xxx.xx" and accepting
TCP/IP connections on port 5432?

Address omitted, but it is correct. The thing I can't be sure of is whether postgres is listening on the port as there is no (?) config option for this from the dashboard - though I would assume it to be running on 5432 (default)

Is there anything, either postgres or Google Cloud Infrastructure specific that I have missed?

The most resilient and portable way of connecting to a CloudSQL instance is through the CloudSQL Proxy .

There are several options for using the proxy, but in the docs there are specific instructions for using it from a GCE instance . I encourage you to check that option, as it will allow you to move your infrastructure anywhere without the need to change your code, you'll only need to configure the proxy properly wherever you're deploying your app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM