30. Creating a GoldenGate confguration to run a Shell script when an end-of-day processing record is
阿新 • • 發佈:2019-01-30
簡單說明:
OGG提供了EVENTMARKER特性,可以用來建立事件並執行它,本篇博文主要測試該特性
依據《11. Setting up a simple GoldenGate replication confguration between two single node databases》
部署試驗環境模擬本次實驗,將該博文實驗步驟全部執行完畢
環境準備:
1° 源端和目標端均建立標誌狀態的表,該表觸發事件的執行
su - oracle
sqlplus scott/tiger
create table PROCESS_STATUS
(
EVENTNO NUMBER not null,
EVENTTIME DATE,
STATE VARCHAR2(255)
);
alter table PROCESS_STATUS
add constraint PK_PROCESS_STATUS primary key (EVENTNO)
using index;
exit
cd /ggs
./ggsci
DBLOGIN, USERID ggs PASSWORD ggs
ADD TRANDATA scott.*
INFO TRANDATA scott.*
exit
2° 目標端建立時間執行的簡單指令碼:
su - oracle
cat >/ggs/testEvent.sh<<EOF
#!/bin/bash
source ~/.bash_profile
echo "\$(date +%F_%T) testEvent">>/tmp/testEvent.log
# 該指令碼需要在成功執行後返回成功狀態0
exit 0
EOF
chmod +x /ggs/testEvent.sh
實驗步驟:
1° 源端抽取和傳送程序保持配置不變,正常啟動狀態
2° 目標端改寫應用程序並重啟:
su - oracle
cd /ggs/dirprm
cat>RGGTEST1.prm<<EOF
REPLICAT RGGTEST1
USERID ggs, PASSWORD ggs
DISCARDFILE /ggs/dirrpt/RGGTEST1.dsc, append, MEGABYTES 500
ASSUMETARGETDEFS
MAP SCOTT.BONUS, TARGET SCOTT.BONUS;
MAP SCOTT.SALGRADE, TARGET SCOTT.SALGRADE;
MAP SCOTT.DEPT, TARGET SCOTT.DEPT;
MAP SCOTT.EMP, TARGET SCOTT.EMP;
MAP SCOTT.PROCESS_STATUS, TARGET SCOTT.PROCESS_STATUS, &
FILTER (@STREQ(STATE, "EOF COMPLETE")=1), EVENTACTIONS (SHELL "/ggs/testEvent.sh");
EOF
cd /ggs
echo 'STOP REPLICAT RGGTEST1'|./ggsci
echo 'START REPLICAT RGGTEST1'|./ggsci
echo 'STATUS REPLICAT RGGTEST1'|./ggsci
3° 測試驗證:
# 源端操作
su - oracle
sqlplus scott/tiger
INSERT INTO PROCESS_STATUS VALUES (1, SYSDATE, 'EOF COMPLETE');
commit;
exit
# 目標端驗證
sqlplus scott/tiger
select * from PROCESS_STATUS;
exit
cat /tmp/testEvent.log
# 表資料複製,觸發EVENT,測試成功
[TOC]