Marcos Hill
Marcos Hill

Reputation: 11

psql: FATAL: password authentication failed for user {user}

I'm pulling my hair out trying to figure out what is wrong.

I am attempting to connect to a local install of postgres 11 on ubuntu 19.

sudo -u postgres psql gives me full access to the psql shell as user postgres. I created a new user and db, granted permissions, set a password, edited the pg_hba.conf file, and restarted the server. I have also ensured that my password is not expired.

Now I expect psql "host=localhost user=marcos port=5433 dbname=reddit sslmode=require" to connect to my database, but I get a password error: "psql: FATAL: password authentication failed for user". I know the password I typed is correct, so what is wrong?

Here are the relevant pg_hba.conf lines:

# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5
# custom rules
host    all             marcos          all                     md5

Upvotes: 1

Views: 2029

Answers (2)

Sharofiddin
Sharofiddin

Reputation: 393

Maybe something is wrong with your old password, try this:

ALTER ROLE marcos WITH ENCRYPTED PASSWORD '<new_password>';

And then connect to your DB with this password.

Upvotes: 0

bhavik
bhavik

Reputation: 19

follow this step for ubuntu/linxs

-> sudo -u postgres psql

-> postgres=#

After that right

->postgres=# \password

Enter new password for user “postgres”:

Enter it again:

Now check, the new password is working successfully.

Upvotes: 1

Related Questions