oracle 数据库高可用之OGG的基础配置

前言:本文主要内容为当初刚开始接触OGG高可用架构时的部署,包含了我看到的一些比较好的文章的引用。目的都是为了让更多同学能更快的掌握相关知识,如果原创作者对此觉得损害了您的权益请留言。


目录:

理论、概念

基础实验



理论、概念,有助理解OGG的理解。学习必备。

感谢原文作者,原文地址:飞机票


理论、概念

一. OGG 概述 

OGG 全称Oracle Golden Gate。

历史:

Golden Gate公司于1995年成立于美国加州旧金山,它的名称源自旧金山闻名于世的金门大桥。两位创始人Eric Fish和Todd Davidson最初旨在为Tandem计算机公司设计一个容错系统,由于Golden Gate的健壮性和出色的数据复制功能,银行用它来把ATM网络的交易数据发送到IBM大型机,后来广泛地应用到金融行业及要求数据复制高效、健壮的各个行业。该公司于2009年9月被Oracle公司收购,在此之前Oracle和Golden Gate公司就有了长达超过10年的合作关系。在Oracle收购Golden Gate以后,与Oracle原有的 Data Guard互为补充,共同为企业提供跨平台实时数据同步的解决方案。

 

Golden Gate 软件分类说明:

(1)Golden Gate:包括GoldenGate Capture, Deliver 和Active Data Guard, XStream on Oracle DB,并支持各种开放数据系统,是我们通常讲的OGG的概念。
(2)Golden Gate Director:实际上,在下载的时候,可以发现没有Director的类目了,替换的是一个Golden Gate Management Pack的包,其实这个就是之前的OGG Director。Management Pack是基于浏览器的管理工具包,有限使用WebLogic SE,所以配置MP,需要先安装weblogic。
(3)Golden Gate Veridata:跨平台比较复制的源库和目标库,为Golden Gate源端和目标端提供数据比对和校验的功能。
另外,也有不太常见的:
(1)Golden Gate for Mainframe:包括GoldenGate Capture, Deliver for HP Non-Stop, IBM DB2 on 
Mainframe, plus Syncfile。
(2)Golden Gate Adapters:对Java、Flat File、Siebel等的接口包。
 
 
二 、OGG架构
 
支持的异构平台:

 

 
支持的架构形式:
 

 

 
 
 
实现的功能:
 
 

 

三、目录结构
 
目录          说明
BR        boundedrecover需要的checkpointfiles
cfg        配置OGG监控所需要的property和XML文件
dirchk    Extract或者Replicat进程创建的checkpointfile。cpe和cpr后缀
dirdat    trial文件的默认存放位置,2个用户定义的字符+6个数字组成
dirdef    异构数据定义文件,由DEFGEN生成
dirjar    OGGmonitor相关的jar包
dirpcs   进程状态文件
dirprm   参数文件
dirrpt    进程报告的存储目录
dirsql    Sql脚本
dirtmp  超出分配内存的事务临时存储目录
 
四、 OGG进程
 
在Oracle OGG 12c中,有如下组件:
(1)Extract
(2)Data pump
(3)Replicat
(4)Trails 或 extract files
(5)Checkpoints
(6)Manager
(7)Collector

  重点理解图:


简单逻辑架构(单向):

源                                              目标

mgr(管理进程)                          mgr(管理进程)   

extract(抽取进程)                      Replicat(复制应用进程)             

data pump(发送进程)

 

1.  Extract 进程

Extract 进程负责数据抽取工作。
Extract 可以配成如下两种模式:
(1)Initial Load:
在初始化装载过程中,Extract 进程直接从源对象中抽取当前的数据。

(2)Change synchronization: 
为了保证源数据和其他对象保持数据的一致,extract 进程会捕获源对象自初始化同步以后的DML 和DDL 的变化。
如果接收到的是rollback,那么Extract 会清除该事务之前的所有记录。
如果接收到的是commit,Extract 会将之前存储的事务信息进行持久化,即将事务信息写入磁盘上的trail 文件,然后按队列传送到目标库。 
 
2.Data Pump 进程
Data pump 进程是OGG 源库上的一个辅助Extract Group。
 
3. Replicat 进程
Replicate 进程运行在目标系统上,该进程会读取目标端的trail中的文件,并将解析为DML 或者DDL 语句,然后在目标数据库执行。
 
 
Replicate可以配置成如下模式:
(1)Initial loads:
(2)Change synchronization
 
4. Trails 文件
为了支持连续的extraction 和 replication 数据的改变,OGG抓取这些改变的数据临时存放在一个序列化的磁盘文件里, 这个文件就叫trail。 

Trail 文件可以放在源端或者目标端的系统里,甚至可以放到临时中转的系统上,这主要取决与GG 的配置,如果存放在local system上,就叫extract trail 或者 local trail,如果存放在remote system上就叫作remote trail。
 
