Skip to content

Commit 05e72a5

Browse files
make connection logic more forgiving
1 parent 47d631e commit 05e72a5

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

pgconn/pgconn.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,15 @@ func connectPreferred(ctx context.Context, config *Config, connectOneConfigs []*
268268

269269
var pgErr *PgError
270270
if errors.As(err, &pgErr) {
271-
const ERRCODE_INVALID_PASSWORD = "28P01" // wrong password
272-
const ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION = "28000" // wrong password or bad pg_hba.conf settings
273-
const ERRCODE_INVALID_CATALOG_NAME = "3D000" // db does not exist
274-
const ERRCODE_INSUFFICIENT_PRIVILEGE = "42501" // missing connect privilege
271+
// pgx will try next host even if libpq does not in certain cases (see #2246)
272+
// consider change for the next major version
273+
274+
const ERRCODE_INVALID_PASSWORD = "28P01"
275+
const ERRCODE_INVALID_CATALOG_NAME = "3D000" // db does not exist
276+
const ERRCODE_INSUFFICIENT_PRIVILEGE = "42501" // missing connect privilege
277+
278+
// auth failed due to invalid password, db does not exist or user has no permission
275279
if pgErr.Code == ERRCODE_INVALID_PASSWORD ||
276-
pgErr.Code == ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION && c.tlsConfig != nil ||
277280
pgErr.Code == ERRCODE_INVALID_CATALOG_NAME ||
278281
pgErr.Code == ERRCODE_INSUFFICIENT_PRIVILEGE {
279282
return nil, allErrors

0 commit comments

Comments
 (0)