herokuのデータベースの中身をローカルでも再現したかったのですが、地味にリファレンスいろんなところ読まないといけなくて面倒だったのでまとめる。
まずはインストール
$ brew install postgres
# 以下省略
#ここらへん大事。初期設定の方法が載ってる。
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
パソコンの起動時に常にpostgresql起動しておきたいなら
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
postgresqlを明示的に起動したいなら
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
みたいな感じのをやる
操作方法
\h
でヘルプ出てくるんでそこらへん見ればいいんですが、載ってないのだと
/d
:テーブル一覧
\dn
:データベースの確認
\l
:データベース一覧
はよく使う。参考これはpsqlのコマンド。
herokuでdumpしたDBを復元
$ pg_restore --verbose --clean --no-acl --no-owner -h localhost -U ユーザ名 -d データベース名 バックアップファイル名
でオーケー。
\connect database_name
で指定したデータベースと繋がるのであとは普通に操作。