以前行ったDockerをつかってCentOS7上でPostgreSQLの論理レプリケーションを試すでは、
論理レプリケーションを試したが、もしデュアルマスタ的に両向きに行うとどうなるか試した。
結果はある意味当たり前だが、タイトルの通り無限にレプリケーションし続けた。
設定
基本的作業は記事のマスタ設定を両サーバーに行う
そして、テーブル作成から
# M/S共通
CREATE TABLE test_table (
id SERIAL,
name varchar(80)
);
CREATE ROLE test WITH LOGIN REPLICATION PASSWORD 'hogehoge';
GRANT ALL ON test_table TO test;
# M
ALTER SEQUENCE test_table_id_seq INCREMENT BY 2;
# S
ALTER SEQUENCE test_table_id_seq INCREMENT BY 2 RESTART WITH 2;
# M
CREATE PUBLICATION pub_srv1_test_table FOR TABLE test_table;
# S
CREATE PUBLICATION pub_srv2_test_table FOR TABLE test_table;
# M
CREATE SUBSCRIPTION sub_srv3_test_table CONNECTION 'dbname=testdb host=postgresql2 port=5432 user=test' PUBLICATION pub_srv2_test_table;
# S
CREATE SUBSCRIPTION sub_srv4_test_table CONNECTION 'dbname=testdb host=postgresql1 port=5432 user=test' PUBLICATION pub_srv1_test_table;
実行
こんな感じに設定して、1回INSERTしてみる。
Insert into test_table (name) values('aaa');
無限に増えていく
testdb=# select * from test_table;
id | name
----+------
1 | aaa
1 | aaa
1 | aaa
1 | aaa
1 | aaa
1 | aaa
1 | aaa
1 | aaa
1 | aaa
1 | aaa
1 | aaa
testdb=# select count(*) from test_table;
count
-------
88
(1 row)
testdb=# select count(*) from test_table;
count
-------
96
(1 row)