【问题标题】:capistrano, rails, PG::ConnectionBad: fe_sendauth: no password suppliedcapistrano, rails, PG::ConnectionBad: fe_sendauth: 未提供密码
【发布时间】:2016-04-14 03:29:28
【问题描述】:

我正在尝试在 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';,什么都没有。

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

【问题讨论】:

    标签: ruby-on-rails postgresql capistrano


    【解决方案1】:

    您应该在pg_hba.conf 中的localhost 方法下使用“信任”。请注意,这意味着来自 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

    【讨论】:

    • 我觉得自己像个傻瓜,终于用 SQL SELECT pg_reload_conf(); 重新启动它,该死的,它成功了。谢谢。
    • 没问题,我们都去过那里。
    • 生产方面的情况如何,我可以阅读的任何资源/主题,以及如何确保安全而不遇到此问题?
    • 无论密码如何,此解决方案都可以正常工作。这将信任所有连接。所以我们需要使用 md5 作为最佳实践。
    【解决方案2】:

    解决问题的最佳做法是 -

    1. 在您的 Gemfile 中添加以下 gem 并在开发组下进行捆绑安装。

      gem 'capistrano-postgresql'

    2. Capfile

      中添加以下行

      需要“capistrano/postgresql”

    3. config/deploy.rbconfig/deploy/*.rb

      中添加以下行

      设置 :pg_password, ENV['DATABASE_PASSWORD']

      设置 :pg_ask_for_password, true

    【讨论】:

      猜你喜欢
      • 2014-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-25
      • 2019-07-23
      • 2015-12-17
      • 2016-10-15
      • 1970-01-01
      相关资源
      最近更新 更多