Get Error: FATAL: Peer authentication failed for user “postgres” when use “rake db:create”

1. Open the file pg_hba.conf for Ubuntu it will be in /etc/postgresql/9.x/main and change this line:

local      all     postgres      peer

to

local      all     postgres       trust

2. Restart the postgreSQL server

sudo service postgresql restart

3. Login into psql and set your password

ALTER USER postgres WITH PASSWORD '<new_password>';

4. Finally change the pg_hba.conf from

local      all      postgres      trust

to

local      all      postgres         md5

and restart PostgreSQL server.

After restarting the postgresql server, you can access it with your own password

NoteAuthentication methods details:

trust – anyone who can connect to the server is authorized to access the database

peer – use client’s operating system user name as database user name to access it.

md5 – password-base authentication

Advertisements