31
50

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PostgreSQLのダンプとリストア

Last updated at Posted at 2016-12-05

平文形式でバックアップ

ダンプ作成

pg_dump -U "ユーザー名" --no-privileges --schema=public --blobs "DB名" | gzip > dump.sql.gz

リストア

1. 受取る側のユーザーとデータベース作成

create user 'ユーザー名';
create database 'DB名' owner 'ユーザー名';

2. リストア実行

gzip -cd dump.sql.gz | psql -U "ユーザー名" -d "DB名"

独自アーカイブ形式でバックアップ

ダンプ作成

pg_dump -Fc --no-privileges --schema=public --blobs "DB名" > db.dump

リストア

1. 受取る側のユーザーとデータベース作成

create user 'ユーザー名';
create database 'DB名' owner 'ユーザー名';

2. リストア実行

pg_restore -U "ユーザー名" -C -d "DB名" db.dump

[おまけ] タブ区切りファイルで出力

psql "DB名" -U "ユーザー名" -c "SELECT文;" -A -F $'\t' > ./export.tsv
31
50
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
31
50

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?