概要
開発環境を作るために、テスト環境からダンプしたりする機会があるので、
ちょっとメモしておく。
ダンプ
Postgresの場合、ロールとかの権限が移植できていないとアプリが接続エラーになるのでダンプする。
※ 特定のDBに関係するものだけでいいけど、やり方がわからないのでとりあえず全出力...
ターミナル
# ロールのみ
$ pg_dumpall -U postgres -h 127.0.0.1 --roles-only -p 5432 > ~/roles.sql
# 構造のみ
$ pg_dump -U postgres -h 127.0.0.1 -s -p 5432 --create example_db > ~/schema.sql
# データのみ
$ pg_dump -U postgres -h 127.0.0.1 -a -p 5432 example_db > ~/data.sql
リストア
ターミナル
$ psql -U postgres -f roles.sql
$ psql -U postgres -f schema.sql
$ psql -U postgres example_db < data.sql
Postgres操作 & 権限
ターミナル
$ psql -d example_db -U hoge
¥d
¥d table_name
¥q
権限追加(とりあえず...)
GRANT ALL * ON TO hoge;
以上