bucardo是PostgreSQL数据库中实现双向同步的软件,可以实现PostgreSQL数据库的双master的方案,不过bucardo中的同步都是异步的,它是通过触发器记录变化,程序是perl写的.bucardo可以实现postgresql的多主复制、主从同步,甚至可以以postgresql为源库,可以和oracle、mysql、mongodb等很多数据库进行数据异步同步。
 
而pg原生的stream replication;虽可以同步;只能单向同步。只能是只读操作。而bucardo不支持DDL的同步; 所以说 相当于对stream replication的关系;相当于同oracle中 ogg对dg。
 
一 , 安装软件包
 
 
    对上面perl安装包;安装过程
perl Makefile.PL
make
make install
3. 上面安装好了软件;下面实例化Bucardo;在postgres用户下面新建.bucardorc 文件
log_conflict_file         = /home/postgres/log/bucardo_conflict.log
piddir = /home/postgres/run
reason_file = /home/postgres/log/bucardo.restart.reason.log
warning_file = /home/postgres/log/bucardo.warning.log

4. 初始化bucardo

[postgres@sdserver40_222 ~]$ bucardo install
This will install the bucardo database into an existing Postgres cluster.
Postgres must have been compiled with Perl support,
and you must connect as a superuser Current connection settings:
. Host: <none>
. Port:
. User: postgres
. Database: bucardo
. PID directory: /home/postgres/run
Enter a number to change it, P to proceed, or Q to quit: Change the host to: 127.0.0.1 Changed host to: 127.0.0.1
Current connection settings:
. Host: 127.0.0.1
. Port:
. User: postgres
. Database: bucardo
. PID directory: /home/postgres/run
Enter a number to change it, P to proceed, or Q to quit: Change the database name to: mydb Changed database name to: mydb
Current connection settings:
. Host: 127.0.0.1
. Port:
. User: postgres
. Database: mydb
. PID directory: /home/postgres/run
Enter a number to change it, P to proceed, or Q to quit: P Postgres version is: 9.5
Attempting to create and populate the bucardo database and schema
Database creation is complete Updated configuration setting "piddir"
Installation is now complete.
If you see errors or need help, please email bucardo-general@bucardo.org You may want to check over the configuration variables next, by running:
bucardo show all
Change any setting by using: bucardo set foo=bar
这步可能会出现问题;大多数是依赖包没装的问题;现后面FAQ
 
二, 配置bucardo环境
 
下面的配置的环境:
主机1: 192.168.1.201 
主机2: 192.168.1.202
 
1 添加源数据库
在192.168.1.201 执行
[postgres@sdserver40_222 ~]$ bucardo add db db1 dbname=mydb host=127.0.0.1 port=  user=postgres
Added database "db1"
[postgres@sdserver40_222 ~]$ bucardo add db db2 dbname=mydb host=192.168.1.202 port= user=postgres
Added database "db2"
这里需要注意的是;psql -h 192.168.1.202是否可以连通;看是不是防火墙;在主机192.168.1.202上pg_hba.conf是否配置。
 
2. 添加表:

[postgres@sdserver40_222 ~]$  bucardo add all tables
New tables added: 0
Already added: 13
[postgres@sdserver40_222 ~]$ bucardo add all sequences
Sorry, no sequences were found
New sequences added: 0
如果要添加某一个表,则可以bucardo add  table tablename
 
3.  添加复制群组(即复制一组表):

[postgres@sdserver40_222 ~]$ bucardo add relgroup relgroup1 lottu03 lottu01;
Created relgroup "relgroup1"
The following tables or sequences are now part of the relgroup "relgroup1":
  public.lottu01
  public.lottu03
[postgres@sdserver40_222 ~]$ bucardo add dbgroup dbgroup1 db1:source db2:target
Created dbgroup "dbgroup1"
Added database "db1" to dbgroup "dbgroup1" as source
Added database "db2" to dbgroup "dbgroup1" as target