创建和维护Trail 文件:
默认情况下,trails存放在GG 安装目录的dirdat 子目录下。
默认情况下,每个trails的文件是10M,为了保证进程的正常运行必须不断的创建的新的trail 文件。 这个过程由OGG 自动实现,并且不影响OGG的运行。
每个新生成的文件,文件名都会继承旧trail文件的前2个字母,然后加上6个数字,这样来进行唯一性约束。 数字从000000到999999。当数字到达999999时,又继续从000000开始。之前的trail 文件被覆盖。
 
补充: (Extract Files)
Extract file 可以是一个文件,或者配置成多个文件。 配置成多个文件可以避免触及操作对单个文件最大大小的限制。
Extract file 和 trail 文件很类似,但是Extract file中不会存储checkpoints的信息。  Extract file 会在运行时自动创建。
 
5. Checkpoints 机制 
Replicate都会checkpoint table 和 checkpoint file中记录事务的位置。我们也可以不使用checkpoint table。 
 
6. Manager 进程
Manager 是Golden Gate的控制进程,Manager 必须在所有的Golden Gate端运行,并且要在Extract 或者 Replicat 进程启动之前运行。 在Extract 或者 Replicat进程运行期间,需要一直保证Manager进程的运行,这样才能管理相关的资源。
 
Manager 进程有如下功能:
(1)启动Golden Gate 进程
(2)启动其他相关的进程
(3)维护进程的端口
(4)管理trail 进程
(5)创建event,error和threshold 的报告。
 
7.   Collector 进程
target的一个后台进程。
Collector  进程做如下工作:
(1) 将源端Extract 进程的请求发送到Manager进程,扫描并绑定可用的端口,并将端口信息返回给Manager 进程,然后分配给请求的的Extract 进程。

(2) Collector 进程会接收源库Extract 进程发送过来的改变的数据,并将数据写入target 系统的trail 文件中。
若srouce 端pump 进程起不来,collector 会锁trail 文件 。 那么我需要确认是哪个pump进程出现问题,view report pump#,查看后找到collector ,kill -9 杀死。
 
 
补充说明:
每个Extract 和 Replicat 进程需要大约25-55M的内存。

==========================================================================

(风景分割线)






再回忆一下架构:

简单逻辑架构(单向):

源                                              目标

mgr(管理进程)                          mgr(管理进程)   

extract(抽取进程)                      Replicat(复制应用进程)             

data pump(发送进程)

部署实验

============================================================

这里测试开启DDL同步,忽略初始化过程的单向同步。Oracle测试模式为test。

os:oel 6.5

db:11.2.0.4

ogg:11.2.1.0.1

本测试在源端没有使用pump进程。


1、安装GoldenGate

1.1 解压安装文件


源端和目标端都使用oracle用户进行下列操作:

创建ogg目录并安装:

mkdir -p /u01/ogg
tar xvf fbo_ggs_Linux_x64_ora11g_64bit.tar -C /u01/ogg

1.2 添加环境变量

在源端和目标端编辑oracle用户环境变量,在文件~/.bash_profile中加入下列行:

export PATH=/u01/ogg:$PATH
export LD_LIBRARY_PATH=/u01/ogg:$LD_LIBRARY_PATH

并使其生效:
source ~/.bash_profile

1.3 使用ggsci创建目录

在源端和目标端都执行:

[oracle@oraclesrc ogg]$ ggsci
GGSCI (oraclesrc) 1> create subdirs

2、配置源端数据库强制归档

查看源端数据库归档情况:

SQL> select log_mode,supplemental_log_data_min,force_logging from v$database;

LOG_MODE     SUPPLEME FOR
------------ -------- ---
NOARCHIVELOG NO       NO

修改归档模式:

SQL>shutdown immediate
SQL>startup mount
SQL>alter database archivelog;
SQL>alter database open;
SQL>alter database force logging;
SQL>alter database add supplemental log data;

3、开启DDL同步

配置DDL同步需要在源端执行以下操作

3.1 创建存放DDL信息的user

SQL> create user ogg identified by ogg default tablespace users temporary tablespace temp;

User created.

SQL> grant connect,resource,dba to ogg;

Grant succeeded.

SQL> grant create table,create sequence to ogg;

Grant succeeded.

SQL> grant execute on utl_file to ogg;

Grant succeeded.

在目标端同样创建一次该用户,用来存放同步相关信息。

3.2 执行脚本

进入OGG目录执行以下脚本:

[oracle@oraclesrc ~]$ cd /u01/ogg

SQL> @marker_setup.sql

Marker setup script

