Postgresql – Cannot login to Postgrest database despite setting password for user ‘postgres’

postgresql

I'm trying to use pgAdmin III to manage my Postgres database.

Here are the commands I've run on my machine:

sudo apt-get install postgresql

Then I installed the pgAdmin III application:

sudo apt-get install pgadmin3

Next I focused on setting my username and password in order to login:

sudo -u postgres psql postgres

Here I set my password
\password postgres

Finally I just created my database:

sudo -u postgres createdb repairsdatabase

When I try to login using pgAdmin III, I get the error:

An error has occurred:

Error connecting to the server: FATAL: Peer authentication failed for user "postgres"

enter image description here

Best Answer

This is a bit of a FAQ.

You're connecting via UNIX sockets, and your pg_hba.conf is set to use peer authentication, so it expects your UNIX user ID to be the same as your PostgreSQL user ID.

Change pg_hba.conf to use md5 for local connections, and/or use TCP/IP by specifying "localhost" as the host instead of leaving the host blank. Local TCP/IP connections might be set to use ident in pg_hba.conf so change that to md5 if it is and if you want to use password auth.

See the PostgreSQL manual on pg_hba.conf for more information, and search Google for your error message.