$ brew install postgresql
初期ディレクトリを移動。これやっておかないと次のinitdb
で失敗する。
$ mv /usr/local/var/postgres/ /usr/local/var/postgres.backup/
utf-8で初期化
$ initdb /usr/local/var/postgres/ -E utf8
$ pg_ctl -D /usr/local/var/postgres/ -l /usr/local/var/postgres/server.log start
-l
オプションはログファイルの場所
$ pg_ctl -D /usr/local/var/postgres/ stop
$ psql -l
$ createuser -P -s <ユーザー名>
PostgreSQLだとユーザーはロールというらしい。
-P
はパスワードを作る、-s
はスーパーユーザー。
とりあえずpostgres
っていうユーザー作っておけばいいと思う。
$ psql postgres -q -c'select * from pg_user'
$ createdb <DB名> -O <オーナーとなるユーザー名>
$ psql -U <ユーザー名> <DB名>
\q
で終了できる。\?
でヘルプ。
$ vim /usr/local/var/postgres/pg_hba.conf
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
trust
をmd5
にする
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
変更後は再起動
$ ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
この設定したらpg_ctl
コマンドで停止とかできなくなる。
停止は
$ launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
起動
$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist