[英]Why can't I access my service from my container host when running with `--network host` mode?
[英]Why can I not access postgres when running it as a service?
當我嘗試通過webapp訪問postgres,或用psql -d template1
打開postgres shell時,我收到一個錯誤。
psql:無法連接到服務器:沒有這樣的文件或目錄服務器是否在本地運行並接受Unix域套接字“/tmp/.s.PGSQL.5432”上的連接?
(*我已經閱讀了很多有關此錯誤的SO主題,但推薦的解決方案並未解決此問題)
將postgres作為服務啟動:
brew services restart postgresql
停止
postgresql
...(可能需要一段時間)==>成功停止postgresql
(標簽:homebrew.mxcl.postgresql)==>成功啟動postgresql
(標簽:homebrew.mxcl.postgresql)
在終端中手動運行postgres:
我可以通過在終端窗口中運行來完成所有工作,但我更喜歡在后台運行它。
postgres -D /usr/local/var/postgres9.6.3
集群:
我在/usr/local/var
有3個數據庫集群,但我想使用postgres9.6.3/
postgres
postgres9.5/
postgres9.6.3/
哪一個:
which psql
返回/usr/local/bin/psql
路徑:
echo $PATH
返回/usr/local/bin
和/usr/local/var
(已添加)
其他推薦解決方案
很多人都可以通過刪除/postgres/postmaster.pid
來解決這個/postgres/postmaster.pid
,但這個文件對我來說並不存在。
運行ps -ef | grep postgres
ps -ef | grep postgres
,僅輸出,
501 2135 1530 0 12:08pm ttys002 0:00.00 grep postgres
使用brew servies
重新啟動postgres后, /usr/local/var/log
中的postgres.log
包含,
FATAL: database files are incompatible with server
DETAIL: The data directory was initialized by PostgreSQL version 9.5, which is not compatible with this version 9.6.3.
服務定義仍在指定舊的9.5數據目錄。 如果你打開〜/ Library / LaunchAgents / homebrew.mxcl.postgresql.plist,你會看到一個如下所示的部分:
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/postgresql/bin/postgres</string>
<string>-D</string>
<string>/usr/local/var/postgres9.5</string>
</array>
將最終參數更改為指向9.6.3數據目錄並重新啟動該服務。 如果不需要,您可能需要注銷並重新登錄,以便重新讀取plist。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.