Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for connections/connstrings that don't require passwords #2040

Open
kevin-matthew opened this issue Jun 11, 2024 · 1 comment
Open

Comments

@kevin-matthew
Copy link

Is your feature request related to a problem? Please describe.
When using typical connection strings, you can exclude the password part as postgres (by default, on many machines) authenticates the connection via PEER authentication method. This requires no password nor username. Otherwise, there are also settings (in pg_hba.conf) that allows all users to connect to any role without password.

But - as far as I can tell - pgx only authenticates with password-provided methods. Any attempt to use a connstring without a password you get:

failed to connect to `host=localhost user=<user> database=<database>`: failed SASL auth (FATAL: password authentication failed for user "<user>" (SQLSTATE 28P01))

Describe the solution you'd like
Tthe connstrings that exclude passwords should be possible on postgres instances where passwords are not needed.

@jackc
Copy link
Owner

jackc commented Jun 11, 2024

peer authentication only works over a local Unix socket not TCP. You are connecting to localhost which means using TCP. Use a Unix socket (e.g. /tmp/ or /var/run/postgresql) as your host and it should work fine.

If your PostgreSQL socket is in one of the normal places, pgx will default to that if no host is given. And pgx will use the OS user name as user if not otherwise provided. So you conn string might work with just database=<database>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants