Nikolay Ageev
Nikolay Ageev

Reputation: 601

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) I can normally login to psql under customuser 2) command on serverRAILS_ENV=production rake db:migrate is workling 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

also tried peer

Upvotes: 1

Views: 754

Answers (2)

James Hibbard
James Hibbard

Reputation: 17755

I had a the same error message when attempting to deploy a Rails app with Capistrano and arrived here.

In my case, I had hardcoded a dummy password into an environment variable:

DATABASE_URL=postgresql://deploy:[email protected]/myapp

Of course, PASSWORD should have been the actual password.

I'm leaving this here in case my stupidity helps someone else.

Upvotes: 2

Nikolay Ageev
Nikolay Ageev

Reputation: 601

Solved. Needed to add gem https://github.com/capistrano-plugins/capistrano-postgresql

In 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

Upvotes: 0

Related Questions