On my Ubuntu machine, I have installed postgres 15. I created a new superuser called "test" (with password "test"). Then, I created a database called "test" as well and granted all privileges to the user test. Here the sequence of steps I made:
# Create a new user on Ubuntu
sudo adduser test
# Create the user test on postgres
sudo -u postgres psql postgres;
CREATE USER test SUPERUSER;
ALTER USER test WITH PASSWORD 'test';
exit;
# Login with test to create the DB and being the owner of the DB
sudo -u test psql postgres;
CREATE DATABASE test;
GRANT ALL PRIVILEGES ON DATABASE test TO test;
exit;
From psql, when I try the following I can successfully connect:
psql -d test -U test
However, If I try:
psql postgresql://test:test@localhost:5432/test
I get: psql: error: connection to server at "localhost" (127.0.0.1), port 5432 failed: FATAL: password authentication failed for user "test"
I browsed on the internet, but without any success. This is the relevant part of mu pg_hba.conf file.
Any help?
SELECT rolpassword FROM pg_authid WHERE rolname = 'test';
? The start of the result string will show us how your password is hashed. You can simply remove thelocalhost
from the URL, and the connection should work again.psql postgresql://test:test@:5432/test
to get a socket connection. Did you reload PostgreSQL to make sure the config file is actually used? What exactly is the error message in the PostgreSQL log?