我正在使用ubuntu 12.04和rails 3.2。我正在创建一个rails应用程序,我在其中使用了PostgreSQL databse。Rails在应用程序中连接Postgresql数据库ubuntu
sudo apt-get install postgresql
参考我检查出https://help.ubuntu.com/community/PostgreSQL:我使用下面的命令安装的PostgreSQL。后来我创建的用户的Postgres和使用下面的命令
sudo -u postgres psql postgres
\password postgres
接下来,我使用创建的数据库设置密码的Postgres:
sudo -u postgres createdb mydb
我试图在PostgreSQL用户名为Postgres的和密码连接postgres并成功连接以下命令:
psql -U postgres -h localhost
Password for user postgres:
psql (9.1.4)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
postgres=#
在我的Rails应用我的database.yml具有下面的代码:
development:
adapter: postgresql
encoding: unicode
database: mydb_development
pool: 5
username: postgres
password: postgres
test:
adapter: postgresql
encoding: unicode
database: mydb_test
pool: 5
username: postgres
password: postgres
production:
adapter: postgresql
encoding: unicode
database: mydb_production
pool: 5
username: postgres
password: postgres
现在,当我运行命令rake db:migrate
我得到以下错误:
rake aborted!
FATAL: Peer authentication failed for user "postgres"
我尝试添加主机:本地主机数据库.yml为每个环境中,我也得到了以下错误:
rake aborted!
couldn't parse YAML at line 28 column 0
线28
development:
adapter: postgresql
encoding: unicode
database: hackathonio_development
pool: 5
username: postgres
password: testing
host: localhost {This is line 28}
请帮我找出一个解决方案..
做那些mydb_ * DB的存在吗? – dezso 2012-08-14 12:42:12
是否将'host:localhost'添加到每个环境的底部可解决问题? – aguazales 2012-08-14 12:46:59
这里有一个答案:http://stackoverflow.com/questions/9987171/rails-3-2-fatal-peer-authentication-failed-for-user-pgerror – davidrac 2012-08-14 12:47:41