終端機執行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.pid
將postmaster.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
沒有留言:
張貼留言