I am able to connect fine from psql and node.js, but not from deno using deno-postgres. Why is this?
I am running postgres 15 in docker using the official postgres:15 image. This is the composed service:
db:
image: postgres:15
ports:
- 5432:5432
environment:
POSTGRES_PASSWORD: foo
I can connect to it without any problem using psql
psql postgres://postgres:foo@localhost:5432/postgres
and node.js
const { Client } = require('pg')
const client = new Client('postgres://postgres:foo@localhost:5432/postgres');
client.connect();
but from deno (1.29.2)
import { Client } from 'https://deno.land/x/postgres@v0.16.1/mod.ts';
const client = new Client('postgres://postgres:foo@localhost:5432/postgres');
client.connect();
I get this in the deno log
error: Uncaught (in promise) PostgresError: password authentication failed for user "postgres" throw new PostgresError(parseNoticeMessage(maybe_sasl_final));
And this in the db log
FATAL: password authentication failed for user "postgres"
Found 3 different solutions thanks to spyrospal
The usage seems correct.
You can verify the authentication error by inspecting the log of the db
container. You should be able to see something like this:
FATAL: password authentication failed for user "postgres"
Are you getting any more info from the logs?
The lib seems to have attempted a login using the scram-sha-256 authentication method. Use can see the configured auth methods by inspecting the contents of the pg_hba.conf.
docker exec -it db cat /var/lib/postgresql/data/pg_hba.conf
If the scram-sha-256 method is indeed enabled maybe changing to md5 can help.
Finally, if all fails then you can try to update to v0.17.0
version of the
deno-postgres.