Skip to content
This repository was archived by the owner on Jul 12, 2025. It is now read-only.
This repository was archived by the owner on Jul 12, 2025. It is now read-only.

Search the password in .pgpass is not working when using UNIX paths. #73

@lesovsky

Description

@lesovsky

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):

  1. Create .pgpass file
/var/run/postgresql/:5432:postgres:vasya:vasya123
  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions