Rails - Creating postgres database on server throws error "could not connect to server: Connection refused"

StackOverflow https://stackoverflow.com/questions/23666590

  •  22-07-2023
  •  | 
  •  

Question

I've been trying to get my app running for a couple of days now, and all previous problems were answered by searching, but I can't find a solution for this problem.

So I managed to deploy my app to a webhost following this guide: https://gorails.com/deploy/ubuntu/14.04

now I've come to the step were I need to perform the following action:

RAILS_ENV=production bundle exec rake db:create

I do this SSHing to deploy@[server IP] and going into the current folder, but it throws the following error:

could not connect to server: Connection refused
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `initialize'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `new'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `connect'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:548:in `initialize'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
/home/deploy/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/home/deploy/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_handling.rb:79:in `retrieve_connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_handling.rb:53:in `connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/tasks/postgresql_database_tasks.rb:8:in `connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/tasks/postgresql_database_tasks.rb:17:in `create'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/tasks/database_tasks.rb:73:in `create'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/tasks/database_tasks.rb:87:in `block in create_current'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/tasks/database_tasks.rb:183:in `block in each_current_configuration'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/tasks/database_tasks.rb:182:in `each'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/tasks/database_tasks.rb:182:in `each_current_configuration'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/tasks/database_tasks.rb:86:in `create_current'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/railties/databases.rake:20:in `block (2 levels) in <top (required)>'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/task.rb:240:in `call'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/task.rb:240:in `block in execute'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/task.rb:235:in `each'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/task.rb:235:in `execute'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/home/deploy/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/task.rb:172:in `invoke_with_call_chain'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/task.rb:165:in `invoke'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:150:in `invoke_task'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:106:in `each'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:106:in `block in top_level'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:115:in `run_with_threads'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:100:in `top_level'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:78:in `block in run'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:176:in `standard_exception_handling'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:75:in `run'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/bin/rake:33:in `<top (required)>'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/bin/rake:23:in `load'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/bin/rake:23:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"dbblog", "pool"=>5, "username"=>"postgres", "password"=>"[removed]", "host"=>"localhost"}

this is the database.yml:

production:
  adapter: postgresql
  encoding: unicode
  database: dbblog
  pool: 5
  username: postgres
  password: [password removed!]
  host: localhost

I used the same host as the writer of the guide author, and followed the same steps, so I don't get what I'm doing wrong.

I hope somebody can help me and thanks in advance!

Was it helpful?

Solution

First thing to check is whether your local Postgres instance is running at all:

ps -ef | grep postgres

And then if so, on what port it's running. 5432 is the default, so if you didn't do anything special in terms of config, that's where it should be running.

Also: Is the server where you're doing the rake the same one on which Postgres is running?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top