1)若添加若有表则用 all tables;

2) 只能同步存在主键的table;像这里的lottu01我是没建主键的;下面添加同步步骤会出现错误。

4. 添加同步

[postgres@sdserver40_222 ~]$ bucardo add sync sync1 relgroup=relgroup1 dbs=dbgroup1
Added sync "sync1"
   1)这里注意的是;同步到表需要主键约束;不然同步是添加不了的。
会报如下错误;这个是跟触发器有关系;bucardo是建立在触发器之上的。
Failed to add sync: DBD::Pg::st execute failed: ERROR:  Table "public.lottu01" must specify a primary key! at line . at line .
CONTEXT: PL/Perl function "validate_sync" at /usr/local/bin/bucardo line
  2)删除同步 :bucardo add sync syncname
  3 ) bucardo 添加同步;参数详情 如下;
  add sync:
bucardo add sync name relgroup=xxx dbs=xxx Adds a sync, which is a named replication event containing information
about what to replicate from where to where. The supported parameters
are: "dbs"
The name of a dbgroup or comma-delimited list of databases. All of
the specified databases will be synchronized. Required. "dbgroup"
The name of a dbgroup. All of the databases within this group will
be part of the sync. If the dbgroup does not exists and a separate
list of databases is given, the group will be created and populated. "relgroup"
The name of a relgroup to synchronize. All of the tables and/or
sequences in the relgroup will be synchronized. Required unless
"tables" is specified. "tables"
List of tables to add to the sync. This implicitly creates a
relgroup with the same name as the sync. Required unless "relgroup"
is specified. "status"
Indicates whether or not the sync is active. Must be either "active"
or "inactive". Defaults to "active". "rebuild_index"
Boolean indicating whether or not to rebuild indexes after every
sync. Defaults to off. "lifetime"
Number of seconds a KID can live before being reaped. No limit by
default. "maxkicks"
Number of times a KID may be kicked before being reaped. No limit by
default. "conflict_strategy"
The conflict resolution strategy to use in the sync. Supported
values: "bucardo_source"
The rows on the "source" database always "win". In other words,
in a conflict, Bucardo copies rows from source to target. "bucardo_target"
The rows on the "target" database always win. "bucardo_skip"
Any conflicting rows are simply not replicated. Not recommended
for most cases. "bucardo_random"
Each database has an equal chance of winning each time. This is
the default. "bucardo_latest"
The row that was most recently changed wins. "bucardo_abort"
The sync is aborted on a conflict. "onetimecopy"
Determines whether or not a sync should switch to a full copy mode
for a single run. Supported values are: : off
: always full copy
: only copy tables that are empty on the target "stayalive"
Boolean indicating whether or not the sync processes (CTL) should be
persistent. Defaults to false. "kidsalive"
Boolean indicating whether or not the sync child processes (KID)
should be persistent. Defaults to false. "autokick"
Boolean indicating whether or not tables in the sync should
automatically send kick messages when they're modified. May be
overridden by the "autokick" parameter of individual tables. "checktime"
An interval specifying the maximum time a sync should go before
being kicked. Useful for busy systems where you don't want the
overhead of notify triggers. "priority"
An integer indicating the priority of the sync. Lower numbers are
higher priority. Currently used only for display purposes. "analyze_after_copy"
Boolean indicating whether or not to analyze tables after every
sync. Off by default. Optional. "overdue"
An interval specifying the amount of time after which the sync has
not run that it should be considered overdue. "check_bucardo_sync"
issues a warning when a sync has not been run in this amount of
time. "expired"
An interval specifying the amount of time after which the sync has
not run that it should be considered expired. "check_bucardo_sync"
issues a critical message when a sync has not been run in this
amount of time. "track_rates"
Boolean indicating whether or not to track synchronization rates. "rebuild_index"
Boolean indicating whether or not to rebuild indexes after every
sync. Off by default. Optional. "strict_check"
Boolean indicating whether or not to be strict when comparing tables
in the sync. If the columns have different names or data types, the
validation will fail. But perhaps the columns are allowed to have
different names or data types. If so, disable "strict_check" and
column differences will result in warnings rather than failing the
validation. Defaults to true.

