0
0

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 の pg_dump/psql のデータコピーを冪等に行う。

Last updated at Posted at 2023-06-16

pg_dumpコマンド

データのダンプの際には、

  • デフォルトでは、CREATE ○○ IF NOT EXISTS
  • --clean オプションを指定すると、DROP ○○ してから、CREATE ○○ IF NOT EXISTS
  • --clean --if-exists オプションを指定すると、DROP ○○ IF EXISTS してから、CREATE ○○ IF NOT EXISTS

psqlコマンド

リストアの際には、

  • デフォルトでは、途中のクエリが失敗しても中断せずに最後までリストアする。
  • --set=ON_ERROR_STOP=1 で途中で失敗したら中断する。DBは途中までリストアされた状態で残る。
  • --single-transaction オプションを指定すると、シングルトランザクション内でのリストアしてくれる。(途中で失敗すると最初の状態までロールバックする)

冪等にするには

いずれかかな。

  • pg_dump + psql --single-transaction
  • pg_dump --clean --if-exists + psql --set=ON_ERROR_STOP=1
  • pg_dump --clean --if-exists + psql --single-transaction
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?