2017-09-21 135 views
0

我在本地创建了Postgresql数据库。 Postgre databaseRuby on Rails身份验证错误postgres

这里是我的database.yml文件。 默认:&默认 适配器:PostgreSQL的 池:5 超时:5000

development: 
    <<: *default 
    database: myrubyblog 
    username: postgres 
    password: Naruto1994. 

# Warning: The database defined as "test" will be erased and 
# re-generated from your development database when you run "rake". 
# Do not set this db to the same as development or production. 
test: 
    <<: *default 
    database: myrubyblog 
    username: postgres 
    password: Naruto1994. 

production: 
    <<: *default 
    database: myrubyblog 
    username: postgres 
    password: Naruto1994. 

我已经确定输入正确的密码,但我仍然得到这个错误。

Error in the code

+0

尝试从密码中删除点?另外,你如何创建你的数据库?你有没有在psql上设置这个密码? – NeoVe

回答

1

您可以添加本地主机,如果你有每个环境(开发,测试和生产)

development: 
    adapter: postgresql 
    encoding: unicode 
    database: myrubyblog_development 
    host: localhost 
    username: postgres 
    password: Naruto1994. 
    pool: 5 

test: 
    adapter: postgresql 
    encoding: unicode 
    host: localhost 
    database: myrubyblog_test 
    username: postgres 
    password: Naruto1994. 
    pool: 5 

production: 
    adapter: postgresql 
    encoding: unicode 
    database: myrubyblog_production 
    pool: 5 
    host: localhost 
    username: #env_variable 
    password: #env_variable 
之间点或没有点(Naruto1994),我建议拆分数据库名密码makesure
1

这样的消息表明您已联系服务器,并且它愿意与您交谈,但直到您通过pg_hba.conf文件中指定的授权方法为止。

试试这个:

// set new password for user "postgres" 
$sudo su postgres -c 'psql --username=postgres' 
ALTER USER postgres with encrypted password 'your_password'; 
//change pg_hba.conf 
local all postgres md5 

然后重新启动Postgres的。

这篇文章可以帮助你:Postgresql: password authentication failed for user "postgres"

0

你只需要添加host: localhost到每个ENV。例如

development: 
    <<: *default 
    database: myrubyblog 
    host: localhost 
    username: postgres 
    password: Naruto1994.