LoginSignup
2
1

More than 5 years have passed since last update.

PostgreSQLのダンプについてメモ

Last updated at Posted at 2018-01-02

概要

開発環境を作るために、テスト環境からダンプしたりする機会があるので、
ちょっとメモしておく。

ダンプ

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;

以上

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1