golang-samples icon indicating copy to clipboard operation
golang-samples copied to clipboard

Following the example with github.com/jackc/pgx/v5 doesn't work

Open sanbor opened this issue 2 years ago • 3 comments

Thanks for stopping by to let us know something could be better!

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

The issue you're having must be related to a file in this repository. We are unable to provide assistance for issues unrelated to samples in this repository.

Please include as much information as possible:

In which file did you encounter the issue?

https://github.com/GoogleCloudPlatform/golang-samples/blob/HEAD/cloudsql/postgres/database-sql/connect_connector_iam_authn.go

Did you change the file? If so, how?

Use github.com/jackc/pgx/v4 instead of github.com/jackc/pgx/v5 and github.com/jackc/pgx/v4/stdlib instead of github.com/jackc/pgx/v5/stdlib.

Set usePrivate to true.

Describe the issue

Following the mentioned code sample, I would get the error

failed to connect to `host=/tmp user=<redacted>-sa@<redacted>.iam database=<redacted>-postgres`: failed to receive message (remote error: tls: protocol version not supported)",

After trial and error, I followed https://pkg.go.dev/cloud.google.com/go/cloudsqlconn#section-documentation and out of curiosity tried github.com/jackc/pgx/v4 instead of github.com/jackc/pgx/v5 and the IAM connection started to work.

It seems something doesn't work with github.com/jackc/pgx/v5 and private IP. I suggest you revert https://github.com/GoogleCloudPlatform/golang-samples/pull/3306 to avoid other people running into this issue. Or even better, make it work with private IP and github.com/jackc/pgx/v5.

Have a nice day!

sanbor avatar Oct 26 '23 12:10 sanbor

Hey @jackwotherspoon

This issue is older but I wanted to raise your attention to it as it looks like it might be something for improvement. Thanks.

iennae avatar Mar 13 '25 05:03 iennae

I will take a look at this, thanks for bringing to my attention @iennae 😄

jackwotherspoon avatar Mar 13 '25 13:03 jackwotherspoon

fyi this is still true today. If you try this example you get:

cannot parse `registeredConnConfig0`: failed to parse as DSN (invalid dsn)

idawson-gl avatar May 21 '25 05:05 idawson-gl