LoginSignup
34
29

More than 5 years have passed since last update.

homebrewで PostgreSQL 9.3へバージョンアップ方法

Posted at

勝手にbrew updgrade postgresqlを実行してしまったら、下記のエラーで起動出来なくなりました

/usr/local/var/postgres/server.log
FATAL:  database files are incompatible with server
DETAIL:  The data directory was initialized by PostgreSQL version 9.2, which is not compatible with this version 9.3.0.

解決方法

参照リンクのままですが

  • サービスを停止する
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
  • 9.3バージョンのデータフォルダを作成する
initdb /usr/local/var/postgres9.3 -E utf8
  • アップグレードを実行する
pg_upgrade \
-d /usr/local/var/postgres \
-D /usr/local/var/postgres9.3 \
-b /usr/local/Cellar/postgresql/9.2.4/bin/ \
-B /usr/local/Cellar/postgresql/9.3.0/bin/ \
-v
  • 前回異常終了だった場合はpidファイルが残されているので、それを削除する必要があります
rm /usr/local/var/postgres/postmaster.pid
  • 下記のメッセージが表示されれば、正常終了
Upgrade Complete
----------------
Optimizer statistics are not transferred by pg_upgrade so,
once you start the new server, consider running:
    analyze_new_cluster.sh

Running this script will delete the old cluster's data files:
    delete_old_cluster.sh
  • データフォルダを変更
cd /usr/local/var
mv postgres postgres9.2.4
mv postgres9.3 postgres
  • サービスを起動
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
  • 下記コマンドでアップグレード結果を確認
psql postgres -c "select version()"
...
PostgreSQL 9.3.0 on x86_64-apple-darwin13.0.0, compiled by Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn), 64-bit
(1 row)

psql -l
...
  • クリーンアップ
brew cleanup postgresql
gem uninstall pg #すべてのバージョンを削除する
gem install pg

参考リンク

34
29
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
34
29