当前位置:网站首页>张小白教你使用OGG实现Oracle 19C到MySQL 5.7的数据同步(3)
张小白教你使用OGG实现Oracle 19C到MySQL 5.7的数据同步(3)
2022-06-10 09:39:00 【华为云】

(四)源端OGG配置
编辑~/.bashrc
增加以下内容:
export ORACLE_BASE=/u01/app/oracleexport ORACLE_HOME=$ORACLE_BASE/product/19c/db_1export ORACLE_SID=zhanghuiexport PATH=$ORACLE_HOME/bin:$PATHexport LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATHexport OGG_HOME=/opt/ogg/source_endpointexport PATH=$OGG_HOME:$PATH:$ORACLE_HOME/binexport TNS_ADMIN=$ORACLE_HOME/network/adminsource ~/.bashrc使其生效:

建立软连接:
ln -s $ORACLE_HOME/lib/libnnz19.so /opt/ogg/source_endpoint/libnnz19.so
cd $OGG_HOME
ldd ggsci

(1)OGG源端相关的Oracle配置(创建c##ogg用户、建立测试表test_ogg等等)
切换到oracle用户
su - oracle
mkdir /home/oracle/archivelog
查看目前是否打开了归档日志:
sqlplus '/as sysdba'
archive log list

没打开。
那么就打开它。注意如果打开了归档日志,那么所有的DML操作都会记录到归档日志中,这个文件可能会非常大,直到让文件系统爆满,这会直接导致oracle无法提供服务。所以要务必小心跟踪归档日志所属文件系统的剩余空间情况。
alter system set log_archive_dest_1='location=/home/oracle/archivelog';
shutdown immediate;
startup mount;
alter database archivelog;
alter database open;
alter system archive log start;
alter system archive log current;
alter database force logging;
alter database add supplemental log data;

alter system set enable_goldengate_replication=true;
select name,open_mode,force_logging,supplemental_log_data_min from v$database;
archive log list

创建c##ogg所需要的表空间:
create tablespace oggtbs datafile '/home/oracle/oradata/OGG/tablespace/oggtbs01.dbf' size 1000M autoextend on;
并在上面创建c##ogg用户:
create user c##ogg identified by ogg default tablespace oggtbs;
赋予权限:
grant dba ,connect, resource, unlimited tablespace to c##ogg;
exec dbms_goldengate_auth.grant_admin_privilege('c##ogg','*',TRUE);
select username,common,con_id from cdb_users where username like '%OGG%';
commit;
查看pdb状态:show pdbs
如果发现pdb是MOUNTED状态,可以执行:
alter session set container=ORCLPDB;
alter pluggable database open;
将其改为READ/WRITE状态:

alter session set container=ORCLPDB;
show con_name;

确认现在是在ORCLPDB库中,
给c##ogg用户赋权限:
grant dba ,connect, resource, unlimited tablespace to c##ogg;

编辑$TNS_ADMIN下的 tnsnames.ora文件:
LISTENER_ZHANGHUI = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))ZHANGHUI = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = zhanghui) ) )ORCLPDB = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ORCLPDB ) ) )增加ORCLPDB这个PDB数据库的配置。
创建ogg所需要的表空间:
create tablespace mytbs datafile '/home/oracle/oradata/OGG/tablespace/mytbs01.dbf' size 500M autoextend on;
并在上面创建ogg用户:
create user ogg identified by ogg default tablespace mytbs;
赋予权限:
grant dba ,connect, resource, unlimited tablespace to ogg;


exec dbms_goldengate_auth.grant_admin_privilege('ogg','*',TRUE);
select username,common,con_id from cdb_users where username like '%OGG%';
commit;

验证ogg可以正常登录ORCLPDB数据库:

切换到ogg用户:
cd $OGG_HOME
ggsci
create subdirs

切换到oracle用户,创建一个test_ogg用户:
create user test_ogg identified by ogg ;
grant dba ,connect, resource, unlimited tablespace to test_ogg;(实际上用户的权限不必这么大)
quit
切换到test_ogg用户登录ORCLPDB
sqlplus test_ogg/[email protected]
create table test_ogg(id int,name varchar(20),primary key(id));
(2)OGG源端表级补全日志trandata配置
切换到ogg用户:
cd $OGG_HOME
ggsci
edit param ./globals

填入以下内容:
oggschema ogg
dblogin userid [email protected] password ogg

add schematrandata ORCLPDB.test_ogg

add trandata test_ogg.*

capture tabledef test_ogg.*

(3)OGG源端管理进程MGR配置(侦听本地端口7809)
edit param mgr
编辑以下内容:
PORT 7809保存退出