5. 启动bucardo

bucardo start
bucardo stop
bucardo restart
 
三,验证操作
  在原库操作
[postgres@sdserver40_222 ~]$ psql mydb
psql (9.5.)
Type "help" for help.
mydb=# delete from lottu03;
DELETE mydb=# insert into lottu03 values (1001,'bucardo');
INSERT

在目标库查看

[postgres@sdserver40_210 ~]$ psql mydb
psql (9.5.)
Type "help" for help. mydb=# select * from lottu03;
id | name
------+---------
| bucardo
( row)
 
四, FAQ
 Q1. 在执行bucardo install 操作出现

 Creating superuser 'bucardo'
Attempting to create and populate the bucardo database and schema INSTALLATION FAILED! (psql:/usr/local/share/bucardo/bucardo.schema:: ERROR: language "plperlu" does not exist
HINT: Use CREATE LANGUAGE to load the language into the database.)

解决方法;看提示知道需要“create language plperlu;”但是在我的环境之下

mydb=# create language plperlu;
ERROR: could not access file "$libdir/plperl": No such file or directory
 出现这种问题不奇怪;因在我的博客http://www.cnblogs.com/lottu/p/5149191.html  安装postgres中初始化时未加--with-perl;所以安装后lib目录下缺少plperl.so文件; 
解决方法:再来一边初始化postgrs; 把plperl.so复制到对应的lib目录下即可。

postgres=# CREATE LANGUAGE plperlu;
CREATE LANGUAG
 
Q2: 解决Q1;再一次执行bucardo install 操作出现

install_driver(Pg) failed: DBI version 1.614 required--this is only version 1.609 at /usr/share/perl5/Exporter/Heavy.pm line , <> line .
Compilation failed in require at (eval ) line , <> line .
 解决方法: 这个是我开始安装依赖包时;偷懒未安装DBI 包; 提示是需要更新 DBI 包;目前最新的是1.633版本;这里我们安装16.30就行 
 
Q3: 安装bucardo install 之后错误提示

perl: symbol lookup error: /usr/local/lib64/perl5/auto/DBD/Pg/Pg.so: undefined symbol: DBIc_AIADESTROY
解决方法: 这个缺少symbol: DBIc_AIADESTROY; 这个是Q2问题遗留下来的; 之前安装DBD_pg时是之前的DBI;现DBI更新了;需要重新安装DBD_pg
 
Q4:在启动bucardo start出现错误提示

Checking for existing processes
Can't locate boolean.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/local/share/perl5/Bucardo.pm line 34.
BEGIN failed--compilation aborted at /usr/local/share/perl5/Bucardo.pm line 34.
Compilation failed in require at /usr/local/bin/bucardo line 833.

解决方法: yum install perl-boolean

