pg版本:11.7
version:1.0

发布节点:192.168.232.20
订阅节点:192.168.232.21

#发布节点调整参数:
[postgres@rhel6wcb data]$ more postgresql.conf | grep wal_level
wal_level = logical                     # minimal, replica, or logical
[postgres@rhel6wcb data]$ more postgresql.conf | grep max_replication_slots
max_replication_slots = 8       # max number of replication slots
#订阅节点调整参数:
[postgres@rhel6wcb data]$ more postgresql.conf |grep max_replication_slots
max_replication_slots = 8       # max number of replication slots
[postgres@rhel6wcb data]$ more postgresql.conf |grep max_logical_replication
max_logical_replication_workers = 8     # taken from max_worker_processes
#max_sync_workers_per_subscription = 2  # taken from max_logical_replication_workers
#发布节点创建逻辑复制用户:
postgres@postgres=>\c test
You are now connected to database "test" as user "postgres".
postgres@test=>create user logical_user replication login connection limit 8 encrypted password 'logical_user';
CREATE ROLE
postgres@test
postgres@test=>create table t_lr1(id int4,name text);
CREATE TABLE
postgres@test=>insert into t_lr1 values (1,'a');
INSERT 0 1
postgres@test=>create publication pub1 for table t_lr1;
CREATE PUBLICATION
postgres@test=>select * from pg_publication;pubname | pubowner | puballtables | pubinsert | pubupdate | pubdelete | pubtruncate
---------+----------+--------------+-----------+-----------+-----------+-------------pub1    |       10 | f            | t         | t         | t         | t
(1 row)
#订阅节点:
postgres@test=>create table t_lr1(id int4,name text);
CREATE TABLE
postgres@test=>create subscription sub1 connection 'host=192.168.232.20 port=5432 dbname=test user=logical_user' publication pub1;
NOTICE:  created replication slot "sub1" on publisher
CREATE SUBSCRIPTION
#发布节点:
postgres@test=>select slot_name,plugin,slot_type,database,active,restart_lsn from pg_replication_slots;slot_name |  plugin  | slot_type | database | active | restart_lsn
-----------+----------+-----------+----------+--------+-------------sub1      | pgoutput | logical   | test     | t      | 0/59EC7260
(1 row)
#订阅节点:
postgres@test=>select * from pg_subscription;
-[ RECORD 1 ]---+------------------------------------------------------------
subdbid         | 24589
subname         | sub1
subowner        | 10
subenabled      | t
subconninfo     | host=192.168.232.20 port=5432 dbname=test user=logical_user
subslotname     | sub1
subsynccommit   | off
subpublications | {pub1}postgres@test=>select * from t_lr1;id | name
----+------
(0 rows)
#订阅节点查看日志:
2020-12-07 21:52:20.776 CST [14062] LOG:  logical replication apply worker for subscription "sub1" has started
2020-12-07 21:52:20.782 CST [14063] LOG:  logical replication table synchronization worker for subscription "sub1", table "t_lr1" hasstarted
2020-12-07 21:52:20.873 CST [14063] ERROR:  could not start initial contents copy for table "public.t_lr1": ERROR:  permission deniedfor table t_lr1
2020-12-07 21:52:20.874 CST [13878] LOG:  background worker "logical replication worker" (PID 14063) exited with exit code 1
2020-12-07 21:52:25.891 CST [14064] LOG:  logical replication table synchronization worker for subscription "sub1", table "t_lr1" hasstarted
2020-12-07 21:52:25.968 CST [14064] ERROR:  could not start initial contents copy for table "public.t_lr1": ERROR:  permission deniedfor table t_lr1
#发现是权限问题。需要在发布节点添加权限。
#发布节点:
postgres@test=>grant usage on schema public to logical_user;
GRANT
postgres@test=>grant select on t_lr1 to logical_user;
GRANT订阅节点:
postgres@test=>select * from t_lr1;id | name
----+------1 | a
(1 row)

检验insert、update、delete操作。

#发布节点:
postgres@test=>insert into t_lr1 values (2,'b');
INSERT 0 1
#订阅节点
postgres@test=>select * from t_lr1 where id =2;id | name
----+------2 | b
(1 row)
#发布节点
postgres@test=>update t_lr1 set name = 'bbb' where id = 2;
ERROR:  cannot update table "t_lr1" because it does not have a replica identity and publishes updates
HINT:  To enable updating the table, set REPLICA IDENTITY using ALTER TABLE.
postgres@test=>alter table t_lr1 add primary key (id);
ALTER TABLE
#订阅节点:
postgres@test=>alter table t_lr1 add primary key (id);
ALTER TABLE#发布节点:
postgres@test=>update t_lr1 set name = 'bbb' where id = 2;
UPDATE 1
#订阅节点:
postgres@test=>select * from t_lr1 where id =2;id | name
----+------2 | bbb
(1 row)#发布节点:
postgres@test=>delete from t_lr1 where id =2;
DELETE 1
#订阅节点:
postgres@test=>select * from t_lr1;id | name
----+------1 | a
(1 row)
#发布节点添加同步表:
postgres@test=>create table t_big(id int4 primary key,create_time timestamp(0) default clock_timestamp(),name character varying(32));
CREATE TABLE
postgres@test=>insert into t_big(id,name) select n,n*random()*1000 from generate_series(1,1000000) n;
INSERT 0 1000000
postgres@test=>grant select on t_big to logical_user;
GRANT
postgres@test=>alter publication pub1 add table t_big;
ALTER PUBLICATION
postgres@test=>\dRp+ pub1Publication pub1Owner   | All tables | Inserts | Updates | Deletes | Truncates
----------+------------+---------+---------+---------+-----------postgres | f          | t       | t       | t       | t
Tables:"public.t_big""public.t_lr1"postgres@test=>select * from pg_publication_tables;pubname | schemaname | tablename
---------+------------+-----------pub1    | public     | t_lr1pub1    | public     | t_big
(2 rows)#订阅节点添加相应的表结构:
postgres@test=>create table t_big(id int4 primary key,create_time timestamp(0) default clock_timestamp(),name character varying(32));
CREATE TABLE
postgres@test=>select * from t_big;id | create_time | name
----+-------------+------
(0 rows)postgres@test=>alter subscription sub1 refresh publication;
ALTER SUBSCRIPTION
postgres@test=>select count(*) from t_big;count
---------1000000
(1 row)

逻辑复制的启动,停止:

#在订阅节点开启订阅,关闭订阅即可。
postgres@test=>select subname,subenabled,subpublications from pg_subscription;subname | subenabled | subpublications
---------+------------+-----------------sub1    | t          | {pub1}
(1 row)
postgres@test=>alter subscription sub1 disable;
ALTER SUBSCRIPTION
postgres@test=>select subname,subenabled,subpublications from pg_subscription;subname | subenabled | subpublications
---------+------------+-----------------sub1    | f          | {pub1}
(1 row)
postgres@test=>alter subscription sub1 enable;
ALTER SUBSCRIPTION
postgres@test=>select subname,subenabled,subpublications from pg_subscription;subname | subenabled | subpublications
---------+------------+-----------------sub1    | t          | {pub1}
(1 row)