(4)OGG源端抽取进程extorcl配置(实现从Oracle数据库表抽取数据到数据文件)
edit param extorcl
extract extorclDDL INCLUDE ALLSETENV (ORACLE_HOME = "/u01/app/oracle/product/19c/db_1")SETENV (ORACLE_SID="zhanghui")SETENV (NLS_LANG="american_america.AL32UTF8")userid c##[email protected] , password oggexttrail /opt/ogg/source_endpoint/dirdat/totable ORCLPDB.test_ogg.*;注意:
1.如果使用ORCLPDB中的ogg用户,在启动extorcl的时候就会报以下错误:

所以必须配置使用c##ogg用户登录才行。
2.如果table忘记带了数据库名,写成这样:table test_ogg.*;,启动extorcl的时候就会报以下错误:

delete extract extorcl
add extract extorcl,INTEGRATED TRANLOG,BEGIN NOW
add exttrail /opt/ogg/source_endpoint/dirdat/to, extract extorcl
dblogin userid [email protected], password ogg

register extract extorcl database container(ORCLPDB)

很奇怪,它不能在PDB里面注册,那我们切换都CDB环境试试:
dblogin userid c##[email protected], password ogg
register extract extorcl database container(ORCLPDB)

(5)OGG源端传输进程pumysql配置(实现将抽取的数据文件发送到OGG目的端)
edit param pumysql
加入以下内容:
extract pumysqluserid c##[email protected] , password oggrmthost 127.0.0.1,mgrport 7810rmttrail /opt/ogg/target_endpoint/dirdat/rttable ORCLPDB.test_ogg.*;注意:如果使用ORCLPDB中的ogg用户,在启动pumysql的时候就会报以下错误:

所以必须配置使用c##ogg用户登录才行。
delete extract pumysql
add extract pumysql, exttrailsource /opt/ogg/source_endpoint/dirdat/to
add rmttrail /opt/ogg/target_endpoint/dirdat/rt, extract pumysql, megabytes 100
info all

start mgr

start extorcl

start pumysql

(6)OGG源端异构mapping文件defgen生成
edit param tab1
dsdffile /opt/ogg/source_endpoint/dirdef/ogg_test.ogg_testuserid [email protected], password oggtable test_ogg.test_ogg;quit
./defgen paramfile dirprm/tab1.prm

info all

插入一条test_ogg表的记录:
insert into test_ogg values(1,'Hello World');
commit;

在ggsci中查看extorcl的日志:
view report extorcl

在Run Time Messages后面就是从oracle抽取记录的日志。
在ggsci中查看pumysql的日志:

在Run Time Messages后面就是将上面抽取的表记录发送到mysql服务端MGR的日志。
(未完待续)
边栏推荐
- P1387 maximum square (DP)
- Talk about the trend of digital transformation in 2022
- 提升.NET技术水平,我是怎么做的
- 四种最简单的防反接电路
- 618 is coming. Is it too time-consuming to generate a large number of coupons? Threadpooltaskexecutor thread pool helps you
- Product recommendation system based on deep learning (WEB)
- 【图像去噪】基于matlab BdCNN图像去噪【含Matlab源码 1866期】
- CF1304C Air Conditioner(思维)
- PostgreSQL cost model
- #795 D Max GEQ Sum(单调栈+RMQ)
猜你喜欢

Local browser access remote server jupyter configuration

隐私计算重要技术突破!亿级数据密态分析可在10分钟内完成

Concurrency - create thread

mmclassification

Monthly 50 f cocktails (thinking)
![[Timm] an image model library based on pytorch](/img/b6/2fc7744a31fae1250f03b5d2fc8225.png)
[Timm] an image model library based on pytorch

Pointnet: deep learning on point sets for 3D classi "location and segmentation

Enlightenment from Alibaba's digital transformation

On the night of the joint commissioning, I beat up my colleagues

HMM details + examples
随机推荐
GNSS positioning data collection
How about the course system of PHP
Xiaobai yuesai 49 e Zen (DP)
[fishing artifact] UI library second to second lowcode tool - list part (II) small tool for maintaining JSON
1143. longest common subsequence
powerdesigner物理数据模型导出的SQL文件,执行时报错?
Want to be iron man? It is said that many big men use it to get started
01 backpack problem
基于STM32设计智能家居控制系统(OneNet)_2022
Kotlin 1.7.0 已发布,推出新的 Kotlin К2 编译器
【边缘检测】基于matlab八方向sobel图像边缘检测【含Matlab源码 1865期】
【图像去噪】基于matlab BdCNN图像去噪【含Matlab源码 1866期】
618来袭,大量优惠券生成太耗时?ThreadPoolTaskExecutor线程池帮你来搞定
MySQL数据库(26):视图 view
天才啊!仅用四个整数编写一个贪吃蛇游戏!
jqGrid表格部分处理方法:
Partial processing method of jqgrid table:
Talk about the trend of digital transformation in 2022
What should we pay attention to when developing, designing and building the reward task source code
微软再曝“丑闻”:在办公室看 VR 黄片,“HoloLens 之父”即将离职!