简体   繁体   English

Rails-在服务器上创建postgres数据库会引发错误“无法连接到服务器:连接被拒绝”

[英]Rails - Creating postgres database on server throws error “could not connect to server: Connection refused”

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 因此,我按照此指南将应用程序部署到了虚拟主机: 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: 我通过SSHing到deploy @ [服务器IP]并进入当前文件夹,但是会引发以下错误:

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: 这是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! 希望有人能帮助我,并预先感谢!

First thing to check is whether your local Postgres instance is running at all: 首先要检查的是本地Postgres实例是否正在运行:

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. 默认值为5432 ,因此,如果您在配置方面没有做任何特别的事情,那么它应该在此运行。

Also: Is the server where you're doing the rake the same one on which Postgres is running? 另外:您正在进行rake的服务器是否与运行Postgres的服务器相同?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rails-Postgres-无法连接到服务器:连接被拒绝(PG :: ConnectionBad) - Rails - Postgres - could not connect to server: Connection refused (PG::ConnectionBad) Heroku Rails部署失败,并显示错误“无法连接到服务器:连接被拒绝” - Heroku Rails deploy fails with error “could not connect to server: Connection refused” PG ::错误:无法连接到服务器:连接被拒绝 - PG::Error: could not connect to server: Connection refused Rails本地服务器未运行:无法连接到服务器:连接被拒绝 - Rails local server doesnt run : could not connect to server: Connection refused 无法连接到服务器:连接被拒绝 - could not connect to server: Connection refused Cloud9中的postgresql错误“无法连接到服务器:连接被拒绝” - postgresql error in Cloud9 “could not connect to server: Connection refused” PG::ConnectionBad - 无法连接到服务器:连接被拒绝 - PG::ConnectionBad - could not connect to server: Connection refused PG :: ConnectionBad:无法连接到服务器:连接被拒绝 - PG::ConnectionBad: could not connect to server: Connection refused 如何在Docker上将Rails与Postgresql连接? 正在获取:无法连接到服务器:连接被拒绝 - How to connect rails with postgresql on docker? Getting: could not connect to server: Connection refused pg_dump:[archiver(db)]与数据库“development”的连接失败:无法连接到服务器:Connection拒绝 - pg_dump: [archiver (db)] connection to database “development” failed: could not connect to server: Connection refused
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM