I have my WSL2 running an Ubuntu 20.04 distro. I have installed my PostgreSQL (12.19) using apt-get
.
I ran sudo passwd postgres
to set password as root
I am able to access the DB from the WSL terminal using the command sudo -u postgres psql
I installed DBeaver on my Windows machine and initiated a connection to PostgreSQL, with the details
host: 127.0.0.1
port: 5432
username: postgres
password: root
This gives me error on test connection: FATAL: password authentication failed for user "postgres"
.
I tried solutions available here on StackOverflow asking me to set sudo ufw allow 5432/tcp
but that too didn't help.
I also tried changing the IPv4 config to set 0.0.0.0/0
with md5 for host which didn't help either.
I had updated the postgresql.conf to listen_addresses = '*'
as mention here. And yet it didn't change the error message that authentication failed.
The server logs just says: User "postgres" has no password assigned
The case seems pretty clear: the database user postgres
has no password, so the password authentication is bound to fail.
I guess you are confused by the difference between an operating system user and a database user. They are something different, even if they have the same name. With sudo passwd postgres
you set the password for thew operating system user, but not for the database user.
To set the database user's password, connect with psql
and run
\password postgres
Remark: using a superuser like postgres
for your first step on a play system is fine. But if you ever plan to use a database seriously, try to be careful not to connect as a superuser more often than absolutely necessary.