capistrano,rails,PG :: ConnectionBad:fe_sendauth:没有提供密码

时间:2016-04-14 03:29:28

标签: ruby-on-rails postgresql capistrano

我试图在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,但仍然没有运气。

是否合理猜测用户名未被正确访问/存储?我有什么方法可以测试吗?我为ALTER ROLE ben WITH PASSWORD 'mypw';ben角色手动mll,没有。

我的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 个答案:

答案 0 :(得分:3)

你应该使用&#34; trust&#34;在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

答案 1 :(得分:0)

解决此问题的最佳做法是-

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

    gem'capistrano-postgresql'

  2. Capfile

    中添加以下行

    需要“ capistrano / postgresql”

  3. config / deploy.rb config / deploy / *。rb

    中添加以下行

    设置:pg_password,ENV ['DATABASE_PASSWORD']

    设置:pg_ask_for_password,正确