You will be prompted for the name of a schema for the Oracle GoldenGate database objects.
NOTE: The schema must be created prior to running this script.
NOTE: Stop all DDL replication before starting this installation.

Enter Oracle GoldenGate schema name:ogg


Marker setup table script complete, running verification script...
Please enter the name of a schema for the GoldenGate database objects:
Setting schema name to OGG

MARKER TABLE
-------------------------------
OK

MARKER SEQUENCE
-------------------------------
OK

Script complete.


SQL> @ddl_setup.sql


Oracle GoldenGate DDL Replication setup script

Verifying that current user has privileges to install DDL Replication...

You will be prompted for the name of a schema for the Oracle GoldenGate database objects.
NOTE: For an Oracle 10g source, the system recycle bin must be disabled. For Oracle 11g and later, it can be enabled.
NOTE: The schema must be created prior to running this script.
NOTE: Stop all DDL replication before starting this installation.

Enter Oracle GoldenGate schema name:ogg

Working, please wait ...
Spooling to file ddl_setup_spool.txt

Checking for sessions that are holding locks on Oracle Golden Gate metadata tables ...

Check complete.







Using OGG as a Oracle GoldenGate schema name.

Working, please wait ...

DDL replication setup script complete, running verification script...
Please enter the name of a schema for the GoldenGate database objects:
Setting schema name to OGG

CLEAR_TRACE STATUS:

Line/pos             Error
-------------------- -----------------------------------------------------------------
No errors            No errors

CREATE_TRACE STATUS:

Line/pos             Error
-------------------- -----------------------------------------------------------------
No errors            No errors

TRACE_PUT_LINE STATUS:

Line/pos             Error
-------------------- -----------------------------------------------------------------
No errors            No errors

INITIAL_SETUP STATUS:

Line/pos             Error
-------------------- -----------------------------------------------------------------
No errors            No errors

DDLVERSIONSPECIFIC PACKAGE STATUS:

Line/pos             Error
-------------------- -----------------------------------------------------------------
No errors            No errors

DDLREPLICATION PACKAGE STATUS:

Line/pos             Error
-------------------- -----------------------------------------------------------------
No errors            No errors

DDLREPLICATION PACKAGE BODY STATUS:

Line/pos             Error
-------------------- -----------------------------------------------------------------
No errors            No errors

DDL IGNORE TABLE
-----------------------------------
OK

DDL IGNORE LOG TABLE
-----------------------------------
OK

DDLAUX  PACKAGE STATUS:

Line/pos             Error
-------------------- -----------------------------------------------------------------
No errors            No errors

DDLAUX PACKAGE BODY STATUS:

Line/pos             Error
-------------------- -----------------------------------------------------------------
No errors            No errors

SYS.DDLCTXINFO  PACKAGE STATUS:

Line/pos             Error
-------------------- -----------------------------------------------------------------
No errors            No errors

SYS.DDLCTXINFO  PACKAGE BODY STATUS:

Line/pos             Error
-------------------- -----------------------------------------------------------------
No errors            No errors

DDL HISTORY TABLE
-----------------------------------
OK

DDL HISTORY TABLE(1)
-----------------------------------
OK

DDL DUMP TABLES
-----------------------------------
OK

DDL DUMP COLUMNS
-----------------------------------
OK

DDL DUMP LOG GROUPS
-----------------------------------
OK

DDL DUMP PARTITIONS
-----------------------------------
OK

DDL DUMP PRIMARY KEYS
-----------------------------------
OK

DDL SEQUENCE
-----------------------------------
OK

GGS_TEMP_COLS
-----------------------------------
OK

GGS_TEMP_UK
-----------------------------------
OK

DDL TRIGGER CODE STATUS:

Line/pos             Error
-------------------- -----------------------------------------------------------------
No errors            No errors

DDL TRIGGER INSTALL STATUS
-----------------------------------
OK

DDL TRIGGER RUNNING STATUS
----------------------------------------------------------------------
ENABLED

STAYMETADATA IN TRIGGER
----------------------------------------------------------------------
OFF

DDL TRIGGER SQL TRACING
----------------------------------------------------------------------
0

DDL TRIGGER TRACE LEVEL
----------------------------------------------------------------------
0

LOCATION OF DDL TRACE FILE
------------------------------------------------------------------------------------------------------------------------
/u01/app/oracle/diag/rdbms/orasrc/orasrc/trace/ggs_ddl_trace.log

Analyzing installation status...


STATUS OF DDL REPLICATION
------------------------------------------------------------------------------------------------------------------------
SUCCESSFUL installation of DDL Replication software components

Script complete.

SQL> @role_setup.sql

GGS Role setup script

This script will drop and recreate the role GGS_GGSUSER_ROLE
To use a different role name, quit this script and then edit the params.sql script to change the gg_role parameter to the preferred name. (Do not run the script.)

