关于ruby on rails:致命:用户“shop”的对等身份验证失败

FATAL: Peer authentication failed for user “shop”

我做了什么:

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

然后我从GitHub(一个使用pg的rails应用程序)克隆了一个存储库,bundle install,编辑database.yml来编写我的密码,现在rake db:create(也是setupmigrate)不起作用。

database.yml

<5233>


请将主机添加到database.yml文件中。 希望它会对你有所帮助。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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

几天前我遇到了同样的错误。

编辑/etc/postgresql/$version/main/pg_hba.conf

您可以在psql控制台中查看您正在使用的版本select VERSION();

里面pg_hba.conf改变

local all postgres peer

至:

local all postgres md5

同行认证解释

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.