Postgres 不会使用 c9.io 连接到 Rails 应用上 Ruby 中的服务器

Postgres won't connect to server in Ruby on Rails app using c9.io

几天前,我能够从 SQLite 成功安装 Postgresql 和 create/migrate 我的数据库(为部署我的 Rails 4 应用程序做准备)……我是这么想的。

我重新启动了我的服务器,但是当我尝试访问我的应用程序时,出现了这个错误:

PG::ConnectionBad
could not connect to server: Connection refused 
Is the server running locally and accepting connections on Unix domain socket 
"/var/run/postgresql/.s.PGSQL.5432"?

我在 SO 上看到了几个类似的回答问题,但它们都涉及 Mac。由于我使用的是 Cloud 9 IDE,我认为可能存在差异(例如,提及 localhost 可能不相关,因为这不是我当前在 c9.io.)

根据其他问题的答案,我在我的终端上试了一下:

sudo ps auxw | grep post

这给了我:

ubuntu    2527  0.0  0.0  10552   888 pts/5    S+   15:21   0:00 grep --color=auto post

然后我尝试了:

sudo find / -name .s.PGSQL.5432 -ls

我得到了:

5286    0 lrwxrwxrwx   1 root     root           26 May 11 15:13 /var/pgsql_socket/.s.PGSQL.5432 -> /private/tmp/.s.PGSQL.5432
5183    0 srwxrwxrwx   1 postgres postgres        0 May 10 22:18 /run/postgresql/.s.PGSQL.5432

yamilethmedina@wheels_registration:~/workspace (master|MERGING) $ psql
psql: could not connect to server: Connection refused
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

这是我的服务器的完整跟踪:

Started GET "/" for 12.43.117.2 at 2015-05-11 16:35:48 +0000

PG::ConnectionBad (could not connect to server: Connection refused
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
):
activerecord (4.1.6) lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `initialize'
activerecord (4.1.6) lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `new'
activerecord (4.1.6) lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect'
activerecord (4.1.6) lib/active_record/connection_adapters/postgresql_adapter.rb:568:in `initialize'
activerecord (4.1.6) lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
activerecord (4.1.6) lib/active_record/connection_adapters/postgresql_adapter.rb:41:in  `postgresql_connection'
activerecord (4.1.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection'
activerecord (4.1.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection'
activerecord (4.1.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `acquire_connection'
activerecord (4.1.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
/usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
activerecord (4.1.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout'
activerecord (4.1.6)  lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
activerecord (4.1.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
activerecord (4.1.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection'
activerecord (4.1.6) lib/active_record/connection_handling.rb:113:in `retrieve_connection'
activerecord (4.1.6) lib/active_record/connection_handling.rb:87:in `connection'
activerecord (4.1.6) lib/active_record/migration.rb:388:in `check_pending!'
activerecord (4.1.6) lib/active_record/migration.rb:377:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.1.6) lib/active_support/callbacks.rb:82:in `run_callbacks'
actionpack (4.1.6) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.6) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.6) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.6) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.6) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.6) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.6) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.1.6)   lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.1.6) lib/rails/engine.rb:514:in `call'
railties (4.1.6) lib/rails/application.rb:144:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'


Rendered /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/rescues/_source.erb (1.1ms)
Rendered /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (3.8ms)
Rendered /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (2.9ms)
Rendered /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (45.7ms)

我的整个 github 存储库以防万一: https://github.com/yamilethmedina/wheels_registration.git

postgresql 看起来不像 运行ning。也许它没有设置为自动启动。一个原因可能是 postgresql 在最后 运行 没有完全关闭,并留下一个 pid 文件。

尝试

  sudo service postgresql start 

看看它是否恢复正常,只需确保关闭虚拟机(这样停止脚本就可以 运行),而不是仅仅关闭它。