目录

19c单实例配置GoldenGate 并进行用户数据同步测试

当前数据使用的是经典模式配置GoldenGate 进行数据同步,关于容器数据库配置GoldenGate 请参阅:

Configuring Oracle GoldenGate in a Multitenant Container Database (Doc ID 2031069.1)

一、数据库操作

1、开启数据库附加日志

开启的最小附加日志和强制日志

SQL> alter database add supplemental log data;
SQL> select supplemental_log_data_min from v$database;
SQL> alter database force logging;
SQL> select force_logging from v$database;

2、开启数据库归档模式

RAC所有节点
SQL> shutdown immediate 实例1:
SQL> startup mount
SQL> alter database archivelog;
SQL> archive log list;
SQL> alter database open; 实例2 :
直接执行
SQL> startup

如果需要修改归档日志路径:

SQL> alter system set log_archive_dest_1= 'location=<归档路径>' sid='*';

3、开启goldengate同步

SQL> show parameter gol

NAME				     				TYPE	 VALUE
------------------------------------ ----------- ------------------------------
enable_goldengate_replication boolean FALSE SQL> alter system set ENABLE_GOLDENGATE_REPLICATION=true; System altered. SQL> show parameter gol NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
enable_goldengate_replication boolean TRUE

4、创建goldengate管理用户

--1、create tablespace
create tablespace gguser_dat datafile '/u01/app/oracle/oradata/ORCL/gguser_dat_01.dbf' size 100m autoextend on next 100m maxsize unlimited; --2、create the user
create user gguser IDENTIFIED BY gguser123
default tablespace gguser_dat
temporary tablespace TEMP
profile DEFAULT; --3、Grant role privileges
grant connect to GGUSER;
grant resource to GGUSER; --4、Grant system privileges
grant alter any index to GGUSER;
grant alter any table to GGUSER;
grant alter session to GGUSER;
grant alter system to GGUSER;
grant create any directory to GGUSER;
grant create any index to GGUSER;
grant create any table to GGUSER;
grant create session to GGUSER;
grant delete any table to GGUSER;
grant drop any directory to GGUSER;
grant drop any index to GGUSER;
grant drop any table to GGUSER;
grant flashback any table to GGUSER;
grant insert any table to GGUSER;
grant select any dictionary to GGUSER;
grant select any table to GGUSER;
grant select any transaction to GGUSER;
grant unlimited tablespace to GGUSER;
grant update any table to GGUSER;

5、集成捕获所需权限授权

授予gguser用户集成捕获所需的权限

SQL> exec dbms_goldengate_auth.grant_admin_privilege('GGUSER',container=>'ALL');

请参阅:Integrated Capture Process Cannot Start with OGG-02061 at Multitenant Configuration (Doc ID 2748951.1)

6、创建测试用户及测试表

--1、创建测试用户表空间(SHUAIGE_DAT)
create tablespace shuaige_dat datafile '/u01/app/oracle/oradata/ORCL/shuaige_dat_01.dbf' size 100M autoextend on next 100m maxsize unlimited; --2、创建测试用户(SHUAIGE),密码(shuaige123)
create user SHUAIGE IDENTIFIED BY shuaige123
default tablespace shuaige_dat
temporary tablespace TEMP
quota unlimited ON shuaige_dat
profile DEFAULT; --3、授予用户(SHUAIGE)用户数据库角色
grant connect to SHUAIGE;
grant resource to SHUAIGE; --4、创建测试表 --测试表(T1)
CREATE TABLE SHUAIGE.T1 (
ID number(10),
NAME varchar2(30))
tablespace shuaige_dat; --测试表(T2)
CREATE TABLE SHUAIGE.T2 (
ID number(10),
NAME varchar2(30))
tablespace shuaige_dat; --5、给测试表创建主键约束 --创建表主键(T1),主键名(T1_PK),主键列(ID)
alter table SHUAIGE.T1 add constraint T1_PK primary key(id)
using index
tablespace shuaige_dat; --创建表主键(T2),主键名(T2_PK),主键列(ID)
alter table SHUAIGE.T2 add constraint T2_PK primary key(id)
using index
tablespace shuaige_dat;

