Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FATAL: Peer authentication failed for user "shop"

What I did:

sudo -u postgres psql
CREATE ROLE shop CREATEDB LOGIN PASSWORD 'kurt1245';

Then I cloned a repository from GitHub (a rails application which uses pg), bundle install, edit database.yml to write my password and now after rake db:create (also setup and migrate) doesn't work.

database.yml:

development: adapter: postgresql encoding: unicode database: shop_development pool: 5 username: shop password: kurt1245 test: adapter: postgresql encoding: unicode database: shop_test pool: 5 username: shop password: kurt1245

like image 450
Darth Nyan Avatar asked Dec 06 '22 16:12

Darth Nyan


2 Answers

Please Add host to your database.yml file. Hope it will help you.

development:
  adapter: postgresql
  encoding: unicode
  host: localhost
  database: shop_development
  pool: 5
  username: shop
  password: kurt1245

test:
  adapter: postgresql
  encoding: unicode
  host: localhost
  database: shop_test
  pool: 5
  username: shop
  password: kurt1245
like image 164
Md. Sahidul Islam Avatar answered Dec 19 '22 02:12

Md. Sahidul Islam


I've had the same error a few days back.

Edit the /etc/postgresql/$version/main/pg_hba.conf

You can check what version you're using in the psql console as select VERSION();

Inside pg_hba.conf change

local all postgres peer

to:

local all postgres md5

Peer Authentication explained

19.3.7. Peer Authentication

The peer authentication method works by obtaining the client's operating system user name from the kernel and using it as the allowed database user name (with optional user name mapping). This method is only supported on local connections.

like image 31
Kevin Etore Avatar answered Dec 19 '22 01:12

Kevin Etore