capistrano,rails,PG::ConnectionBad:fesendauth:未提供密码



我正试图在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

我尝试了所有类似帖子的解决方案,但没有成功。对于kicks,我还尝试在远程应用程序目录中运行该命令,结果如下:

PG::ConnectionBad: FATAL:  password authentication failed for user "mll"
FATAL:  password authentication failed for user "mll"

这很有趣,因为它使用我的数据库名称作为我的用户名。请参阅下面的database.yml,所以我添加了一个mll角色,您瞧,它在运行rake db:migrate时就起了作用。我试着用这个新角色再次运行Capistrano,但仍然没有成功。

用户名没有被正确访问/存储,这是合理的猜测吗?有什么办法让我测试一下吗?我为我的benmll角色手动ALTER ROLE ben WITH PASSWORD 'mypw';,但什么都没有。

我的数据库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

您应该在pg_hba.conf中localhost的方法下使用"trust"。请注意,这意味着来自localhost的所有连接都可以作为任何用户登录,只要您将其用于开发,这可能是可以的。

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust

更改pg_hba.conf后,您可以使用pg_ctl reload 重新启动postgres

解决问题的最佳实践是-

  1. 将以下gem添加到Gemfile下的开发组和捆绑包安装中。

    gem'capistrano-postgresql'

  2. Capfile中添加以下行

    需要"capistrano/postgresql"

  3. config/deploy.rbconfig/deploy/*.rb中添加以下行

    设置:pg_password,ENV['DATABASE_password']

    设置:pg_ask_for_password,true