title: Rails - Creating postgres database on server throws error "could not connect to server: Connection refused"
body: <p>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.</p>
  
  <p>So I managed to deploy my app to a webhost following this guide: <a href="https://gorails.com/deploy/ubuntu/14.04" rel="nofollow">https://gorails.com/deploy/ubuntu/14.04</a></p>
  
  <p>now I've come to the step were I need to perform the following action:</p>
  
  <pre><code>RAILS_ENV=production bundle exec rake db:create
  </code></pre>
  
  <p>I do this SSHing to deploy@[server IP] and going into the current folder, but it throws the following error: </p>
  
  <pre><code>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 &lt;top (required)&gt;'
  /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 `&lt;top (required)&gt;'
  /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 `&lt;main&gt;'
  Couldn't create database for {"adapter"=&gt;"postgresql", "encoding"=&gt;"unicode", "database"=&gt;"dbblog", "pool"=&gt;5, "username"=&gt;"postgres", "password"=&gt;"[removed]", "host"=&gt;"localhost"}
  </code></pre>
  
  <p>this is the database.yml:</p>
  
  <pre><code>production:
    adapter: postgresql
    encoding: unicode
    database: dbblog
    pool: 5
    username: postgres
    password: [password removed!]
    host: localhost
  </code></pre>
  
  <p>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. </p>
  
  <p>I hope somebody can help me and thanks in advance!</p>