PostgreSQL的OGG -- bucardo的更多相关文章

  1. 使用ogg实现oracle到postgresql表的实时同步

    参考:https://docs.oracle.com/goldengate/c1221/gg-winux/index.html https://blog.51cto.com/hbxztc/188071 ...

  2. OGG For Oracle To PostgreSQL

    本文档描述OGG(Oracle goldengate)为Oracle同步到PostgreSQL数据库配置.在目前去“IOE”潮流.PostgreSQL确实是Oracle最好的替代品之一. 实验环境如下 ...

  3. 配置ogg从Oracle到PostgreSQL的同步复制json数据

    标签:goldengate postgresql oracle json 测试环境说明 Oracle:Windows 8.1 + Oracle 12.2.0.1.0 + GoldenGate 12.3 ...

  4. PostgreSQL高可用性、负载均衡、复制与集群方案介绍

    目录[-] 一.高可用性.负载均衡.复制的几个方案比较: 二.多节点集群方案比较 9.3官方文档(中文):http://58.58.27.50:8079/doc/html/9.3.1_zh/high- ...

  5. PostgreSQL and bloat

    The bucardo project has released its nagios plugins for PostgreSQL and we can extract from them this ...

  6. Top PG Clustering HA Solutions for PostgreSQL

    转自:https://severalnines.com/blog/top-pg-clustering-ha-solutions-postgresql If your system relies on  ...

  7. PostgreSQL逻辑复制之pglogical篇

    PostgreSQL逻辑复制之slony篇 一.pglogical介绍 pglogical 是 PostgreSQL 的拓展模块, 为 PostgreSQL 数据库提供了逻辑流复制发布和订阅的功能. ...

  8. PostgreSQL Replication之第六章 监控您的设置(4)

    6.4 处理监控工具 还有几个监控工具可以使您的日常生活更轻松. 其中最流行的监控工具是Nagios.它被广泛地使用,也支持各种软件组件. 要使用 Nagios 来监控您的 PostgreSQL 集群 ...

  9. PostgreSQL、Greenplum 日常监控 和 维护任务

    背景 Greenplum的日常监控点.评判标准,日常维护任务. 展示图层 由于一台主机可能跑多个实例,建议分层展示. 另外,即使是ON ECS虚拟机(一个虚拟机一个实例一对一的形态)的产品形态,实际上 ...

随机推荐

  1. 手机端布局rem 与vm的使用

    手机端原来的时候,在项目中使用js判断出html的字体,然后根据rem设置字体,但是js本着少用的原则,考虑用vm,vh等(顺带说一句,vm vh是网页可视区域宽度 高度 即浏览器宽度减去约16px) ...

  2. Python 随机数生成总结

    random.uniform(a, b),返回[a,b]之间的浮点数 random.randint(a, b),返回[a,b]之间的整数 random.randrange([start], stop[ ...

  3. Approaches to Vector Computation

    COMPUTER OR GANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION

  4. SQLServer一次性删除重复的数据

    delete from [GCPCore].[GCP.Product].[CityMall] where  AreaID in(select AreaID from [GCPCore].[GCP.Pr ...

  5. Hyper-V 与Broadcom网卡兼容问题

    最近在测虚拟机时,碰到一个网卡和Hyper-V不兼容问题,现在共享给大家参考,希望对大家有帮忙. 故障描述: Dell R720 Windows 2012操作系统下的Hyper-V环境后,虚拟机网络速 ...

  6. CentOS7.2 创建本地YUM源和局域网YUM源

    1背景 由于开发环境只有局域网,没法使用网上的各种YUM源,来回拷贝rpm包安装麻烦,还得解决依赖问题. 想着搭建个本地/局域网YUM源,方便自己跟同事安装软件. 2环境 [root@min-base ...

  7. 基于 Token 的身份验证方法

    使用基于 Token 的身份验证方法,在服务端不需要存储用户的登录记录.大概的流程是这样的: 客户端使用用户名跟密码请求登录 服务端收到请求,去验证用户名与密码 验证成功后,服务端会签发一个 Toke ...

  8. MQTT——服务器搭建(一)

    MQTT介绍 MQTT,是IBM推出的一种针对移动终端设备的基于TCP/IP的发布/预订协议,可以连接大量的远程传感器和控制设备: 轻量级的消息订阅和发布(publish/subscribe)协议 建 ...

  9. Linux 设置定时任务crontab命令

    1.  crontab命令概念 crontab命令用于设置周期性被执行的指令.该命令从标准输入设备读取指令,并将其存放于“crontab”文件中,以供之后读取和执行. cron 系统调度进程. 可以使 ...

  10. jQuery 跨域访问的三种方式 No 'Access-Control-Allow-Origin' header is present on the reque

    问题: XMLHttpRequest cannot load http://v.xxx.com. No 'Access-Control-Allow-Origin' header is present ...