Capistrano,Rails,PG :: ConnectionBad:fe_sendauth:未提供密码

3

我正在尝试在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,仍然没有成功。
可以合理地猜测用户名未被正确访问/存储吗?有什么办法可以测试一下呢?我手动为我的benmll角色执行了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
2个回答

3

pg_hba.conf文件中,应该使用“trust”方法来处理本地主机。请注意,这意味着所有来自本地主机的连接都能够作为任何用户登录,只要您将其用于开发目的,这通常是可以接受的。

# "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。


我感觉自己像个笨蛋,最终使用 SQL SELECT pg_reload_conf(); 重启成功了,真是太好了。谢谢。 - Ben
没问题,我们都经历过那个阶段。 - Anthony E
生产环境方面,有没有一些资源或主题可以让我了解如何确保安全,避免出现这种问题? - Ben
无论密码如何,此解决方案都可行。这将信任所有连接。因此,我们需要使用md5作为最佳实践。 - Anjankumar H N

0

解决此问题的最佳实践是 -

  1. 在开发组下添加以下宝石到您的Gemfile并运行bundle install。

    gem 'capistrano-postgresql'

  2. Capfile中添加以下行

    require 'capistrano/postgresql'

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

    set :pg_password, ENV['DATABASE_PASSWORD']

    set :pg_ask_for_password, true


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接