OGG简单配置
Posted ritchy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OGG简单配置相关的知识,希望对你有一定的参考价值。
针对部分表进行OGG同步的话,可以参考下面的步骤进行操作,正常情况下按顺序执行就差不多了
【数据库准备】
首先,开启归档、全局附加日志和FORCELOGGING
SHUTDOWN IMMEDIATE;
STARTUP MOUNT;
ALTER DATABASE ARCHIVELOG;
ALTER DATABASE OPEN;
--查询结果要是YES,不是的话执行ALTER
SELECT SUPPLEMENTAL_LOG_DATA_MIN,FORCE_LOGGING FROM V$DATABASE;
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
ALTER DATABASE FORCE LOGGING;
下面是源库和目标库都需要做
1、创建ogguser用户
create user ogguser identified by ogguser;
grant connect to ogguser;
grant resource to ogguser;
grant unlimited tablespaces to ogguser;
grant execute on tul_file to ogguser;
grant select any dictionary to ogguser;
grant select any table to ogguser;
grant alter any table to ogguser;
grant flashback any table to ogguser;
grant execute on dbms_flashback to ogguser;
2、解压安装goldengate并创建目录 ./ggsci、create subdirs
[[email protected] goldengate]$ ./ggsci
GGSCI (rac1) 2> create subdirs
3、创建CKPT表
edit param ./GLOBALS
ggschema ogguser
checkpointtable ogguser.checkpoint
GGSCI (DBDATA) 9> dblogin userid ogguser password ogguser
Successfully logged into database.
GGSCI (DBDATA as [email protected]) 10> add checkpointtable ogguser.checkpoint
Successfully created checkpoint table ogguser.checkpoint.
--如果出现已存在或有问题,通过sqlplus来drop,再重新执行上面的
sqlplus ogguser/ogguser
drop table checkpoint;
drop table checkpoint_lox;
4、创建并启动MGR进程
edit param mgr
PORT 7839
DYNAMICPORTLIST 7840-7914
AUTOSTART EXTRACT *
AUTORESTART EXTRACT *, RETRIES 3, WAITMINUTES 3
PURGEOLDEXTRACTS ./dirdat/*, USECHECKPOINTS, MINKEEPDAYS 5
LAGREPORTHOURS 1
LAGINFOMINUTES 30
LAGCRITICALMINUTES 45
GGSCI (rac1 as [email protected]) 15> start mgr
Manager started.
【源库】
0识别需要同步的表并添加附加日志:
ALTER TABLE TEST.T_TEST ADD SUPPLEMENTAL LOG DATA (ALL) COLUMNS;
ALTER TABLE TEST.AA ADD SUPPLEMENTAL LOG DATA (ALL) COLUMNS;
ALTER TABLE TEST.BB ADD SUPPLEMENTAL LOG DATA (ALL) COLUMNS;
1、抽取进程
ADD EXT ext1, TRANLOG, THREADS 1, BEGIN now
add exttrail ./dirdat/r1, extract ext1,megabytes 1000
edit param ext1
EXTRACT ext1
setenv (NLS_LANG=AMERICAN_AMERICA.ZHS16GBK)
setenv (ORACLE_SID=rac1)
USERID ogguser, PASSWORD ogguser
--REPORTCOUNT EVERY 1 MINUTES, RATE
--NUMFILES 5000
discardfile ./dirrpt/ext.dsc,append, megabytes 100
DISCARDROLLOVER AT 3:00
EXTTRAIL ./dirdat/r1,megabytes 100
DYNAMICRESOLUTION
TRANLOGOPTIONS CONVERTUCS2CLOBS
TRANLOGOPTIONS DBLOGREADER
FETCHOPTIONS NOUSESNAPSHOT
FETCHOPTIONS FETCHPKUPDATECOLS
STATOPTIONS REPORTFETCH
WARNLONGTRANS 5h,CHECKINTERVAL 30m
----TABLES------
table TEST.T_TEST;
table TEST.aa;
table TEST.bb;
start ext1
--数据库环境变量字符集的查询,要与下面的对应
SQL> select * from nls_database_parameters;
PARAMETER VALUE
------------------------------ --------------------------------------------------
--NLS_LANGUAGE AMERICAN
--NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
--NLS_CHARACTERSET ZHS16GBK
2、传输进程
add extract pxt1,exttrailsource ./dirdat/r1
add rmttrail ./dirdat/p1, extract pxt1,megabytes 1000
--其中 192.168.5.233 对应的是目标端的主机IP
edit param pxt1
EXTRACT pxt1
DYNAMICRESOLUTION
PASSTHRU
RMTHOST 192.168.5.233, MGRPORT 7839, COMPRESS
RMTTRAIL ./dirdat/p1
NUMFILES 500
---tables
TABLE TEST.T_TEST;
TABLE TEST.AA;
TABLE TEST.BB;
start pxt1
3、注意事项:
1、启动这个之前要启动目标机的MGR进程
2、检查源、目标库抓取和获取数据是否正常 ll dirdat
验证源端抓取是否正常,已产生r1000000 文件
[[email protected] goldengate]$ ll dirdat
16
-rw-r----- 1 oracle oinstall 1370 10-17 18:33 r1000000
验证目标端获取数据是否正常,已产生 p1000000 文件
[[email protected] goldengate]$ ll dirdat
total 12
-rw-r----- 1 oracle oinstall 0 Oct 17 18:46 p1000000
【目标库数据初始化】
1、源库获取SCN
需要用到源库SCN
col current_scn format 999999999999999
Select current_scn from v$database;
2、源+目标库
create or replace directory dump_dir as ‘/home/oracle/dump_dir‘;
grant read,write on directory dump_dir to ogguser;
3、EXPDP/IMPDP
源库
expdp TEST/TEST directory=dump_dir tables=T_TEST,aa,bb dumpfile=expdp_TEST_2tabs.dmp logfile=expdp_TEST_2tabs.log FLASHBACK_SCN=8689213127
--传输文件到目标库,然后就恢复
scp /mnt/dump_dir/expdp_TEST_2tabs* 192.168.5.233:/home/oracle/dump_dir
目标库
impdp ogguser/ogguser directory=dump_dir remap_schema=TEST:ogguser dumpfile=expdp_TEST_bb.dmp logfile=expdp_TEST_bb_imp.log
【目标库】
复制进程
用到的文件/目录是源端传输进程的p1,对应关系要一一对应
add replicat rxt1, exttrail ./dirdat/p1,
edit param rxt1
replicat rxt1
handlecollisions
ASSUMETARGETDEFS
--setenv (ORACLE_SID=TEST233)
setenv (NLS_LANG=AMERICAN_AMERICA.ZHS16GBK)
userid ogguser,password ogguser
DBOPTIONS NOSUPPRESSTRIGGERS
REPORTCOUNT EVERY 1 MINUTES, RATE
--REPERROR DEFAULT, ABEND
NUMFILES 500
discardfile ./dirrpt/rxt.dsc, append, megabytes 100
ALLOWNOOPUPDATES
----TABLES-----
map TEST.T_TEST, target ogguser.T_TEST;
map TEST.aa, target ogguser.aa;
map TEST.bb, target ogguser.bb;
start rxt1
注意事项
NOSUPPRESSTRIGGERS 目标端需要用到触发器时,要加这个参数,否则触发器不能用。
【(带触发器的表)同步测试】
--源表与目标表(结构一样,初始从源库impdp过来),必须有主键,主键必是触发器中的条件
create table BB
(
bb VARCHAR2(30) not null,
sdate DATE not null
);
alter table BB add constraint PK_B primary key (BB);
--中间表,可不要主键
create table BB_CHANGES
(
bb VARCHAR2(30),
timestamp TIMESTAMP(6),
status NUMBER default 0
);
--触发器,源表主键必是其中的一个条件
CREATE OR REPLACE TRIGGER TR_BB_CHANGES
AFTER INSERT OR UPDATE ON BB
FOR EACH ROW
DECLARE
CNT NUMBER;
BEGIN
SELECT COUNT(1)
INTO CNT
FROM BB_CHANGES S
WHERE :NEW.BB = S.BB
AND S.STATUS = 0;
IF CNT = 0 THEN
INSERT INTO BB_CHANGES
(BB, TIMESTAMP)
VALUES
(:NEW.BB, CURRENT_TIMESTAMP);
END IF;
END;
在源库执行
INSERT INTO BB (BB, SDATE) VALUES (‘1‘, SYSDATE);
COMMIT;
INSERT INTO BB (BB, SDATE) VALUES (‘2‘, SYSDATE);
COMMIT;
INSERT INTO BB (BB, SDATE) VALUES (‘3‘, SYSDATE);
COMMIT;
UPDATE BB SET BB=‘11‘ WHERE BB=‘1‘;
COMMIT;
--在目标库可以看到BB表中已同步存在上面的数据,且BB_CHANGES中会增加相应的DML记录
SELECT * FROM OGGUSER.BB ORDER BY SDATE DESC ;
SELECT * FROM OGGUSER.BB_CHANGES;
以上是关于OGG简单配置的主要内容,如果未能解决你的问题,请参考以下文章