0

我已經卸載並安裝了PG和所有與pg相關的gem。當我嘗試運行軌道服務器我收到以下錯誤Rails PG Unix域套接字「/tmp/.s.PGSQL.5432」?問題

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" 
+0

我有同樣的錯誤,當我的電池用完了,我的PG數據庫被卡住,我可以通過執行這行代碼解決這個問題:你可以使用命令重新啓動Postgres的'RM的/ usr /本地的/ var/postgres/postmaster.pid' – lienvdsteen

+0

@lienvdsteen得到這個RM:/usr/local/var/postgres/postmaster.pid:沒有這樣的文件或目錄 –

回答

2

這個錯誤通常出現在postgres服務器沒有啓動時。嘗試重新啓動postgres服務。

sudo service postgresql restart 
+0

這是爲OSX? –

+0

sudo:service:command not found –

+0

你是如何安裝postgres的?使用brew嗎? –