rails
rails copied to clipboard
Problem with Postgresql db:migrate when deploy
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
- I can normally login to psql under customuser
- command on server
RAILS_ENV=production rake db:migrate
is workling - database.yml :
production:
<<: *default
database: app_production
host: localhost
username: customuser
password: mypassword
- /etc/postgresql/10/main/pg_hba.conf :
# "local" is for Unix domain socket connections only
local all all md5
also tried peer
you got any solution for this?
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
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?
Sorry, I don't have any more ideas. Let us know what you find.
please check here there are few lines added
DATABASE_URL=postgresql://deploy:[email protected]/myapp
https://gorails.com/deploy/ubuntu/18.04
Thanks @jose2007kj
for me issue was there was commented database connection on top after removing that commented connect it worked for me.
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.