AdSense

網頁

2023/4/6

Homebrew PostgreSQL 啟動狀態錯誤 status error 256

終端機執行brew services start postgresql啟動Homebrew安裝的PostgreSQL資料庫時狀態為error 256錯誤。


環境:

  • MacBook Pro Intel Core i5
  • macOS Ventura 13.2.1
  • Homebrew 4.0.3
  • psql (PostgreSQL) 14.5 (Homebrew)


~% brew services start postgresql@14
==> Successfully started `postgresql@14` (label: homebrew.mxcl.postgresql@14)
~% brew services list
Name          Status     User  File
postgresql@14 error  256 user  ~/Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist


原因

錯誤原因是PostgreSQL安裝目錄的postmaster.pid檔可能因PostgreSQL程序未正常關閉沒被刪除,導致啟動PostgreSQL服務時發現此檔案已存在而無法成功啟動。postmaster.pid是一個lock file,作用為用來防止同時多個資料庫實例程序使用同一份資料目錄(data directory)。


解決

先執行brew services stop postgresql@14將PostgreSQL服務停止。

~% brew services stop postgresql@14
==> Downloading https://formulae.brew.sh/api/formula.json
######################################################################## 100.0%
Stopping `postgresql@14`... (might take a while)
==> Successfully stopped `postgresql@14` (label: homebrew.mxcl.postgresql@14)

然後執行rm -f /usr/local/var/postgresql@14/postmaster.pidpostmaster.pid檔刪除。

~% rm -f /usr/local/var/postgresql@14/postmaster.pid

Mac M1是執行rm -f /opt/homebrew/var/postgresql@14/postmaster.pid

~% rm -f /opt/homebrew/var/postgresql@14/postmaster.pid

再執行brew services start postgresql@14啟動。

~% brew services start postgresql@14
==> Successfully started `postgresql@14` (label: homebrew.mxcl.postgresql@14)

執行brew services list檢查服務狀態為正常。

~% brew services list
Name          Status  User  File
postgresql@14 started user  ~/Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist


沒有留言:

AdSense