highgo=# alter system set listen_addresses='*'; highgo=# alter system set wal_level='logical'; highgo=# alter system set max_replication_slots=30; highgo=# alter system set max_wal_senders=40; highgo=# alter system set max_logical_replication_workers=40; highgo=# alter system set max_sync_workers_per_subscription=10; highgo=# alter user postgres with password'postgres';
2、发布端修改pg_hba.conf文件,增加以下内容
host all all 0.0.0.0/0 md5 host replication all 0.0.0.0/0 md5
3、发布端重启数据库,使修改后的配置参数生效
pg_ctl start
4、发布端创建用于逻辑复制同步的表,并插入测试数据
highgo=# create table test1(id int primary key,txt text); highgo=# insert into test1 values(1,'a'); highgo=# insert into test1 values(2,'b'); highgo=# create table test2(id int primary key,txt text); highgo=# insert into test2 values(1,'a'); highgo=# insert into test2 values(2,'b');
5、发布节点创建逻辑复制用户
highgo=# create user logicalrep replication login encrypted password 'Logical@123';
6、将发布表的相关权限授权给发布用户。
highgo=# grant usage on schema public to logicalrep; highgo=# grant select on all tables in schema public to logicalrep; highgo=# alter default privileges in schema public grant select on tables to logicalrep ;
7、发布节点创建发布
highgo=# create publication pub1 for table public.test1,public.test2; highgo=# select * from pg_publication; #查询发布详情
8、订阅端修改数据库运行参数
highgo=# alter system set listen_addresses='*'; highgo=# alter system set max_replication_slots=30; highgo=# alter system set max_wal_senders=40; highgo=# alter system set max_logical_replication_workers=40; highgo=# alter system set max_sync_workers_per_subscription=10;