rails icon indicating copy to clipboard operation
rails copied to clipboard

Problem with Postgresql db:migrate when deploy

Open unavailabl3 opened this issue 5 years ago • 7 comments

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 server RAILS_ENV=production rake db:migrate is workling
  3. database.yml :
production:
  <<: *default
  database: app_production
  host: localhost
  username: customuser
  password: mypassword
  1. /etc/postgresql/10/main/pg_hba.conf :
# "local" is for Unix domain socket connections only
local   all             all                                     md5

also tried peer

unavailabl3 avatar Apr 24 '19 10:04 unavailabl3

you got any solution for this?

hiteshranaut avatar Jul 19 '19 14:07 hiteshranaut

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

mattbrictson avatar Jul 19 '19 23:07 mattbrictson

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?

hiteshranaut avatar Jul 20 '19 04:07 hiteshranaut

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

mattbrictson avatar Jul 20 '19 16:07 mattbrictson

please check here there are few lines added DATABASE_URL=postgresql://deploy:[email protected]/myapp https://gorails.com/deploy/ubuntu/18.04

jose2007kj avatar Nov 26 '19 07:11 jose2007kj

Thanks @jose2007kj

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

hiteshranaut avatar Nov 26 '19 10:11 hiteshranaut

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.

aesyondu avatar Sep 15 '20 17:09 aesyondu