mac異常關機後總是無法使用postgresql數據庫,解決辦法:
刪除postmaster.pid文件,然後重新啓動postgresql。
啓動 PostgreSQL:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
關閉 PostgreSQL:
pg_ctl -D /usr/local/var/postgres stop -s -m fast
在 mac 下,可以利用 homebrew 直接安裝 PostgreSQL:
brew install postgresql -v
稍等片刻,PostgreSQL 就安裝完成。接下來就是初始數據庫,在終端執行一下命令,初始配置 PostgreSQL:
initdb /usr/local/var/postgres -E utf8
上面指定 "/usr/local/var/postgres" 爲 PostgreSQL 的配置數據存放目錄,並且設置數據庫數據編碼是 utf8,更多配置信息可以 "initdb --help" 查看。
設成開機啓動 PostgreSQL:
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist