像其他一些人一樣,當我在我的項目中運行rake db:migrate或者甚至為我的Ruby on Rails 3.2應用程序嘗試大多數數據庫任務時,我收到此錯誤.
PGError(無法連接到服務器:沒有這樣的文件或目錄.服務器是否在本地運行并接受Unix域套接字上的連接"/tmp/.s.PGSQL.5432"?
很久以前我用Homebrew安裝了PostgreSQL,并且在最近嘗試安裝MongoDB后,我的PostgreSQL安裝從未如此.我正在運行OS X v10.6 Snow Leopard.
出了什么問題,我怎么能更好地理解PostgreSQL是如何設置在我的Mac上的呢?
到目前為止(我認為)這告訴我PostgreSQL沒有運行(?).
ps -aef|grep postgres (ruby-1.9.2-p320@jct-ana) (develop) ?
501 17604 11329 0 0:00.00 ttys001 0:00.00 grep postgres
但這是否告訴我PostgreSQL正在運行?
? launchctl load -w /usr/local/Cellar/postgresql/9.1.4/homebrew.mxcl.postgresql.plist (ruby-1.9.2-p136)
homebrew.mxcl.postgresql: Already loaded
我該如何解決?我沒看到什么?
PS:~/Library/LaunchAgents包含兩個PostgreSQL .plist文件.我不確定這是否相關.
org.postgresql.postgres.plist
homebrew.mxcl.postgresql.plist
我嘗試了下面的結果,得到了如下結果.
$ psql -p 5432 -h localhost
psql: 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?
could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (fe80::1) and accepting
TCP/IP connections on port 5432?
我已經閱讀了,因為OS X安裝了自己版本的PostgreSQL,而Homebrew在不同的地方安裝了不同的版本,PostgreSQL命令在/ tmp /目錄中查找.您需要在Stack Overflow上搜索更多內容,但基本上您可以通過符號鏈接PostgreSQL,以便任何查看該tmp路徑的內容實際上都能找到真正的路徑,如果這有意義的話.
這是我發現更多東西要嘗試的鏈接,特別是如上所述的符號鏈接,
幫助進行故障排除的最新見解:
$ which psql // This tells you which PostgreSQL you are using when you run $ psql.
然后運行:
$ echo $PATH
要考慮的關鍵是:
確保要運行的PostgreSQL副本的路徑條目在OS X系統的PostgreSQL路徑之前進行.
這是決定運行PostgreSQL的核心要求,也是我所說的導致大多數這些問題的原因.