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

RDS(Postgres)からデータをdumpしてローカルDBに投入する

Posted at

環境

  • RDS Postgres
  • Amazon Linux 2(※dumpを取得する環境として)

手順

pg_dump:aborting because of server version mismatch というエラーが出た場合は、後述の手順を実施。

dump の取得

以下をサーバ(ここでは Amazon Linux 2 を想定)にログインして実行。

$ /usr/pgsql-9.6/bin/pg_dump -U <user> -h <db_url> -p 5432 <db_name> -f <dump_file>

// 以下、例。
$ /usr/pgsql-9.6/bin/pg_dump -U root -h foo.cbvedzbhutma.ap-northeast-1.rds.amazonaws.com -p 5432 your_db_name_comes_here -f foo_dump.sql

scp でローカルにコピー

以下をローカルホストで実行。
作業後不要になった dump ファイルは適時削除する。

scp -i ~/.ssh/xxx <user>@<server_address>:<path_to_dump_file> <path_to_dump_file_on_local>

ローカルDB にデータを投入する

psql -U <user> -h localhost -d <db_name> -p 5432 -f <path_to_dump_file_on_local>

トラブルシューティング

pg_dump:aborting because of server version mismatch が出た場合

※バージョン 9.6 用ですが、他のバージョン用に適時読み替えてください。

$ sudo yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/postgresql96-libs-9.6.12-1PGDG.rhel7.x86_64.rpm

$ sudo yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/postgresql96-9.6.12-1PGDG.rhel7.x86_64.rpm
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?