4

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

Darth Nyan
  • 359
  • 2
  • 4
  • 13
  • Duplicate of: http://stackoverflow.com/questions/18664074/getting-error-peer-authentication-failed-for-user-postgres-when-trying-to-ge – Loqman Sep 03 '16 at 11:10

2 Answers2

9

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
Md. Sahidul Islam
  • 351
  • 1
  • 3
  • 14
6

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.

Community
  • 1
  • 1
Kevin Etore
  • 1,046
  • 3
  • 14
  • 32