今天寫 side project 時要啟動資料庫時遇到 postgres 版本問題
waiting for server to start....2019-03-02 12:45:08.851 EST [3310] FATAL: database files are incompatible with server
2019-03-02 12:45:08.851 EST [3310] DETAIL: The data directory was initialized by PostgreSQL version 10, which is not compatible with this version 11.2.
stopped waiting
pg_ctl: could not start server
Examine the log output.
解法
brew postgresql-upgrade-database
如果跳出
Error: /usr/local/var/postgres.old already exists!
Remove it if you want to upgrade data automatically.
那就直接跟著刪掉吧
rm -rf /usr/local/var/postgres.old
再跑一次 brew postgresql-upgrade-database
沒意外就會看到
==> Upgraded postgresql data from 10 to 11!
==> Your postgresql 10 data remains at /usr/local/var/postgres.old
==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)