测试目标即(SHUAIGE.T1)表数据使用Goldengate同步到(SHUAIGE.T2)表

二、配置GOLDENGATE

1、配置MGR

GGSCI > edit params mgr

添加以下内容:

PORT 7809

DYNAMICPORTLIST 7810-7899

USERID gguser, PASSWORD AACAAAAAAAAAAAJAACQGHDZHDDGFMEACUCUEPFYGGJBFJGIH BLOWFISH, ENCRYPTKEY DEFAULT

AUTORESTART ER *, RETRIES 5, WAITMINUTES 1, RESETMINUTES 10

PURGEOLDEXTRACTS ./dirdat/*, USECHECKPOINTS, MINKEEPDAYS 1

LAGINFOMINUTES 10
LAGCRITICALMINUTES 60

使用goldengate默认生成的key的加密方法:encrypt password <要进行加密的密码>,ENCRYPTKEY default Using default key

示例:(用户:gguser,密码:gguser123),对该密码进行加密

GGSCI  27> encrypt password gguser123,ENCRYPTKEY default Using default key
Using Blowfish encryption with DEFAULT key.
Encrypted password: AACAAAAAAAAAAAJAACQGHDZHDDGFMEACUCUEPFYGGJBFJGIH
Algorithm used: BLOWFISH

为了安全起见最好在goldengate配置文件中使用加密密码进行配置,当然明文密码也是可用的

2、重启MGR

GGSCI > 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 > start mgr
Manager started.

3、配置GLOBALS

GGSCI > edit params ./GLOBALS

添加以下内容:

CHECKPOINTTABLE gguser.checkpoint
OUTPUTFILEUMASK 027

4、创建checkpoint表

GGSCI > DBLOGIN USERID gguser, PASSWORD AACAAAAAAAAAAAJAACQGHDZHDDGFMEACUCUEPFYGGJBFJGIH BLOWFISH, ENCRYPTKEY DEFAULT

Successfully logged into database.

GGSCI > ADD CHECKPOINTTABLE gguser.checkpoint

Successfully created checkpoint table gguser.checkpoint.

或使用明文密码登录数据库:dblogin userid , password ,示例如下:

GGSCI > dblogin userid gguser, password gguser123
Successfully logged into database.

5、添加表级别的附加日志

ggsci命令行中登录数据库

GGSCI > DBLOGIN USERID gguser, PASSWORD AACAAAAAAAAAAAJAACQGHDZHDDGFMEACUCUEPFYGGJBFJGIH BLOWFISH, ENCRYPTKEY DEFAULT

Successfully logged into database.
  1. 若数据全部同步没有条件、没有主键表、添加表级别附加日志
    GGSCI > add trandata 用户名.表名
  2. 若数据同步有条件过滤并且表有主键,添加表级别附加日志
    GGSCI > add trandata 用户名.表名,clos(列名)

info trandata 用户.表名查询trandata是否添加成功(enable),未添加trandata为(disable)状态

按用户生成添加、查询、删除表级别附加日志sql,示例:

#在数据库中执行:
select 'add trandata '||owner||'.'||table_name from dba_tables where owner = 'SHUAIGE';
select 'info trandata '||owner||'.'||table_name from dba_tables where owner = 'SHUAIGE';
select 'delete trandata '||owner||'.'||table_name from dba_tables where owner = 'SHUAIGE';
#在GGSCI中执行:
add trandata SHUAIGE.T1
add trandata SHUAIGE.T2 info trandata SHUAIGE.T1
info trandata SHUAIGE.T2

添加成功输出如下:

GGSCI > add trandata SHUAIGE.T1

2022-05-10 10:41:10  INFO    OGG-15132  Logging of supplemental redo data enabled for table SHUAIGE.T1.

2022-05-10 10:41:10  INFO    OGG-15133  TRANDATA for scheduling columns has been added on table SHUAIGE.T1.

2022-05-10 10:41:10  INFO    OGG-15135  TRANDATA for instantiation CSN has been added on table SHUAIGE.T1.

2022-05-10 10:41:11  INFO    OGG-10471  ***** Oracle Goldengate support information on table SHUAIGE.T1 *****
Oracle Goldengate support native capture on table SHUAIGE.T1.
Oracle Goldengate marked following column as key columns on table SHUAIGE.T1: ID. GGSCI > add trandata SHUAIGE.T2
2022-05-10 10:41:11 INFO OGG-15132 Logging of supplemental redo data enabled for table SHUAIGE.T2. 2022-05-10 10:41:11 INFO OGG-15133 TRANDATA for scheduling columns has been added on table SHUAIGE.T2. 2022-05-10 10:41:11 INFO OGG-15135 TRANDATA for instantiation CSN has been added on table SHUAIGE.T2. 2022-05-10 10:41:11 INFO OGG-10471 ***** Oracle Goldengate support information on table SHUAIGE.T2 *****
Oracle Goldengate support native capture on table SHUAIGE.T2.
Oracle Goldengate marked following column as key columns on table SHUAIGE.T2: ID.

校验trandata输出如下:

GGSCI > info trandata SHUAIGE.T1

2022-05-10 10:43:26  INFO    OGG-10471  ***** Oracle Goldengate support information on table SHUAIGE.T1 *****
Oracle Goldengate support native capture on table SHUAIGE.T1.
Oracle Goldengate marked following column as key columns on table SHUAIGE.T1: ID. Logging of supplemental redo log data is enabled for table SHUAIGE.T1. Columns supplementally logged for table SHUAIGE.T1: "ID". Prepared CSN for table SHUAIGE.T1: 2175964 GGSCI > info trandata SHUAIGE.T2 2022-05-10 10:43:33 INFO OGG-10471 ***** Oracle Goldengate support information on table SHUAIGE.T2 *****
Oracle Goldengate support native capture on table SHUAIGE.T2.
Oracle Goldengate marked following column as key columns on table SHUAIGE.T2: ID. Logging of supplemental redo log data is enabled for table SHUAIGE.T2. Columns supplementally logged for table SHUAIGE.T2: "ID". Prepared CSN for table SHUAIGE.T2: 2176044
GGSCI (ocp19c as gguser@orcl) 14>

6、查询数据库字符集

当前数据库session的环境字符集:

SQL> select userenv('language') from dual;

AMERICAN_AMERICA.AL32UTF8

7、添加抽取进程

GGSCI > add extract ef_test1,TRANLOG,BEGIN NOW

GGSCI > add exttrail ./dirdat/cs,extract ef_test1

GGSCI > edit params ef_test1

(./dirdat/cs)表示extract进程生成exttrail文件的位置和文件名开头为cs,示例文件:

-rw-r----- 1 ggate ggate 1823 May 10 11:24 cs000000000

goldengate所有的进程(extract、replicat)的名字都不能超过八个字符,在添加进程和设置配置文件的时候最好起一些有含义的名字

这个示例(ef_test1)ef代表捕获进程也叫抽取进程,test1就代表第一个测试

添加以下内容:

EXTRACT ef_test1

SETENV (ORACLE_SID="orcl")
SETENV(NLS_LANG="AMERICAN_AMERICA.AL32UTF8") USERID gguser, PASSWORD AACAAAAAAAAAAAJAACQGHDZHDDGFMEACUCUEPFYGGJBFJGIH BLOWFISH, ENCRYPTKEY DEFAULT NUMFILES 3000
EOFDELAYCSECS 10 EXTTRAIL ./dirdat/cs TRANLOGOPTIONS LOGRETENTION DISABLED
TRANLOGOPTIONS DBLOGREADER
TRANLOGOPTIONS DBLOGREADERBUFSIZE 1048576
TRANLOGOPTIONS _NOREADAHEAD ANY WARNLONGTRANS 4H, CHECKINTERVAL 300 GETTRUNCATES
GETUPDATEBEFORES NOCOMPRESSDELETES CACHEMGR, CACHESIZE 128MB -- TABLES
TABLE shuaige.t1;

注意:进程中所有的参数都可以按照实际的生产或测试需求添加,以上参数是我比较常用的

我发现在19c 配置goldengate与11g配置goldengate不同的地方和个别参数限制,如下:

  1. 不能在添加抽取进程时指定线程(thread)参数(单实例)
  2. value "3 M" is out of legal range (300 s - 20000000 s) for [checkinterval].
  3. CACHESIZE. Range values between: min 128 - max 2097152 MB.

在GGSCI命令行输入help查询更多帮助信息

8、添加复制进程

GGSCI > add replicat rf_test1,exttrail ./dirdat/cs, checkpointtable gguser.checkpoint

GGSCI > edit params rf_test1

这里的(./dirdat/cs)表示要指定replicat进程读取的exttrail文件

在(3、配置GLOBALS)中已经配置了全局GLOBALS,添加复制进程时会自动添加到gguser.checkpoint,若添加时手动指定checkpoint表,则以手动指定的为准

添加以下内容:

REPLICAT rf_test1

SETENV(NLS_LANG="AMERICAN_AMERICA.AL32UTF8")

USERID gguser, PASSWORD AACAAAAAAAAAAAJAACQGHDZHDDGFMEACUCUEPFYGGJBFJGIH BLOWFISH, ENCRYPTKEY DEFAULT

SQLEXEC "ALTER SESSION SET COMMIT_LOGGING=IMMEDIATE"
SQLEXEC "ALTER SESSION SET COMMIT_WAIT=NOWAIT" NUMFILES 3000
EOFDELAYCSECS 10 DISCARDFILE ./dirdsc/rf_test1.dsc, APPEND, MEGABYTES 512
DISCARDROLLOVER AT 00:00 ASSUMETARGETDEFS ALLOWNOOPUPDATES GETTRUNCATES
GETUPDATEBEFORES --TABLES
MAP shuaige.t1, TARGET shuaige.t2;

注意:进程中所有的参数都可以按照实际的生产或测试需求添加,以上参数是我比较常用的

这个示例(rf_test1)rf代表复制进程也叫应用进程,所有rf_test1就代表第一个测试的复制进程

使用ggate用户手动创建dirdsc目录,因为我在这个复制进程中配置了DISCARDFILE参数,会在指定目录下生成.dsc文件

mkdir -p /ggate/dirdsc

9、启动抽取进程与复制进程

GGSCI > start ef_test1
GGSCI > start rf_test1

查看进程状态

GGSCI > info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING
EXTRACT RUNNING EF_TEST1 00:00:00 00:00:06
REPLICAT RUNNING RF_TEST1 00:00:00 00:00:07

三、进行数据同步测试:

1、数据插入测试

(1)向SHUAIGE.T1表中插入一条数据
SYS@orcl> insert into shuaige.T1 values(1,'李清照');

1 row created.

SYS@orcl> commit;

Commit complete.
(2)检查进程同步状态
GGSCI >  stats ef_test1,total

Sending STATS request to EXTRACT EF_TEST1 ...

Start of Statistics at 2022-05-10 11:25:49.

Output to ./dirdat/cs:

Extracting from SHUAIGE.T1 to SHUAIGE.T1:

*** Total statistics since 2022-05-10 11:24:10 ***
Total inserts 1.00
Total updates 0.00
Total deletes 0.00
Total upserts 0.00
Total discards 0.00
Total operations 1.00 End of Statistics. GGSCI > stats rf_test1,total Sending STATS request to REPLICAT RF_TEST1 ... Start of Statistics at 2022-05-10 11:26:41. Replicating from SHUAIGE.T1 to SHUAIGE.T2: *** Total statistics since 2022-05-10 11:24:11 ***
Total inserts 1.00
Total updates 0.00
Total deletes 0.00
Total upserts 0.00
Total discards 0.00
Total operations 1.00 End of Statistics.

可以看到插入的数据已经成功的捕获和应用了

常用检查进程状态命令stats,EXTRACT与REPLICAT进程都适用

GGSCI > stats EXTRACT,total --查看当前进程所有的操作状态

GGSCI > stats EXTRACT,hourly --查看当前小时整点到当前时间所有的操作状态

GGSCI > stats EXTRACT,daily --查看今日凌晨0点到当前时间所有的操作状态

详情查看(help stats EXTRACT)(help stats REPLICAT):

(3)验证数据是否同步
SYS@orcl> select * from shuaige.t1;

		ID NAME
---------- ------------------------------
1 李清照 SYS@orcl> select * from shuaige.t2; ID NAME
---------- ------------------------------
1 李清照

2、数据更新测试

(1)在SHUAIGE.T1表中更新一条数据
SYS@orcl> update shuaige.t1 set name='辛弃疾' where id = '1';

1 row updated.

SYS@orcl> commit;

Commit complete.
(2)检查进程同步状态
GGSCI (ocp19c) 17> stats ef_test1,total

Sending STATS request to EXTRACT EF_TEST1 ...

Start of Statistics at 2022-05-10 15:49:43.

Output to ./dirdat/cs:

Extracting from SHUAIGE.T1 to SHUAIGE.T1:

*** Total statistics since 2022-05-10 11:24:10 ***
Total inserts 1.00
Total updates 1.00
Total befores 1.00
Total deletes 0.00
Total upserts 0.00
Total discards 0.00
Total operations 2.00 End of Statistics. GGSCI (ocp19c) 18> stats rf_test1,total Sending STATS request to REPLICAT RF_TEST1 ... Start of Statistics at 2022-05-10 15:50:07. Replicating from SHUAIGE.T1 to SHUAIGE.T2: *** Total statistics since 2022-05-10 11:24:11 ***
Total inserts 1.00
Total updates 1.00
Total befores 1.00
Total deletes 0.00
Total upserts 0.00
Total discards 0.00
Total operations 2.00 End of Statistics.

可以看到更新的数据已经成功的捕获和应用了

(3)验证数据是否同步
SYS@orcl> select * from shuaige.t1;

		ID NAME
---------- ------------------------------
1 辛弃疾 SYS@orcl> select * from shuaige.t2; ID NAME
---------- ------------------------------
1 辛弃疾

3、数据删除测试

(1)在SHUAIGE.T1表中删除一条数据
SYS@orcl> delete from shuaige.t1 where id = 1;

1 row deleted.

SYS@orcl> commit;

Commit complete.
(2)检查进程同步状态
GGSCI (ocp19c) 19> stats ef_test1,total

Sending STATS request to EXTRACT EF_TEST1 ...

Start of Statistics at 2022-05-10 15:52:48.

Output to ./dirdat/cs:

Extracting from SHUAIGE.T1 to SHUAIGE.T1:

*** Total statistics since 2022-05-10 11:24:10 ***
Total inserts 1.00
Total updates 1.00
Total befores 1.00
Total deletes 1.00
Total upserts 0.00
Total discards 0.00
Total operations 3.00 End of Statistics. GGSCI (ocp19c) 20> stats rf_test1,total Sending STATS request to REPLICAT RF_TEST1 ... Start of Statistics at 2022-05-10 15:52:56. Replicating from SHUAIGE.T1 to SHUAIGE.T2: *** Total statistics since 2022-05-10 11:24:11 ***
Total inserts 1.00
Total updates 1.00
Total befores 1.00
Total deletes 1.00
Total upserts 0.00
Total discards 0.00
Total operations 3.00 End of Statistics.

可以看到删除的数据已经成功的捕获和应用了

(3)验证数据是否同步
SYS@orcl> select * from shuaige.t1;

no rows selected

SYS@orcl> select * from shuaige.t2;

no rows selected

Oracle19c单实例数据库配置OGG单用户数据同步测试的更多相关文章

  1. 为单实例数据库配置ASM

    环境配置沿用搭建RAC的环境配置 配置ASM可以在数据库软件安装之前进行,也可以在安装完数据库软件配置数据库前进行 [root@rac01 Packages]# cd /etc/yum.repos.d ...

  2. 在 Oracle Linux 6.5 上安装 Oracle 11g 单实例数据库

    Checking the Hardware Requirements 系统必须满足下面最小的硬件要求 Memory Requirements Minimum: 1 GB of RAMRecommend ...

  3. Oracle 单实例数据库安装和real application clusters数据库安装的区别

    在想了解Oracle单实例数据可和RAC数据库前,请确保你已经知道了数据库和实例的关系,如果不了解,请参考Oracle 数据库实例和数据库. 单实例数据库模式 单实例模式下,一个数据库只能通过一个实例 ...

  4. 使用dataguard将单实例数据库转换为rac数据库

    我们常常将oracle rac数据库通过dataguard容灾到一个单实例数据库中.当生产库出现问题后能够将生产库切换到dgserver上.而当生产库rac修复完毕后.我们相同能够通过dg将数据回切到 ...

  5. 【RAC】将RAC备份集恢复为单实例数据库

    [RAC]将RAC备份集恢复为单实例数据库 一.1  BLOG文档结构图 一.2  前言部分 一.2.1  导读 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其它你所不知道的知识, ...

  6. Oracle 10g通过创建物化视图实现不同数据库间表级别的数据同步

    摘自:http://blog.csdn.net/javaee_sunny/article/details/53439980 目录(?)[-] Oracle 10g 物化视图语法如下 实例演示 主要步骤 ...

  7. Mysql单实例数据库安装

    第1章 MySQL数据库安装 在当今的大中型互联网企业里,MySQL数据库服务几乎都是运行在Linux系列操作系统上,当然,你在可以运行在Windows/Unix等商业操作系统上,大中型互联网企业使用 ...

  8. oracle rac切换到单实例DG后OGG的处理

    在RAC切换到单实例DG后,将OGG目录复制过去,在使用alter extract ext_name,begin now的时候报错 2016-04-10 11:27:03 WARNING OGG-01 ...

  9. oracle 单实例DG(配置篇二)

    一,DG搭建实例--主库配置 one : 归档配置 01,查看归档  1 select log_mode,force_logging from v$database; 02,开启归档 关闭数据库重新启 ...

随机推荐

  1. java-idea创建maven管理web项目不能解析EL的解决方法

    默认会原样输出: 这是由于这样子创建的web.xml的版本不够高 2.5之前web.xml文件中的头定义中,el表达式默认是忽略不解析的,故需要显示声明解析el表达式 所以我们要修改版本: 再< ...

  2. @Required 注解 ?

    这个注解表明 bean 的属性必须在配置的时候设置,通过一个 bean 定义的显式的 属性值或通过自动装配,若@Required 注解的 bean 属性未被设置,容器将抛出 BeanInitializ ...

  3. SringBoot之yaml语法

    ------------恢复内容开始------------ SpringBoot之yaml语法 1.配置文件 官方配置文档太多了,根本记不住! 怎么办呐-->了解原理 SpringBoot使用 ...

  4. NE555脉冲模块电路

  5. 复习——高级语法对象原型,es5新增语法

    今天的开始进入了js的高级语法 我马上也要复习完了,之前学到闭包递归,就回去复习去了,复都复习这么久而且,复习的过程真的比学知识的过程难熬的多,只不过终于要复习完了,再来点es6的新语法马上就要步入v ...

  6. canvas写个简单的小游戏

    之前在HTML5 Canvas属性和方法汇总一文中,介绍过Canvas的各种属性以及方法的说明,并列举了自己写的一些Canvas demo,接下来开始写一个简单的小游戏吧,有多简单,这么说吧,代码不到 ...

  7. react、react-router、redux 也许是最佳小实践1

    小前言 这是一个小小的有关react的小例子,希望通过一个小例子,可以让新手更好的了解到react.react-router4.0.redux的集中使用方法. 这是基于create-react-app ...

  8. 【Android开发】通过 style 设置状态栏,导航栏等的颜色

    <style name="test"> <!--状态栏颜色--> <item name="colorPrimaryDark"> ...

  9. 微信小程序如何把接口调用成功的回调函数返回的参数return出去?(promise就可以解决)

    举个栗子//获取应用实例 //const app = getApp() //const util = require('../../utils/util.js') //const sign = uti ...

  10. box-shadow 阴影的高级用法,多个阴影叠加

    box-shadow的这些用法你知道吗? $shadowH: ''; @for $i from 1 through 12 { $shadowH: #{$shadowH}, 0 ($i * 30px) ...