PostgreSQL11.7逻辑复制的搭建相关推荐

  1. PostgreSQL11.7逻辑复制压测

    PG版本:11.7 1个发布节点 1个订阅节点 单边insert压测 #发布节点: postgres@test=>create table t_per1(id int4,name text,cr ...

  2. postgresql update使用别名_PostgreSQL逻辑复制之pglogical

    朱贵平(lottu)   中国PG分会认证专家 宜搜科技资深DBA,擅长Oracle.PostgreSQL,目前从事Oracle.PostgreSQL 相关的运维管理及迁移等工作. 一.pglogic ...

  3. 参数详解 复制进程_如何优化PostgreSQL逻辑复制

    How to Optimize PostgreSQL Logical Replication 逻辑复制( Logical Replication )或 Pglogical 是表级别的复制.两者都是基于 ...

  4. pg内功修炼:逻辑复制

    目录 什么是逻辑复制 逻辑解析 复制槽 output plugin 几个常见的outputplugin 几个能手动接收解析数据的函数和工具 逻辑解析测试1:观察用2个不同的output plugin解 ...

  5. FPGA设计思想之“逻辑复制”

    1.逻辑复制是一种通过增加面积来改善时序条件的优化手段,它最主要的应用时调整信号的扇出.如果某个信号需要驱动的后级逻辑信号较多,也就是其扇出非常大,那么为了增加这个信号的驱动能力,就必须插入很多级的B ...

  6. mysql gtid 搭建主从_MySQL5.7 - 基于GTID复制模式搭建主从复制

    MySQL5.7 - 基于GTID复制模式搭建主从复制 发布时间:2020-04-17 10:09:20 来源:51CTO 阅读:226 作者:insist_way 环境: MySQL5.7.24版本 ...

  7. 云和恩墨大讲堂丨PostgreSQL逻辑复制案例分享

    PostgreSQL逻辑复制案例分享--2月24日20:00 在PostgreSQL和基于PostgreSQL的国产数据库的使用中,逻辑复制作为一种区别于流复制的数据同步功能,常用于主业务库向分析库的 ...

  8. dump的文件 查看pg_PostgreSQL 逻辑复制异常引发Pg_wal目录WAL文件膨胀一例

    原文: https://postgres.fun/20200628070600.html 故障现象 前几天一位社区朋友咨询一个PostgreSQL的WAL文件膨胀案例,他们有个生产库最近几天pg_wa ...

  9. PostgreSQL V10逻辑复制

    目录 环境 文档用途 详细信息 环境 系统平台:Linux x86-64 Red Hat Enterprise Linux 7 版本:10.1 文档用途 PostgreSQL V10逻辑复制原理以及作 ...

最新文章

  1. 使用MakeCAB.exe命令创建CAB文件
  2. mysql web备份软件_Windows下实现MySQL自动备份的批处理(复制目录或mysqldump备份)
  3. python中怎么输入角度_在Python中更正两点之间的角度
  4. OpenCV图像的轮廓的匹配
  5. 2021年中国电子签名行业研究报告
  6. 【Linux/Ubuntu】查询文件和文件夹大小
  7. SQL必知必会-更新和删除数据
  8. hdu 5148 cities 树形DP
  9. 关于ConcurrentDictionary的线程安全
  10. java实现ftp连接、登陆、上传、下载、删除文件、获取目录、文件列表
  11. 简易web服务器系统毕业论文设计,毕业论文 简易的WEB服务器的设计
  12. 计算机创新创业选题参考,计算机及相关专创新创业教育指导书.doc
  13. 重复代码检查工具Simian
  14. Nginx搭建反向代理服务器
  15. 东北大学计算机考研专业842包括什么,东北大学2019年计算机考研842计算机专业基础考试大纲...
  16. 3个免费的设计师图库,值得收藏
  17. 【转】腾讯2017校招实习生面试总结 腾讯实习生面试经验 (已拿offer)
  18. 达梦数据库DM8支持Seata事务框架
  19. 二进制、八进制、十六进制的写法
  20. javaWeb实现裁剪图片上传整套方案

热门文章

  1. 42 可写成成三个整数的立方和
  2. 【BZOJ3174】【codevs25442075】拯救小矮人,DP+贪心
  3. 遗传算法的c++语言程,C++实现简单遗传算法
  4. ie11浏览器可以下载java吗_如何卸载IE11? 如何安装低版本的IE浏览器?
  5. linux修改http版本信息,动态库中的soname中版本号的修改
  6. Intel Core Enhanced Core架构/微架构/流水线 (9) - 执行单元发射口旁路时延
  7. WPF、Windows Forms和Silverlight区别
  8. 光线跟踪的几种常见求交运算
  9. html怎么遍历数组,js遍历数组有多少种方法
  10. mysql5.7.10安装_MySQL5.7.10下载及安装及配置-阿里云开发者社区