【发布时间】:2012-08-14 12:39:21
【问题描述】:
我正在使用 ubuntu 12.04 和 rails 3.2。我正在创建一个使用 PostgreSQL 数据库的 Rails 应用程序。我使用以下命令安装了 postgresql:
sudo apt-get install postgresql
作为参考,我查看了https://help.ubuntu.com/community/PostgreSQL。后来我创建了用户 postgres 并使用以下命令设置密码 postgres
sudo -u postgres psql postgres
\password postgres
接下来我使用以下方法创建了数据库:
sudo -u postgres createdb mydb
我尝试使用用户名 postgres 和密码 postgres 连接 Postgresql,并通过以下命令成功连接:
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"
我尝试将 host: localhost 添加到每个环境的 database.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}
请帮我找出解决方案..
【问题讨论】:
-
在每个环境的底部添加
host: localhost是否可以解决问题? -
@dezso 你能告诉我一个命令来检查这些数据库是否存在。我检查了很多链接,但没有找到合适的解决方案。
-
试试这个:
psql -U postgres然后\c mydb_production例如。 -
我认为 YAML 中有 2 的缩进?不?奇怪的是你应该得到 yaml 解析错误。
标签: ruby-on-rails database postgresql