Search code examples
postgresqlgoogle-cloud-platformtableau-api

How to connect to Postgres database from my local client that located inside google VM instance


I installed Tableu server inside google VM instance. Server is connecting to Postgres database that is working on same server inside Virtual Machine. I'm trying to connect to this database from my local client by follow this guide . I created user, set permissions for this user.

My issue that I can't figure out how to specify proxy setting for VM instance to connect from my local client.

For example: for VM machine we are connecting with this command:

gcloud compute ssh --project=name_of_project --zone=us-central1-a name_of_virtual_machine

But I can’t figure out how to do this with Postgres connection string.

I tried to run https://cloud.google.com/sql/docs/mysql/sql-proxy

 ./cloud_sql_proxy -instances={project_name}:us-central1:{name}=tcp:8060

Then connect with my local client with string:

jdbc:postgresql://127.0.0.1:8060/workgroup

But connection is still blocked


Solution

  • To connect to database in VM, first I did tunnel:

    gcloud compute ssh server_name -- -N -L 8060:localhost:8060
    

    And then connected to database via client with:

    jdbc:postgresql://127.0.0.1:8060/mydbname

    Thanks @guillaume blaquiere for pointing me in right direction.