簡體   English   中英

為什么在將其作為服務運行時無法訪問postgres?

[英]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 ,但這個文件對我來說並不存在。

UPDATE

運行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。

如果要將9.5數據與9.6服務器一起使用。 你必須運行:

  • pg_upgrade這里 )或
  • pg_dump從9.5到文件和pg_restore | psql取決於9.6上的備份類型......( 這里

如果您選擇第一個選項,則無需進一步的步驟 - 您的默認版本為9.6,它將與現有數據目錄一起使用。

在運行pg_upgrade之前,請復制data_directory

暫無
暫無

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

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