'FATAL: password authentication failed for user "postgres" (postgresql 11 with pgAdmin 4)

I recently installed Postgresql 11, during the installation, there's no step to put password and username for Postgres. Now in pgAdmin 4, I wanted to connect the database to server and it's asking me to input password, and I haven't put any in the first place. Any one knows what's going on. Thank you!



Solution 1:[1]

For Windows variant - I too experienced this nasty bug because of pgAdmin for my Windows x64 install of version 9.2. It left my production paralyzed.

In folder C:\Program Files\PostgreSQL\9.2\data or C:\Program Files (x86)\PostgreSQL\9.x\data, you'll find the pg_hba.conf text file.

Find the following lines:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

and change METHOD md5 to "trust" like this:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust

From Windows>Run type "services.msc" and enter find the right PostgreSQL instance and restart it.

Your DB security is now blown wide open! Heed the warning to return it back to md5 after changing the user password expiry time to say year 2099 for all the relevant users.

Solution 2:[2]

Change the password of default use ALTER USER postgres WITH PASSWORD 'new_password';

Solution 3:[3]

Note: CREATE USER is the same as CREATE ROLE except that it implies LOGIN.

$ psql postgres
postgres=# create user postgres with superuser password 'postgres';

Solution 4:[4]

After successfully changing the master password

If you get the same error even after following the master password reset steps Open your command prompt and execute

    psql -U postgres

It will ask you for the password, enter the new password which you set now parallelly open SQL shell(psql) and try again with the new password

Solution 5:[5]

try using psql -U postgres if have put password while installing this is command where you have to use that. Thank you :)

Solution 6:[6]

Option 1: If you use trust

Better change only postgres to trust in the pg_hba.conf, then access your db with postgres super user and add other users and passwords with the power of the postgres super user, then change all other peer to md5.

The steps: In the pg_hba.conf, change

  • local postgres to trust
  • do not change local all to trust,
  • instead change local all from peer to md5 - which means that a right password is enough to login.

See this solution in detail at the second answer of 'Getting error: Peer authentication failed for user "postgres", when trying to get pgsql working with rails'.


Option 2: Use md5, no trust needed (recommended)

This way is even easier because you will need to change the pg_hba.conf only once:

  1. Change any local user from peer to md5, usually:
  • Change local postgres from peer to md5
  • Change local all from peer to md5
  1. Add a postgres pw with the power of your Linux pw only:

     sudo su postgres
     psql (or psql -p <port> if you have more than one PostgreSQL)
     \password
     \q
    

See the accepted answer and the comments of "Getting error: Peer authentication failed for user "postgres", when trying to get pgsql working with rails".

Solution 7:[7]

For Linux user try this

//CHECK POSTGRES IS WORKING OR NOT
sudo systemctl status postgresql

//THIS WILL ACCEPT PORTS
sudo pg_isready
sudo su postgres

//NAVIGATE TO SQL TERMINAL / BASH
psql

//CREATE A NEW USER WITH PASSWORD
CREATE USER shayon WITH PASSWORD 'shayon';

Solution 8:[8]

I have tried all the above mentioned solutions, trust me northing worked! I have resolved the issue by using following commands

  1. psql -U default

  2. \password

Enter new password:

Enter it again:

enter image description here

my username is : default

This worked perfectly for me.

Solution 9:[9]

I solved this problem by changing peer to trust in the file "pg_hba.conf" at local postgres then I restarted the postgres service with the command:

sudo service postgresql restart

That's it.

Solution 10:[10]

I know this is an old question, but I had the same problem, e.g. no dialog for setting password for Postgres during installation with Postgresql 11.

Instead of doing all the file manipulations suggested in the other answers, I deleted Postgresql 11 and installed Postgresql 12, where I was prompted for setting password during installation.

Solution 11:[11]

I currently had a headhache solving this case. A friend helped me I decided to post my solution here.

  1. Open pg_hba.conf in any text editor (you can find this file in your postgres instalation folder > data);
  2. Change all the methods fields to trust (meaning you don't need a password for postgre);
  3. Run in your console this comand: "alter user postgres with password '[my password]';" | psql -U postgres (meaning to alter some user password for [my password] for the user as parameter -U postgres);
  4. Et voilĂ  (don't forget to change back the method from trust for the one that should be best for you).

I hope this help someone someday.

Solution 12:[12]

Follow below stepsif you are using pgAdmin4 and facing error in updating password :

1] Open file "pg_hba.conf" and find "IPv4 local connections"

2] See the value under "Method" column, it must be set to "md5" becase you selected it while installing.

3] Make "md5" value blank and save the file. Restart pgAdmin4 application.

4] Now again set the value back to "md5" and input your password in pgAdmin application.

You should be successfully able to do it.

Solution 13:[13]

  • Loggin to PgAdmin4

Go to

  • Object > Create > Login/Group Role
  • Create the "username" that was named in the psql terminal
  • Create password
  • Give it all the rights
  • Save
  • try the password immediately in the psql terminal.

It worked for me.

Hope this works for you.

Solution 14:[14]

You can use the "superuser" password for the first time.

After that you can use Object > Create > Login/Group Role to change the password for the "postgres" user.

Solution 15:[15]

For those of you who got this error and NONE of these answers helped, I may not have StackOverflow fish for you, but I'll teach you how to fish!

You likely don't have the correct order of lines in the pg_hba.conf file. If you read this PostgreSQL documentation link below, it says this error can be thrown if "no matching entry is found". However, that is NOT always true! Documentation is written by humans and humans make mistakes.

https://www.postgresql.org/docs/current/client-authentication-problems.html

The truth is that a line further up might take precedence, is qualifying and is forcing you to use a password stored in PostgreSQL rather than delegated authentication or some other method. If you are not specifying a password stored in PostgreSQL, then you do not need the LOGIN role attribute. Put a line at the very top of this list with your specific user, authentication protocol, network details and other criteria. Also, many may think that most computers use IPv4. Try IPv6 and you'll be surprised. Once you know the very specific criteria of your issue and place a line at the top, then you have established the ONLY RELIABLE WAY to troubleshoot these pg_hba.conf issues without source code debugging!

Another helpful trick is to create a crapload of Server entries in pg_admin (SQL IDE for PostgreSQL) with all of your users and authentication protocols for testing. When you test different scenarios, you'll instantly know which ones fail.

Also, whenever you change this file, restart the PostgreSQL service, before testing the user.

You're welcome my friend. :)

Solution 16:[16]

windown 11 - postgres 14

  1. open pgAdmin4 - click servers
  2. right-click on your windows user name rule, e.g: MyUserName.
  3. definition tab - enter password, click save.
  4. open/re-open terminal
  5. run: psql "postgres:///"

if you get "MyName database doesn't exist" you're good to go

Solution 17:[17]

This particular situation I'm about to mention probably doesn't come up very often, but I was getting this error as well. After looking into it, it was because I had a local postgres instance listening on port 5433, and I was trying to set up a Kubernetes tunnel to a remote PG instance mapped to local port 5433 as well. It turns out the command I was running was attempting to connect to the local instance rather than the remote instance. When I temporarily stopped the local instance, I was able to connect to the remote instance through the tunnel without changing the psql command I was using.