Rails Capistrano 部署 PG::ConnectionBad:严重:密码验证失败

Rails Capistrano deploy PG::ConnectionBad: FATAL: password authentication failed

deploy:migrating
      01 /usr/local/rvm/bin/rvm default do bundle exec rake db:migrate
      01 rake aborted!
      01 PG::ConnectionBad: FATAL:  password authentication failed for user "customuser"
...
Tasks: TOP => db:migrate

1) 我在customuser下可以正常登录psql 2) serverRAILS_ENV=production rake db:migrate 上的命令有效 3) database.yml :

production:
  <<: *default
  database: app_production
  host: localhost
  username: customuser
  password: mypassword

4) /etc/postgresql/10/main/pg_hba.conf :

# "local" is for Unix domain socket connections only
local   all             all                                     md5

也试过peer

已解决。需要添加 gem https://github.com/capistrano-plugins/capistrano-postgresql

deploy.rb

set :pg_without_sudo, false
set :pg_host, 'localhost'
set :pg_database, 'appname_production'
set :pg_username, 'username'
set :pg_ask_for_password, true

我在尝试使用 Capistrano 部署 Rails 应用程序时收到了相同的错误消息并到达此处。

就我而言,我已将虚拟密码硬编码到环境变量中:

DATABASE_URL=postgresql://deploy:PASSWORD@127.0.0.1/myapp

当然,PASSWORD应该是实际密码。

我把它留在这里以防我的愚蠢能帮助到其他人。