LoginSignup
2
3

More than 5 years have passed since last update.

homebrew の PostgreSQL を 9.1 から 9.3 にアップグレードして Rails アプリを動かすまでにしたこと

Posted at

タイトル通り homebrew の PostgreSQL を 9.1 から 9.3 にアップグレードして Rails アプリを動かすまでにしたことの備忘録。

PostgreSQL のアップグレード

HomebrewでPostgresql9.1から9.3へアップデート

PostgreSQL については、こちらの記事を見つつ対応しました。homebrew-versions は使っておらず、以下が実際に行った内容です。

$ brew update
$ brew upgrade postgresql
$ launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
$ mv /usr/local/var/postgres /usr/local/var/postgres91
$ initdb /usr/local/var/postgres -E utf8

# path についてはお使いの環境ごとに変更します
$ pg_upgrade \
  -b /Users/user_name/.homebrew/Cellar/postgresql/9.1.4/bin \
  -B /Users/user_name/.homebrew/Cellar/postgresql/9.3.5_1/bin \
  -d /usr/local/var/postgres91 \
  -D /usr/local/var/postgres

# homebrew.mxcl.postgresql.plist の内容をカスタムしていたので差分を確認して編集した
$ vimdiff /Users/t-matsubara/.homebrew/opt/postgresql/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

# 動作確認
$ psql postgres
psql (9.3.5)

brew upgrade postgres したときに表示された analyze_new_cluster.shdelete_old_cluster.sh は実行していないです。動かしてないですが今のところ困っていることはないです。

Rails アプリで pg gem 再インストール

私の環境では pg が原因で、rails アプリが起動しなくなったので gem の削除、再インストールをします。

$ bundle exec gem uninstall pg
Successfully uninstalled pg-0.15.1
ERROR:  While executing gem ... (NoMethodError)
    undefined method `delete' for #<Bundler::SpecSet:0x007fb2821196d0>
$ bundle install

これをしないと rails s したときに以下のエラーが発生した。PostgreSQL 9.1.4 が依存していた libpq.5.4.dylib がアップグレードでなくなったことが原因。これを直すために、pg gem を再インストールした。

/project/vendor/bundle/ruby/2.1.0/gems/pg-0.15.1/lib/pg.rb:4:in `require': dlopen(/project/vendor/bundle/ruby/2.1.0/extensions/x86_64-darwin-13/2.1.0-static/pg-0.15.1/pg_ext.bundle, 9): Library not loaded: ~/.homebrew/lib/libpq.5.4.dylib (LoadError)
  Referenced from: /project/vendor/bundle/ruby/2.1.0/extensions/x86_64-darwin-13/2.1.0-static/pg-0.15.1/pg_ext.bundle
  Reason: image not found - /project/vendor/bundle/ruby/2.1.0/extensions/x86_64-darwin-13/2.1.0-static/pg-0.15.1/pg_ext.bundle
  from /project/vendor/bundle/ruby/2.1.0/gems/pg-0.15.1/lib/pg.rb:4:in `<top (required)>'

install_name_tool を使うことでも直ったのだけど、たぶん再インストールした方が安全そうです。
あと PostgreSQL 9.3 の方だと、libpq.5.dylib が libpq.5.6.dylib を参照する symlink として作られていたので、もしかすると次バージョンアップするときは勝手に symlink の向き先が変わって大丈夫なのかも?調べておらず分かっていないですが。

Resources

2
3
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
2
3