LoginSignup
0
2

More than 5 years have passed since last update.

【PostgreSQL】(pg_dump)リモートサーバーへ接続してバックアップ

Last updated at Posted at 2018-01-25

バックアップ

PostgreSQLでは、DBの構成やデータをバックアップする時に、デフォルトでDBデータがcopyコマンドでバックアップします。
だが、バックアップしたSQLスクリプトを用いて、その他のソフトウェア(例え、A5M2で実行う)で流して実行したいですが、DBデータ挿入のcopyコマンドが認識できなくて、コピーペースト職人として、DBデータが一個一個でテーブルに反映することになっちゃって、結構面倒くさいことになります。

というところで、今回copyコマンドではなく、insertコマンドでDB構成(DBデータを含む)をバックアップする方法を紹介させていただきます。

/* Windows CMDを起動して、Postgresqlのインストール先へ移動(psql.exeである場所) 
*     console result:C:\PostgreSQL\9.4\bin>
*/
cd C:\PostgreSQL\9.4\bin

/* Postgresqlの環境設定を確認(念のため) 
*     console result:psql (PostgreSQL) 9.4.1
*/
C:\PostgreSQL\9.4\bin>psql -V

/* リモートサーバーを接続してバックアップ 
*     param:
*     -h:HOSTNAME
*     -p:port
*     -U:username
*     -d:database name
*     --inserts:dump the data by [insert] command, not by the default option [copy]
*     -f:file name or the directory
*     
*     console result:C:\PostgreSQL\9.4\bin>
*/
C:\PostgreSQL\9.4\bin>pg_dump -h localhost -p 112 -U myuser -d myDB --inserts -f D:\myDB_20180125.dump

/* pg_dump ヘルプ 
*     tips:バージョンによりオプションが違いので、是非ヘルプにチェックしましょう
*/
C:\PostgreSQL\9.4\bin>pg_dump --help

注意点

postgreSQLバージョンによりコマンドのオプションが違いので、是非ヘルプにチェックしましょう。

以下のサイトから参考になりました。ありがとう!

参考
PostgreSQL 8.2.6文書 pg_dump
DBデータのバックアップとリストア

0
2
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
2