簡體   English   中英

Ruby on Rails 4:當鍵入rails服務器時,得到錯誤消息PG :: ConnectionBad

[英]Ruby on Rails 4: when type rails server , got error message PG::ConnectionBad

我是Ruby on rails的新手。 我通過示例教程學習創建了基本的演示應用程序。

首先它工作正常,一周后我輸入rails s時出錯,

錯誤

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"?

我正在使用PostgreSQL數據庫。

我在MAC OS X 10.8.5上

我在SO上發現了類似的問題,但是他們正在經歷一些提前階段,因此涉及一些先進的解決方案。

當類型

which psql
/usr/local/bin/psql

似乎升級你的操作系統已經改變了Postgres保存其數據的目錄的權限。

sudo chown -R sabir:staff /usr/local/var/postgres

使您的用戶帳戶成為該目錄的所有者。 請求時輸入密碼; 輸入時不會看到字符。

自制的Postgres版本包括自動啟動的功能。 要檢查您的安裝是否存在,請運行

ls -l ~/Library/LaunchAgents/

您應該看到以homebrew.mxcl.postgresql.plist結尾的行。 如果您沒有看到此行,請運行

ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents

為了讓它自動啟動。

最后,跑

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

確保Postgres現在處於活動狀態。 通過鍵入確認

psql -l

使用自制軟件安裝postgres時,可能只是在前台手動啟動它。 因此關閉終端窗口后,postgres不再運行了。

我建議你做以下的步驟:

  • 通過點擊進程列表來檢查postgres是否正在運行: ps aux | grep postgres ps aux | grep postgres
  • 如果它正在運行嘗試sudo kill -9 {POSTGRES_PID}
  • 如果沒有運行,請使用brew info postgres查看如何手動啟動(或啟動等)
  • 用自制的結果開始postgres - 在我的情況下postgres -D /usr/local/var/postgres

我希望,那會幫助你。 如果您在其他基礎上安裝了postgres,我可以相應地更改我的答案。

這可能是您的文件權限問題。

看看這個答案: https//stackoverflow.com/a/8481156/2417848

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM