capistrano / rails

Official Ruby on Rails specific tasks for Capistrano
http://www.capistranorb.com/
MIT License
867 stars 270 forks source link

Problem with Postgresql db:migrate when deploy #230

Open unavailabl3 opened 5 years ago

unavailabl3 commented 5 years ago
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

hiteshranaut commented 5 years ago

you got any solution for this?

mattbrictson commented 5 years ago

Issues like this where you encounter different behavior in capistrano vs running the same command manually on the server are often due to different environment variables being loaded in those two scenarios. Here is some more background: https://capistranorb.com/documentation/faq/why-does-something-work-in-my-ssh-session-but-not-in-capistrano/

My general suggestion is to manually run env on the server and make note of the environment variables. Then run a capistrano task like this one to see what the environment variables are when using capistrano. If there are differences this may account for the differences in behavior you are seeing.

task :print_env do
  on release_roles(:all) do
    puts capture("env")
  end
end
hiteshranaut commented 5 years ago

thanks for reply I also inserted details directly into database but still getting error PG::ConnectionBad: could not connect to server: Connection refused 01 Is the server running on host "127.0.0.1" and accepting 01 TCP/IP connections on port 5432?

mattbrictson commented 5 years ago

Sorry, I don't have any more ideas. Let us know what you find.

jose2007kj commented 4 years ago

please check here there are few lines added DATABASE_URL=postgresql://deploy:PASSWORD@127.0.0.1/myapp https://gorails.com/deploy/ubuntu/18.04

hiteshranaut commented 4 years ago

Thanks @jose2007kj

for me issue was there was commented database connection on top after removing that commented connect it worked for me.

aesyondu commented 3 years ago

Just would like to share my story. I found out the hard way that dotenv files are unable to parse the $ sign (https://github.com/bkeepers/dotenv/issues/214). My temporary solution was to hardcode the password in my config file.

Also this might be helpful if you want to continue deployment without migration (https://stackoverflow.com/a/28300857). Though the app still wouldn't work without a working (database) password.