张小白教你使用OGG实现Oracle 19C到MySQL 5.7的数据同步(3)
(四)源端OGG配置
编辑~/.bashrc
增加以下内容:
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/19c/db_1
export ORACLE_SID=zhanghui
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export OGG_HOME=/opt/ogg/source_endpoint
export PATH=$OGG_HOME:$PATH:$ORACLE_HOME/bin
export TNS_ADMIN=$ORACLE_HOME/network/admin
source ~/.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/ogg@ORCLPDB
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 ogg@ORCLPDB 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 extorcl
DDL INCLUDE ALL
SETENV (ORACLE_HOME = "/u01/app/oracle/product/19c/db_1")
SETENV (ORACLE_SID="zhanghui")
SETENV (NLS_LANG="american_america.AL32UTF8")
userid c##ogg@zhanghui , password ogg
exttrail /opt/ogg/source_endpoint/dirdat/to
table 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 ogg@ORCLPDB, password ogg
register extract extorcl database container(ORCLPDB)
很奇怪,它不能在PDB里面注册,那我们切换都CDB环境试试:
dblogin userid c##ogg@zhanghui, password ogg
register extract extorcl database container(ORCLPDB)
(5)OGG源端传输进程pumysql配置(实现将抽取的数据文件发送到OGG目的端)
edit param pumysql
加入以下内容:
extract pumysql
userid c##ogg@zhanghui , password ogg
rmthost 127.0.0.1,mgrport 7810
rmttrail /opt/ogg/target_endpoint/dirdat/rt
table 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_test
userid test_ogg@ORCLPDB, password ogg
table 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的日志。
(未完待续)
- 点赞
- 收藏
- 关注作者
评论(0)