You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use 'pgx' driver in one of my project, and one of the user has created an issue related to reading password from .pgpass is not working.
I tried to dig into the problem and found, that UNIX path specified in host parameter of connection settings, is not used for searching the password in pgpass. Instead of this the "localhost" string is used, hence this leads that password is not found.
Steps to reproduce (setting up hba is omitted here, it is supposed that psql is successfully connecting using the .pgpass):
Create .pgpass file
/var/run/postgresql/:5432:postgres:vasya:vasya123
Use the following code to test connection.
func Test_Example(t *testing.T) {
// Make sure that passfile is parsed successfully
passfile, err := pgpassfile.ReadPassfile("/home/lesovsky/.pgpass")
assert.NoError(t, err)
for _, e := range passfile.Entries {
fmt.Println(e)
}
cfg, err := pgx.ParseConfig("host=/var/run/postgresql/ port=5432 user=vasya dbname=postgres")
assert.NoError(t, err)
// password is empty, but must be "vasya123".
assert.Empty(t, cfg.Password)}
After ParseConfig has been done, the Password is empty because "localhost" string is used for searching the password.
It is not critical for me and I have a workaround (use localhost instead of paths in .pgpass), but could you explain reasons of this behavior.
The text was updated successfully, but these errors were encountered:
The host name localhost is also searched for when the connection is a Unix-domain socket connection and the host parameter matches libpq's default socket directory path.
Maybe instead it should try config.Host and if nothing is found and the network is unix then try localhost.
Hi,
I use 'pgx' driver in one of my project, and one of the user has created an issue related to reading password from .pgpass is not working.
I tried to dig into the problem and found, that UNIX path specified in host parameter of connection settings, is not used for searching the password in pgpass. Instead of this the "localhost" string is used, hence this leads that password is not found.
Steps to reproduce (setting up hba is omitted here, it is supposed that psql is successfully connecting using the .pgpass):
After ParseConfig has been done, the Password is empty because "localhost" string is used for searching the password.
It is not critical for me and I have a workaround (use localhost instead of paths in .pgpass), but could you explain reasons of this behavior.
The text was updated successfully, but these errors were encountered: