2017-09-21 131 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.