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

capistrano, rails, PG::ConnectionBad: fe_sendauth: no password supplied

我正在 运行 Capist运行o 上 Ubuntu 14 上使用 Postgres 的 rails 应用程序,我 运行 进入密码错误在 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

我尝试了类似帖子的所有解决方案,但没有成功。为了好玩,我还尝试了 运行ning 只是在远程应用程序目录中使用该命令并得到以下内容:

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

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

用户名 accessed/stored 不正确是否合理?有什么办法让我测试一下吗?我手动 ALTER ROLE ben WITH PASSWORD 'mypw'; 为我的 benmll 角色,什么都没有。

我的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

您应该在 pg_hba.conf 中的本地主机方法下使用 "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. 在开发组和捆绑安装下的 Gemfile 中添加以下 gem。

    gem 'capistrano-postgresql'

  2. Capfile

    中添加以下行

    需要'capistrano/postgresql'

  3. config/deploy.rbconfig/deploy/*.rb[=39中添加以下行=]

    设置:pg_password,ENV['DATABASE_PASSWORD']

    设置:pg_ask_for_password,真