Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

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

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

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/ \
  • 前回異常終了だった場合は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:

Running this script will delete the old cluster's data files:
  • データフォルダを変更
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


Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Help us understand the problem. What are the problem?