我正在尝试在Ubuntu 14上使用Postgres运行一个Rails应用程序的Capistrano,但在rake db:migrate
期间遇到了密码错误-
DEBUG [2823f146] Command: cd /home/ben/apps/mll/releases/20160414014303 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.0.0-p645" RAILS_ENV="production" ; $HOME/.rbenv/bin/rbenv exec bundle exec rake db:migrate )
DEBUG [2823f146] rake aborted!
PG::ConnectionBad: fe_sendauth: no password supplied
我尝试了所有类似的解决方案,但还是没有成功。为了好玩,我也尝试在远程应用目录中运行该命令,结果如下:
PG::ConnectionBad: FATAL: password authentication failed for user "mll"
FATAL: password authentication failed for user "mll"
这很有趣,因为它将我的数据库名称用作我的用户名。请参见下面的
database.yml
,所以我添加了一个mll
角色,并且当只运行rake db:migrate
时,它奏效了。不过,我尝试使用这个新角色再次运行Capistrano,仍然没有成功。可以合理地猜测用户名未被正确访问/存储吗?有什么办法可以测试一下呢?我手动为我的
ben
和mll
角色执行了ALTER ROLE ben WITH PASSWORD 'mypw';
,但是没有任何作用。我的database.yml如下:
defaults: &default
adapter: sqlite3
encoding: utf8
development:
<<: *default
database: db/development.sqlite3
test:
<<: *default
database: db/development.sqlite3_test
production:
<<: *default
host: localhost
adapter: postgresql
encoding: utf8
database: mll
pool: 5
username: <%= ENV['DATABASE_USER'] %>
password: <%= ENV['DATABASE_PASSWORD'] %>
\du:
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
ben | Superuser, Create role, Create DB | {}
mll | Superuser, Create role, Create DB | {}
postgres | Superuser, Create role, Create DB, Replication | {}
我看到有些人说将
md5
改为trust
可以帮助解决问题,我尝试过了,但我不确定如何重新启动,我看到的所有命令都没有奏效。
pg_hba.conf:
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
local all all peer
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
SELECT pg_reload_conf();
重启成功了,真是太好了。谢谢。 - Ben