以下の内容はhttps://yohei-a.hatenablog.jp/entry/20201209/1607448229より取得しました。


RDS PostgreSQL から Aurora PostgreSQL に論理レプリケーションする

RDS PostgreSQL から Aurora PostgreSQL に論理レプリケーションレプリケーションしたメモ。

手順

設定
  • RDS PostgreSQL のパラメータグループで rds.logical_replication=1 に設定して、再起動する。
  • rds.logical_replication=1(on) に設定されていることを確認する。
$ psql "host=rds-postgres-117r1.********.ap-northeast-1.rds.amazonaws.com user=awsuser dbname=postgres port=5432"
postgres=> show rds.logical_replication;
 rds.logical_replication
-------------------------
 on
ソース(RDS PostgreSQL
  • ソース DB に接続する。
$ psql "host=rds-postgres117.********.ap-northeast-1.rds.amazonaws.com user=awsuser dbname=postgres port=5432"
  • テーブルを作成する
postgres=> CREATE TABLE LogicalReplicationTest (a int PRIMARY KEY);
  • データを投入する
postgres=> INSERT INTO LogicalReplicationTest VALUES (generate_series(1,10000));
  • 行数をカウントする
postgres=> select count(*) from LogicalReplicationTest;
 count
-------
 10000
  • PUBLICATION を作成する
postgres=> CREATE PUBLICATION testpub FOR TABLE LogicalReplicationTest;
ターゲット(Aurora PostgreSQL
  • ターゲット DB に接続する
$ psql "host=aurora-postgres117.cluster-********.ap-northeast-1.rds.amazonaws.com user=awsuser dbname=postgresql port=5432"
  • テーブルを作成する
postgres=> CREATE TABLE LogicalReplicationTest (a int PRIMARY KEY);
  • 行数をカウントする
postgres=> select count(*) from LogicalReplicationTest;
 count
-------
     0
  • SUBSCRIPTIONを作成する
postgres=> CREATE SUBSCRIPTION testsub CONNECTION 
   'host=rds-postgres-117r1.********.ap-northeast-1.rds.amazonaws.com port=5432 dbname=postgres user=awsuser password=********' 
   PUBLICATION testpub; 
  • 行数をカウントする
postgres=> select count(*) from LogicalReplicationTest;
 count
-------
 10000
追加でデータ投入
  • ソース(RDS PostgreSQL)でデータを追加する
=> INSERT INTO LogicalReplicationTest VALUES (generate_series(10001,20000));
  • ターゲット(Aurora PostgreSQL)で行数をカウントする
=> select count(*) from LogicalReplicationTest;
 count
-------
 20000



以上の内容はhttps://yohei-a.hatenablog.jp/entry/20201209/1607448229より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14