Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'password authentication failed for user "postgres"'

Tags:

postgresql

I have installed PostgreSQL 8.4, Postgres client and Pgadmin 3. Authentication failed for user "postgres" for both console client and Pgadmin. I have typed user as "postgres" and password "postgres", because it worked before. But now authentication is failed. I did it before a couple of times without this problem. What should I do? And what happens?

psql -U postgres -h localhost -W Password for user postgres:  psql: FATAL:  password authentication failed for user "postgres" FATAL:  password authentication failed for user "postgres" 
like image 858
I159 Avatar asked Oct 08 '11 09:10

I159


People also ask

How do I fix postgres password authentication failed?

Restart the PostgreSQL service from the Services control panel ( start->run->services. msc ) Connect using psql or pgAdmin4 or whatever you prefer. Run ALTER USER postgres PASSWORD 'fooBarEatsBarFoodBareFoot'

How do I enable password authentication in PostgreSQL?

PostgreSQL database passwords are separate from operating system user passwords. The password for each database user is stored in the pg_authid system catalog. Passwords can be managed with the SQL commands CREATE ROLE and ALTER ROLE, e.g., CREATE ROLE foo WITH LOGIN PASSWORD 'secret' , or the psql command \password .

What is the default password for postgres user in PostgreSQL?

For most systems, the default Postgres user is postgres and a password is not required for authentication.

How do I login as a user in PostgreSQL?

There are two ways to login PostgreSQL: By running the "psql" command as a UNIX user which is also configured as PostgreSQL user using so-called IDENT/PEER authentication, e.g., " sudo -u postgres psql ". Via TCP/IP connection using PostgreSQL's own managed username/password (using so-called MD5 authentication).


2 Answers

If I remember correctly the user postgres has no DB password set on Ubuntu by default. That means, that you can login to that account only by using the postgres OS user account.

Assuming, that you have root access on the box you can do:

sudo -u postgres psql 

If that fails with a database "postgres" does not exists error, then you are most likely not on a Ubuntu or Debian server :-) In this case simply add template1 to the command:

sudo -u postgres psql template1 

If any of those commands fail with an error psql: FATAL: password authentication failed for user "postgres" then check the file /etc/postgresql/8.4/main/pg_hba.conf: There must be a line like this as the first non-comment line:

local   all         postgres                          ident 

For newer versions of PostgreSQL ident actually might be peer. That's OK also.

Inside the psql shell you can give the DB user postgres a password:

ALTER USER postgres PASSWORD 'newPassword'; 

You can leave the psql shell by typing CtrlD or with the command \q.

Now you should be able to give pgAdmin a valid password for the DB superuser and it will be happy too. :-)

like image 193
A.H. Avatar answered Sep 20 '22 14:09

A.H.


The response of staff is correct, but if you want to further automate can do:

$ sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"

Done! You saved User = postgres and password = postgres.

If you do not have a password for the User postgres ubuntu do:

$ sudo passwd postgres

like image 31
Diego Avatar answered Sep 19 '22 14:09

Diego