当前位置:   article > 正文

Oracle-OGG 12c 单向同步

ogg12g 单向同步配置
Oracle-OGG 12c 单向同步
0.环境说明
说明:
   源端:192.0.2.101
     操作系统:Oracle Linux Server release 6.5(cat /etc/issue)
     数据库:oracle_12.1.0.2.0 - 64bit
     Oracle_sid:prod4
     ogg:OGG-12.2.0.1.1-ReleaseNotes
   目标端:192.0.2.102
     操作系统:Oracle Linux Server release 6.5
     数据库:oracle_12.1.0.2.0 - 64bit
     Oracle_sid:emrep
     ogg:OGG-12.2.0.1.1-ReleaseNotes
目标:
     将101里prod4下的hr数据同步到102里emrep下的hr
1.环境变量
源端:host01
export ORACLE_SID=PROD4
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.1.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
alias ss='sqlplus / as sysdba'
stty erase ^H
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
export nls_lang=american_america.zhs16gbk


目标端:host02
export ORACLE_SID=EMREP
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.1.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
alias ss='sqlplus / as sysdba'
stty erase ^H
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
export nls_lang=american_america.zhs16gbk


说明:设置LD_LIBRARY_PATH,为了安装OGG所用的动态链接库。如果没有配置这个路径的话,在使用OGG执行指令./ggsci的过程中会报找不到动态链接库的错误,可以在不设置LD_LIBRARY_PATH的情形下自行尝试一下错误的复现。
[oracle@host01 ogg]$ ./ggsci
./ggsci: error while loading shared libraries: libnnz12.so: cannot open shared object file: No such file or directory


2.安装OGG 
在 OGG 11 中,是直接解压缩安装文件就可以了,到了 OGG 12c 的版本,OGG 使用 OUI 来进行安装。
源端和目标端均安装,步骤一样。
[oracle@host01 work]$ unzip 121210_fbo_ggs_Linux_x64_shiphome.zip
[oracle@host01 work]$ cd fbo_ggs_Linux_x64_shiphome/Disk1/
[oracle@host01 Disk1]$ ls
install  response  runInstaller  stage
[oracle@host01 Disk1]$ export LANG=C
[oracle@host01 Disk1]$ export DISPLAY=192.168.31.67:0.0
[oracle@host01 Disk1]$ xhost +
access control disabled, clients can connect from any host
[oracle@host01 Disk1]$ ./runInstaller
 
 
 
 
 
3. 验证,能正常使用,且进程MANAGER已启动。如果MANAGER未启动,执行start manager。
主机在非 GG_HOME 目录下执行,会报错,只能在 GG_HOME 下执行该命令:
[oracle@host01 ogg]$ ./ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 12.1.2.1.0 OGGCORE_12.1.2.1.0_PLATFORMS_140727.2135.1_FBO
Linux, x64, 64bit (optimized), Oracle 12c on Aug  7 2014 10:21:34
Operating system character set identified as UTF-8.
Copyright (C) 1995, 2014, Oracle and/or its affiliates. All rights reserved.


GGSCI (host01.example.com) 1> info all 
Program     Status      Group       Lag at Chkpt  Time Since Chkpt
MANAGER     RUNNING                                           


GGSCI (host01.example.com) 2> info manager
Manager is running (IP port host01.example.com.7809, Process ID 5510).
GGSCI (host01.example.com) 3> 


