brew upgrade postgresqlしたらメジャーバージョンアップだったので実行時にエラー

RailsでUser.firstのようにデータベースアクセス時に以下のエラー

PG::ConnectionBad: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

pgのログを見ると

$ tail /usr/local/var/postgres/server.log

FATAL:  database files are incompatible with server
DETAIL:  The data directory was initialized by PostgreSQL version 9.3, which is not compatible with this version 9.4.3.

となっている。
データが9.3のバージョンの形式なのか?
なので以下のようにして、9.4.3にデータを上げる。

# pgの停止
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
# pgのデータベースアップデート
initdb /usr/local/var/postgres9.4 -E utf8
pg_upgrade -d /usr/local/var/postgres -D /usr/local/var/postgres9.4 -b /usr/local/Cellar/postgresql/9.3.5_1/bin/ -B /usr/local/Cellar/postgresql/9.4.3/bin/ -v
mv /usr/local/var/postgres /usr/local/var/postgres9.3.5 # 念のため
mv /usr/local/var/postgres9.4 /usr/local/var/postgres
# pg起動
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

pgをちゃんと使うのは初なので戸惑う。。

タイトルとURLをコピーしました