日常

ケ・セラ・セラ

Mac で postgresql の起動がうまくいかないとき

適当に brew update して久々に postgresql を使おうとしたら起動しなくて暫く時間をくった。

どうやら自分は 9.3 から 9.4 に上げたらしい。

$ postgres --version
postgres (PostgreSQL) 9.4.4

まず、こんな調子だった。

$ psql
psql: 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"?

そういう時はログを見るとよい。

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

postgres cannot access the server configuration file "/usr/local/var/postgres/postgresql.conf": No such file or directory

とあって、postgresql.conf が無かったのでとりあえず touch postgresql.conf した。

その後、以下のようにした。

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
initdb /usr/local/var/postgres9.4 -E utf8

これらの記事を参考にした。

initdb が終わるとこう出力されているので、

Success. You can now start the database server using:

    postgres -D /usr/local/var/postgres9.4
or
    pg_ctl -D /usr/local/var/postgres9.4 -l logfile start

postgres -D /usr/local/var/postgres9.4 すると、フォアグラウンドで postgres があがった。

pg_ctl -D /usr/local/var/postgres9.4 -l logfile start でバックグラウンドであがった。

psql postgres とかして入れるようになっていたので、これでよかったのだと思う。