69
75

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 5 years have passed since last update.

PostgreSQLのDBを複製する方法

Posted at

1つの案件で複数のカスタマイズを同時に行っている時にそれぞれ違う変更をDBに行う必要があり
同じDBを複数用意する必要があったので調べた時のメモ。
一時的なバックアップにも便利かも。

##コマンド1
createdb -T ORG_DB_NAME NEW_DB_NAME

##コマンド2
上記のコマンドは、DBを使用中だと怒られれるので
その場合は、下記コマンド

createdb NEW_DB_NAME
pg_dump -Ft ORG_DB_NAME | pg_restore -d NEW_DB_NAME

##備考
ORG_DB_NAME:コピー元のDB名
NEW_DB_NAME:新しく作るDB名

69
75
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
69
75

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?