Table of Contents
MySQL の場合は MySQL: ダンプを保存せずにデータベースをコピー をご覧ください。
PostgreSQL のデータを移す際によくやるのは、 pg_dump
でダンプデータを取得・保存して、 psql
で流し込む方法です。
いちいちダンプファイルに保存するのも面倒なので、つなげてひとつのコマンドにしてみました。 ダンプファイルの保存は行いません。
Without Password
Usually, database is protected with password, but now let’s check the basic.
With Password
エクスポート元、インポート先のどちらかにパスワードがある場合
パスワードを聞かれた時に入力できるので、 必要に応じて -W
をつければ OK です。
エクスポート元、インポート先の両方にパスワードがある場合
-W
オプションをつけても、パスワードをうまく入力することができません(私はいい方法をみつけることができませんでした)。 そこで .pgpass
ファイル を使います。
.pgpass
If you save password into .pgpass
and locate it in your home directory, you can connect to the databases of PostgreSQL without password.
.pgpass
には次のように記述します。
From the left most, host, IP address, port number, database name, user name and password, connected by “:”. If you have several database configurations, write them into multi lines.
And set the permission of the .pgpass
600, then .pgpass
will be available.
Creating .pgpass
, you can export and import in the same time. You don’t have to add -W
.