首页 > 大数据 > 数据挖掘 > HGDB企业版V6逻辑复制搭建
本文只要用于描述HGDB企业版V6逻辑复制在redhat7环境下的搭建过程。
数据库版本:HGDB企业版V6.0.1
操作系统版本:Redhat7.x
服务器IP地址:192.168.230.51(发布端)
192.168.230.52(订阅端)
1、发布端修改数据库运行参数
|
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 |
| pg_ctl start |
|
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'); |
| highgo=# create user logicalrep replication login encrypted password 'Logical @123'; |
|
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; #查询发布详情 |
|
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; |
9、订阅端导出导入发布表的表结构
|
pg_dump -h 192.168.80.251 -d postgres -U postgres -s -t test1 -t test2 -f createtable.sql psql -f createtable.sql |
| highgo=# create subscription sub1 connection 'host=192.168.230.51 port=5866 dbname=highgo user=logicalrep password=Logical @123' publication pub1; |
12、订阅端查询同步状态
|
highgo=# select * from test1;
id | txt ----+----- 1 | a 2 | b (2 rows)
highgo=# select * from test2;
id | txt ----+----- 1 | a 2 | b (2 rows) |
13、插入数据测试
|
##发布端新插入数据
highgo=# insert into test1 values(3,'c');
##订阅端查询数据是否同步
highgo=# select * from test1;
|
通过查询同步表内的数据可验证逻辑复制搭建完成。
1、发布端
|
select * from pg_publication; ##查询数据库内发布信息
select * from pg_stat_replication; ##查询流复制相关信息
select * from pg_publication_tables; ##查询已经发布的表的信息 |
2、订阅端
|
select * from pg_subscription; ##查询订阅信息
select * from pg_subscription_rel; ##查询每张表的同步状态
select * from pg_replication_origin_status; |
不支持DDL复制(ALTER TABLE/CREATE TABLE)
不支持TEMPRORARY表和UNLOGGED表复制
不支持Sequences复制( serial/bigserial/identity)
不支持TRUNCATE操作复制
不支持大对象复制
不支持视图、物化视图、外部表复制被复制的表上最好有主键约束;如果没有,必须执行:ALTER TABLE reptest REPLICA IDENTITY FULL;
注:订阅端的复制表是可修改的,复制表一旦修改,发布者和订阅者会数据不一致,进而打破复制。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69994931/viewspace-2838309/ ,如需转载,请注明出处,否则将追究法律责任。