0

I'm using Golang (github.com/jackc/pgx/v4) to try and connect to my compute engine VM instance, but not having any luck, "Unable to connect to database: failed to connect to host=[IP] user=postgres database=postgres: dial error (dial tcp 127.0.0.1:5433: connectex: No connection could be made because the target machine actively refused it.)" after following the postgres install on GCP: https://cloud.google.com/community/tutorials/setting-up-postgres

In golang I'm using pgx.Connect() and this is the DSN I'm passing: dsn = "pgsql:host=[My external VM IP on GCP];port=5432;dbname=[DB name];user=postgres;password=[my pass]"

I have a funny feeling I need to connect to an instance ID, but there's no documentation on what's the correct host I pass or the right DSN format when trying to access a VM on GCP.

2 Answers 2

1

The error message looks like it's trying to connect to 127.0.0.1:5433.

Can you try removing the semicolons from the DSN?

pgx.Connect(context.Background(), "host=[My external VM IP on GCP] port=5432 dbname=[DB name] user=postgres password=[my pass]")
Sign up to request clarification or add additional context in comments.

1 Comment

Removing the semicolons gives me another error: Unable to connect to database: failed to connect to host=[my ip] user=postgres database=[my db]: dial error (dial tcp [my ip]: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)
1

It seems the network tag, (that's found in the VM instance under the firewall needs to be the same) And the proper format is like maxm suggested: pgx.Connect(context.Background(), "host=[My external VM IP on GCP] port=5432 dbname=[DB name] user=postgres password=[my pass]")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.