You will be prompted for the name of a schema for the GoldenGate database objects.
NOTE: The schema must be created prior to running this script.
NOTE: Stop all DDL replication before starting this installation.

Enter GoldenGate schema name:ogg
Wrote file role_setup_set.txt

PL/SQL procedure successfully completed.


Role setup script complete

Grant this role to each user assigned to the Extract, GGSCI, and Manager processes, by using the following SQL command:

GRANT GGS_GGSUSER_ROLE TO <loggedUser>

where <loggedUser> is the user assigned to the GoldenGate processes.


SQL> grant GGS_GGSUSER_ROLE to ogg; 
    

Grant succeeded.

SQL> @ddl_enable.sql;

Trigger altered.

至此DDL同步配置完成。

4、配置OGG进程

4.1 配置Manager进程


在源端和目标端配置Manager进程并启动:

注意当前目录为ogg。

[oracle@oraclesrc ogg]$ ggsci

Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Apr 23 2012 08:32:14

Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.



GGSCI (oraclesrc) 1> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     STOPPED                                           


GGSCI (oraclesrc) 2> edit params mgr

输入:
PORT 7809

这里输入了端口号,保存退出。

GGSCI (oraclesrc) 3> start manager 

Manager started.

4.2 配置源数据库的extract进程

测试登录数据库:

GGSCI (oraclesrc) 4> dblogin userid ogg@orasrc,password ogg
Successfully logged into database.

配置extract进程

GGSCI (oraclesrc) 5> add extract ext1,tranlog,begin now
EXTRACT added.

GGSCI (oraclesrc) 6> add rmttrail /u01/ogg/dirdat/lt,extract ext1
EXTTRAIL added.

GGSCI (oraclesrc) 7> edit params ext1

加入如下行:

extract ext1

userid ogg@orasrc, password ogg

rmthost 172.26.181.103, mgrport 7809

rmttrail /u01/ogg/dirdat/lt

ddl include mapped objname test.*;

table test.*;

GGSCI (oraclesrc) 8> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING                                           
EXTRACT     STOPPED     EXT1        00:00:00      00:03:26    


4.3 配置目标数据库的replicat进程

测试连接:

GGSCI (oracledest) 3> dblogin userid ogg@oradest,password ogg
Successfully logged into database.

GGSCI (oracledest) 4> add checkpointtable ogg.checkpoint

Successfully created checkpoint table ogg.checkpoint.

GGSCI (oracledest) 5> add replicat rep1,exttrail /u01/ogg/dirdat/lt,checkpointtable ogg.checkpoint
REPLICAT added.


GGSCI (oracledest) 6> edit params rep1

添加如下行:

replicat rep1
ASSUMETARGETDEFS
userid ogg@oradest,password ogg
discardfile /u01/ogg/dirdat/rep1_discard.txt,append,megabytes 10
DDL
map test.*,target test.*;

5、启动同步

源数据库:

GGSCI (oraclesrc) 1> start extract ext1

Sending START request to MANAGER ...
EXTRACT EXT1 starting


GGSCI (oraclesrc) 2> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING                                           
EXTRACT     RUNNING     EXT1        00:16:47      00:00:00    

目标数据库:

GGSCI (oracledest) 7> start replicat rep1

Sending START request to MANAGER ...
REPLICAT REP1 starting


GGSCI (oracledest) 8> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING                                           
REPLICAT    RUNNING     REP1        00:00:00      00:00:01    


6、测试效果

此时源库和目标库test用户数据如下:

SQL> conn test/test
Connected.
SQL> select * from t1;

no rows selected

在源库插入数据并创建新表:

SQL> insert into t1 values(1);

1 row created.

SQL> commit;

Commit complete.

SQL> create table t2 as select * from t1;

Table created.

在目标库查看数据同步情况:

SQL> select * from t1;

        C1
----------
         1

SQL> select * from t2;

        C1
----------
         1

DML及DDL同步正常。


7、注意事项


实际部署生产系统时,可能需要在目标端replicat参数中添加以下行,来禁止triggers和constraint deferred:

DBOPTIONS SUPPRESSTRIGGERS(For Oracle10.2.0.5 and later patches to 10.2.0.5, and for Oracle 11.2.0.2 and later 11gR2 versions)

DBOPTIONS DEFERREFCONST(For Oracle9.2.0.7 and later)


在更早的Oracle版本下,就需要手动禁止trigger和constraint deferred了


另外还需要禁止带有DML的JOB。


最后还需要在源端配置pump进程。

参考原文: 飞机票
==================================================================================
双向同步有点问题(需要调整一个参数)

同步模式:




如果以上搭建,太过基础,不能满足需求。

这里有篇非常详细的博客,送上优秀部署文章飞机票:真飞机




  • 1
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值