在 Oracle 11g 中,安装完之后,还需要用 ggsci 执行 create subdirs 创建 OGG 的目录,到了 12c,就不
用创建了,安装完后,目录都已建好。
4. 开启归档模式、强制日志、附加日志(源端)
GoldenGate 通过抓取源端数据库重做日志进行分析,将获取的数据应用到目标端,实现数据同步。因
此,源数据库需要必须处于归档模式,并启用附加日志和强制日志。
添加附加日志来唯一标识一行记录,要在数据库级别打开最小开关。为了减少整个数据库添加附加日志,以及减少归档量。
查看 v$database 看这 3 个参数是否已开启,使用 OGG 必须是开启状态
--修改前
SYS@PROD4>select LOG_MODE, SUPPLEMENTAL_LOG_DATA_MIN,FORCE_LOGGING from v$database;
LOG_MODE     SUPPLEME FORCE_LOGGING
------------ -------- ---------------------------------------
ARCHIVELOG   NO       NO
SYS@PROD4>alter system set log_archive_dest_1='location=/u01/archive';           
System altered.
SYS@PROD4>alter database force logging;
Database altered.
SYS@PROD4>alter database add supplemental log data;
Database altered.
SYS@PROD4>alter database add supplemental log data (primary key) columns;
Database altered.
--修改后
SYS@PROD4>select LOG_MODE, SUPPLEMENTAL_LOG_DATA_MIN,FORCE_LOGGING from v$database;
LOG_MODE     SUPPLEME FORCE_LOGGING
------------ -------- ---------------------------------------
ARCHIVELOG   YES      YES
--切换日志组,使附加日志开关生效。
SYS@PROD4>alter system switch logfile;
System altered.
SYS@PROD4>
解释:在正常情况下,oracle是用rowid来唯一标示一行记录的,但ogg这里不够,需要打开附加日志。
--在源和目标库上设置enable_ogg_replication初始化参数为true。
SYS@PROD4>show parameter enable_goldengate_replication
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
enable_goldengate_replication        boolean     FALSE
SYS@PROD4>alter system set enable_goldengate_replication=true;
System altered.
SYS@PROD4>show parameter enable_goldengate_replication
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
enable_goldengate_replication        boolean     TRUE
SYS@PROD4>
注意:如未设置,后续的抽取进程s_e1起不来,且日志也会提示,需要修改enable_goldengate_replication参数为ture。
2016-10-19 12:08:03  ERROR   OGG-02091  Oracle GoldenGate Capture for Oracle, s_e1.prm:  Operation not supported because enable_goldengate_replication is not set to true.


5.创建存放 DDL 信息的 user 并赋权
SYS@PROD4>create tablespace ogg datafile '/u01/app/oracle/oradata/PROD4/ogg01.dbf' size 200m autoextend on;
Tablespace created.
--注意,在 OGG 11g 可以使用默认的 users 等表空间,但 12C 中必须独立的表空间,否则会报错。
SYS@PROD4>create user ogg identified by ogg default tablespace ogg temporary tablespace temp;
User created.
SYS@PROD4>grant connect,resource to ogg;
Grant succeeded.
SYS@PROD4>grant execute on utl_file to ogg;
Grant succeeded.
SYS@PROD4>
/*--在早期ogg版本里,需要赋予的权限较多。在ogg 12c里,在执行后续相关脚本时,有权限赋予的一步。
grant connect,resource,create session,select any dictionary,select any table,select any transaction,alter any table,alter session,flashback any table to ogg;
grant execute on utl_file to ogg;
grant connect to ogg;
grant alter any table to ogg;
grant alter session to ogg;
grant create session to ogg;
grant flashback any table to ogg;
grant select any dictionary to ogg;
grant select any table to ogg;
grant resource to ogg;
grant select any transaction to ogg;
*/


退出所有使用 Oracle 的 session,然后使用 SYSDBA 权限的用户执行执行OGG的配置脚本。
--创建 DDL 标记表
SYS@PROD4>@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


--将在数据库中创建捕获 DDL 语句的 Trigger 等必要组件
SYS@PROD4>@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
--创建 GGS_GGSUSER_ROLE 角色
SYS@PROD4>@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
--授予给 extract group 参数中定义的 userid 用户
SYS@PROD4>grant GGS_GGSUSER_ROLE to ogg;
--启用 ddl 捕获触发器
SYS@PROD4>@ddl_enable.sql
--还有 2 个可选的脚本,用来提高 DDL 复制性能:
--创建 DBMS_SHARED_POOL 包
SYS@PROD4>@?/rdbms/admin/dbmspool.sql
SYS@PROD4>@ddl_pin.sql ogg
--通过 dbms_shared_pool.keep 存储过程将 DDLReplication 相关的对象 keep 在共享池中,以保证这些对
象不要 reload,提升性能。
执行上述的脚本,在出现输入提示的时候,输入ogg用户。


