Mac + Homebrew + Postgresql

Mac OS X 10.10 にHomebrewでPostgresqlの環境を構築する。


①インストール
brew install postgresql

 

②初期化
initdb

※ initdbで初期化はしない。
すると挙動がおかしくなったので。
Homebrewでもinitdbは出てないのでしなくても良い?

環境変数追加
追加することでオプション-Dが不必要になる。

export PGDATA=/usr/local/var/postgres
source .zshrc

 

④起動
postgres -D /usr/local/var/postgres
自動起動の方法は下に書いてある。To have launchd start postgresql at login: ・・・)

pg_ctl start

 

⑤確認

psql -l

 

⑤停止
pg_ctl stop
(終了できない場合・・・)
pg_ctl stop -m fast (fastはSHUTDOWN-MODE) 

 

// インストール時のログ

➜ ~ brew install postgresql
==> Installing postgresql dependency: openssl
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/openssl-1.0.1k.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring openssl-1.0.1k.yosemite.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/openssl/certs

and run
/usr/local/opt/openssl/bin/c_rehash

This formula is keg-only, which means it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.

Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include

==> Summary
🍺 /usr/local/Cellar/openssl/1.0.1k: 431 files, 15M
==> Installing postgresql
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/postgresql-9.4.0.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring postgresql-9.4.0.yosemite.bottle.tar.gz
==> Caveats
If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
https://github.com/Homebrew/homebrew/issues/2510

To migrate existing data from a previous major version (pre-9.4) of PostgreSQL, see:
http://www.postgresql.org/docs/9.4/static/upgrading.html

To have launchd start postgresql at login:
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
Then to load postgresql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or, if you don't want/need launchctl, you can just run:
postgres -D /usr/local/var/postgres
==> /usr/local/Cellar/postgresql/9.4.0/bin/initdb /usr/local/var/postgres
==> Summary
🍺 /usr/local/Cellar/postgresql/9.4.0: 2990 files, 40M