Rails PG Unix域套接字“/tmp/.s.PGSQL.5432”?问题

时间:2016-03-02 16:55:45

标签: ruby-on-rails macos postgresql ruby-on-rails-4 osx-yosemite

我已经卸载并安装了PG和所有与pg相关的宝石。当我尝试运行rails服务器时,我收到以下错误

rails s
=> Booting WEBrick
=> Rails 4.2.5.2 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2016-03-02 22:23:01] INFO  WEBrick 1.3.1
[2016-03-02 22:23:01] INFO  ruby 2.2.2 (2015-04-13) [x86_64-darwin14]
[2016-03-02 22:23:01] INFO  WEBrick::HTTPServer#start: pid=6351 port=3000


Started GET "/" for ::1 at 2016-03-02 22:23:06 +0530

PG::ConnectionBad - could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
:
  activerecord (4.2.5.2) lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
  activerecord (4.2.5.2) lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
  activerecord (4.2.5.2) lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
  activerecord (4.2.5.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
  activerecord (4.2.5.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
  activerecord (4.2.5.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
  activerecord (4.2.5.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
  /Users/harshamv/.rbenv/versions/2.2.2/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
  activerecord (4.2.5.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
  activerecord (4.2.5.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
  /Users/harshamv/.rbenv/versions/2.2.2/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
  activerecord (4.2.5.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
  activerecord (4.2.5.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
  activerecord (4.2.5.2) lib/active_record/connection_handling.rb:113:in `retrieve_connection'
  activerecord (4.2.5.2) lib/active_record/connection_handling.rb:87:in `connection'
  activerecord (4.2.5.2) lib/active_record/migration.rb:383:in `connection'
  activerecord (4.2.5.2) lib/active_record/migration.rb:370:in `call'
  newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.5.2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.2.5.2) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
  activesupport (4.2.5.2) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
  activesupport (4.2.5.2) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.5.2) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.5.2) lib/action_dispatch/middleware/reloader.rb:73:in `call'
  newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.5.2) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
  newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
  newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.5.2) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  web-console (2.3.0) lib/web_console/middleware.rb:28:in `block in call'
  web-console (2.3.0) lib/web_console/middleware.rb:18:in `call'
  newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack-contrib (1.4.0) lib/rack/contrib/response_headers.rb:17:in `call'
  meta_request (0.4.0) lib/meta_request/middlewares/headers.rb:16:in `call'
  newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.5.2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  railties (4.2.5.2) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.5.2) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.5.2) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.5.2) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.5.2) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.2.5.2) lib/rails/rack/logger.rb:20:in `call'
  newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.5.2) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
  newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack (1.6.4) lib/rack/runtime.rb:18:in `call'
  newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  activesupport (4.2.5.2) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack (1.6.4) lib/rack/lock.rb:17:in `call'
  newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.5.2) lib/action_dispatch/middleware/static.rb:116:in `call'
  newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
  newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  railties (4.2.5.2) lib/rails/engine.rb:518:in `call'
  railties (4.2.5.2) lib/rails/application.rb:165:in `call'
  newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack (1.6.4) lib/rack/lock.rb:17:in `call'
  rack (1.6.4) lib/rack/content_length.rb:15:in `call'
  rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
  /Users/harshamv/.rbenv/versions/2.2.2/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
  /Users/harshamv/.rbenv/versions/2.2.2/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
  /Users/harshamv/.rbenv/versions/2.2.2/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'



Started POST "/__better_errors/6febe33a854ba104/variables" for ::1 at 2016-03-02 22:23:06 +0530

postgres中的server.log显示以下内容

DETAIL:  Permissions should be u=rwx (0700).
FATAL:  data directory "/usr/local/var/postgres" has group or world access
DETAIL:  Permissions should be u=rwx (0700).
FATAL:  data directory "/usr/local/var/postgres" has group or world access
DETAIL:  Permissions should be u=rwx (0700).
FATAL:  data directory "/usr/local/var/postgres" has group or world access
DETAIL:  Permissions should be u=rwx (0700).
FATAL:  data directory "/usr/local/var/postgres" has group or world access
DETAIL:  Permissions should be u=rwx (0700).

重新启动brew服务

➜  postgres git:(master) brew services postgres restart
==> Tapping homebrew/services
Cloning into '/usr/local/Library/Taps/homebrew/homebrew-services'...
remote: Counting objects: 7, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 7 (delta 0), reused 4 (delta 0), pack-reused 0
Unpacking objects: 100% (7/7), done.
Checking connectivity... done.
Tapped 0 formulae (32 files, 42.0K)
Error: No available formula with the name "restart"

1 个答案:

答案 0 :(得分:2)

当postgres服务器未启动时,通常会出现此错误。尝试重新启动postgres服务。您可以使用命令重启postgres:

INSERT INTO publicdata:samples.github_nested#TEMP (repository.name, MyCustomField__c) VALUES ('New publicdata:samples.github_nested', '9000');
INSERT INTO publicdata:samples.github_nested#TEMP (repository.name, MyCustomField__c) VALUES ('New publicdata:samples.github_nested 2', '9001');
INSERT INTO publicdata:samples.github_nested#TEMP (repository.name, MyCustomField__c) VALUES ('New publicdata:samples.github_nested 3', '9002');