6.数据初始化.
在 将源端prod4下的hr数据初始化到目标端emrep下
[oracle@host01 ~]$ expdp system/oracle directory=exp_dir dumpfile=hr_metadata_only_20161020.dmp logfile=hr_metadata_only_20161020.log schemas=hr content=metadata_only
[oracle@host01 ~]$ expdp system/oracle directory=exp_dir dumpfile= hr_metadata_only_20161020.dmp logfile=hr_metadata_only_20161020.log schemas=hr content=metadata_only flashback_scn=2129706
[oracle@host01 ~]$ scp hr_metadata_only_20161020.dmp oracle@host02:/home/oracle/work/.


[oracle@host02 work]$ impdp system/oracle directory=exp_dir dumpfile=hr_metadata_only_20161020.dmp logfile=hr_metadata_only_20161020_imp.log
--初始化完成后,源端JOB_HISTORY数据记录。
HR@PROD4>select count(*) from JOB_HISTORY;
  COUNT(*)
----------
        10
--初始化完成后,目标端JOB_HISTORY数据记录。
HR@EMREP>select count(*) from JOB_HISTORY;
  COUNT(*)
----------
        0


7.在 Source 和 Target 上配置 Manager.
在 将源端prod4下的hr数据初始化到目标端emrep下
[oracle@host01 ogg]$ ./ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 12.1.2.1.0 OGGCORE_12.1.2.1.0_PLATFORMS_140727.2135.1_FBO
Linux, x64, 64bit (optimized), Oracle 12c on Aug  7 2014 10:21:34
Operating system character set identified as UTF-8.
Copyright (C) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
GGSCI (host01.example.com) 1> info all
Program     Status      Group       Lag at Chkpt  Time Since Chkpt
MANAGER     RUNNING                                           
GGSCI (host01.example.com) 2> edit params mgr 
PORT 7809
DYNAMICPORTLIST 7810-7890
AUTOSTART EXTRACT *
AUTORESTART EXTRACT *,RETRIES 5, WAITMINUTES 3,RESETMINUTES 5
PURGEOLDEXTRACTS /u01/app/oracle/ogg/dirdat/*,usecheckpoints, minkeepdays 7    
LAGREPORTHOURS 1
LAGINFOMINUTES 30
LAGCRITICALMINUTES 45


"dirprm/mgr.prm" 8L, 246C written
GGSCI (host01.example.com) 3>


说明:  
port 指定mgr进程通信端口
dynamicportlist 表示mgr进程可以为源与目的端动态通信指定端口
autorestart extract 表示自动重启extract进程组,每2分钟尝试重启所有进程,重试5次,每5分钟清零。
配置参数后,重启mgr进程生效
GGSCI (host01.example.com) 6> stop mgr
Manager process is required by other GGS processes.
Are you sure you want to stop it (y/n)?y
Sending STOP request to MANAGER ...
Request processed.
Manager stopped.
GGSCI (host01.example.com) 7> start mgr
Manager started.
GGSCI (host01.example.com) 8> info all
Program     Status      Group       Lag at Chkpt  Time Since Chkpt
MANAGER     RUNNING                                           
GGSCI (host01.example.com) 9>


配置tnsnames. 然后测试。
 [oracle@host02 admin]$ cat tnsnames.ora 
EMREP =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = host02.example.com)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = EMREP.example.com)
    )
  )


PROD4 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = host01.example.com)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = PROD4.example.com)
    )
  )
[oracle@host02 admin]$
8.配置 SourceDB 的复制队列
先连接到数据库,测试连接:
GGSCI (host01.example.com) 9> dblogin userid ogg, password ogg
Successfully logged into database.
GGSCI (host01.example.com as ogg@PROD4) 10>
--增加 Extract 进程
GGSCI (host01.example.com as ogg@PROD4) 10> add extract S_E1,tranlog, begin now
EXTRACT added.
--添加本地trail文件
GGSCI (host01.example.com as ogg@PROD4) 11> add exttrail /u01/app/oracle/ogg/dirdat/se, extract S_E1
EXTTRAIL added.
说明: 创建本地trail文件,主extract进程负责写这部分文件,pump负责把这部分文件传到目标服务器端。
--修改抽取进程 S_E1 参数:
GGSCI (host01.example.com as ogg@PROD4) 12> edit param S_E1
extract S_E1
setenv (ORACLE_SID=PROD4)
setenv (NLS_LANG=AMERICAN_AMERICA.ZHS16GBK) 
dynamicresolution
userid ogg, password ogg
exttrail /u01/app/oracle/ogg/dirdat/se
ddl include all
table hr.*;
说明:  
extract eora定义extract进程名字
dynamicresolution     
setenv设置环境变量
userid 登录数据库
exttrail指定本地trail文件地址
table 定义同步的表




--添加pump进程
GGSCI (host01.example.com) 1> add extract S_P1,exttrailsource /u01/app/oracle/ogg/dirdat/se
EXTRACT added.
--添加远程trail文件
GGSCI (host01.example.com) 2> add rmttrail /u01/app/oracle/ogg/dirdat/se, extract S_P1,megabytes 10
RMTTRAIL added.


GGSCI (host01.example.com) 3> edit param S_P1
extract S_P1
userid ogg, password ogg 
dynamicresolution
passthru
rmthost 31.2.3.12, mgrport 7809,compress 
rmttrail /u01/app/oracle/ogg/dirdat/se
table hr.*;
GGSCI (host01.example.com) 4>
9.Target上配置 DB 同步队列
--添加检查表
说明: 当我们在GLOBALS 文件里指定了默认的checkpoint 之后,新的Replicat groups 在创建时会自动使用这个参数,不需要其他指令
GGSCI (host02.example.com) 6> edit params ./GLOBAL
GGSCHEMA ogg
CHECKPOINTTABLE ogg.checkpoint
exit # 这里需要退出ggsci终端
GGSCI (host02.example.com) 7> dblogin userid ogg,password ogg
Successfully logged into database.
GGSCI (host02.example.com as ogg@EMREP) 8> add checkpointtable ogg.checkpoint
Successfully created checkpoint table ogg.checkpoint.
--添加复制进程
GGSCI (host02.example.com as ogg@EMREP) 9> add replicat T_R1,exttrail /u01/app/oracle/ogg/dirdat/se, checkpointtable ogg.checkpoint
REPLICAT added.
--配置目标端Peplicat进程组
GGSCI (host02.example.com as ogg@EMREP) 10> edit params T_R1
replicat T_R1
setenv (ORACLE_SID=EMREP)
setenv (NLS_LANG=AMERICAN_AMERICA.ZHS16GBK)
ASSUMETARGETDEFS
handlecollisions
userid ogg,password ogg
reperror default,discard 
discardfile /u01/app/oracle/ogg/dirdat/T_R1_discard.txt,append, megabytes 10
ddl include all
ddlerror default ignore retryop
map hr.*, target hr.*;
GGSCI (host02.example.com as ogg@EMREP) 11> start T_R1


10.测试及验证
--源端建立测试表
HR@PROD4>create table t_test as select * from job_history where 1=2;
Table created.
HR@PROD4>select count(*) from t_test;
  COUNT(*)
----------
         0
--源端写入数据
HR@PROD4>insert into t_test select * from job_history;
10 rows created.
HR@PROD4>commit;
Commit complete.
HR@PROD4>select count(*) from t_test;
  COUNT(*)
----------
        10
--目标端验证数据
HR@EMREP>select count(*) from t_test;
  COUNT(*)
----------
        10
HR@EMREP>


11.后续小结
问题1:数据初始化的问题。例如在使用DSG进行数据抽取时,目标端仅需导入元数据,然后系统自动实现数据的全量抽取。ogg怎么配置后能实现类似dsg形式的全量抽取。
问题2:双向复制的练习。
问题3:普通实例往pdb抽取、pdb往普通实例抽取的练习。


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29352310/viewspace-2127195/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29352310/viewspace-2127195/

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/616657
推荐阅读
相关标签
  

闽ICP备14008679号