OGG配置單向複製

源操作系統和目標操作系統:


數據庫版本


OGG版本



第一步,配置源端,目標端操作系統環境變量,建立OGG用戶


源端
create tablespace ogg_t datafile '/u01/app/oracle/oradata/PROD1/ogg_t01.dbf' size 50m autoextend on;
create user ogg identified by oracle default tablespace ogg_t temporary tablespace temp;
grant connect to ogg;
grant alter any table to ogg;
grant alter session to ogg;
grant create session to ogg;
grant flashback any table to ogg;
grant select any dictionary to ogg;
grant select any table to ogg;
grant resource to ogg;
grant select any transaction to ogg;


打開附加日誌,強制數據庫寫日誌,當然歸檔也打開。(歸檔在mount狀態下開)

alter database add supplemental log data;
alter database force logging;

alter database archivelog;

第二步 進入OGG

解壓OGG安裝包,進入OGG安裝文件


運行ggsci


第三步,配置源端OGG配置信息

執行create subdirs 創建相關OGG程序


編輯MGR源端管理進程配置信息

edit params mgr

--編輯內容如下- edit params mgr------------
port 7839 
DYNAMICPORTLIST 7840-7850
AUTOSTART EXTRACT *
AUTORESTART EXTRACT *
PURGEOLDEXTRACTS ./dirdat/*,usecheckpoints, minkeepdays 7
LAGREPORTHOURS 1
LAGINFOMINUTES 30

LAGCRITICALMINUTES 45

查看保存後的內容


-------------------

啓動MGR管理進程  

 start mgr

輸入info all 命令可以看到關於進程狀態相關信息



源端:
配置scott下面表的表級附加日誌。配置登陸用戶。並檢查日誌是否添加成功。
以ogg這個schema登陸數據庫。
dblogin userid ogg, password oracle

添加表級附加日誌
add trandata scott.*

配置源端的抓取進程


add extract ext_demo, tranlog, begin now, threads 1
-------------------------------------------------------------------------------------------
參數分析:
tranlog:表示數據抓取的來源是數據庫的redo數據。
begin now:表示我們在啓動這個抓取進程的就去抓取數據。
threads 1:表示我們數據庫有多少個redo threads,單實例基本上是1或者不設,rac就自己設置了,
配置過RAC的基本都瞭解。
-------------------------------------------------------------------------------------------


添加源端的隊列文件。
add EXTTRAIL ./dirdat/r1, extract ext_demo,megabytes 100
-------------------------------------------------------------------------------------------
分析:
./dirdat:表示trail文件的目錄
r1:trail文件的前綴
extract ext_demo:值指定給那個進程用的(ext_demo)。
megabytes 100:文件大小是100m
-------------------------------------------------------------------------------------------


編輯我們剛剛在源端配置的抓取進程的參數:
edit param ext_demo
-------------------------------------------------------------------------------------------
EXTRACT ext_demo
setenv (ORACLE_SID=PROD1)
setenv (NLS_LANG=AMERICAN_AMERICA.ZHS16GBK)
userid ogg,password oracle
REPORTCOUNT EVERY 1 MINUTES, RATE
numfiles 5000
DISCARDFILE ./dirrpt/ext_demo.dsc,APPEND,MEGABYTES 1000
DISCARDROLLOVER AT 3:00
exttrail ./dirdat/r1,megabytes 100
dynamicresolution
TRANLOGOPTIONS EXCLUDEUSER ogg
TRANLOGOPTIONS convertucs2clobs
TABLE scott.*;
-------------------------------------------------------------------------------------------
分析:
setenv (ORACLE_SID=ogg):指定oracle的sid,單機環境下可以不設或者bashprofile文件中設置了默認的
也可以不設,但是集羣環境就要指定了,這裏我們強烈建議指定。
setenv (NLS_LANG=AMERICAN_AMERICA.ZHS16GBK):源端數據庫的字符集,一定要跟數據庫中匹配。
userid goldengate,password goldengate:告訴抓取進程是通過這個用戶登陸數據庫的。
exttrail ./dirdat/r1,megabytes 100:與我們上面配置抓取進程的設置要一致,路徑和大小嘛。
TABLE HR.*:最重要的,告訴抓取進程抓取的是哪些用戶哪些表的數據。

-------------------------------------------------------------------------------------------

查看配置的進程信息


啓動抓取進程:
start ext_demo

-------------------------------------------------------------------------------------------


配置datapump進程,將抓取數據傳到目標主機。負責TCPIP通訊。
add extract dpe_demo, exttrailsource ./dirdat/r1

輸出:目標主機怎麼寫,也是定義datapumo進程的輸出。
add rmttrail ./dirdat/t1,EXTRACT dpe_demo,MEGABYTES 100

分析:
exttrailsource:抓取進程的來源,因爲這個進程不否則到數據庫中取抓取,所以抓取的來源

是通過抓取進程已經生成好的trail文件中的內容。

配置datapump進程參數:
edit param dpe_demo
-------------------------------------------------------------------------------------------
extract dpe_demo
dynamicresolution
passthru
rmthost 192.168.56.82, mgrport 7839, compress
rmttrail ./dirdat/t1
numfiles 5000
TABLE scott.*;
-------------------------------------------------------------------------------------------
分析:
passthru:上面已經說過不需要連接數據庫,所以用這個指令。
rmthost:目標主機的IP地址,就是說我們的rmttrail進程發送到的主機。
mgrport:目標主機管理進程的端口號,我們上面已經配置了。
compress:在傳輸的過程中啓用壓縮。
rmttrail:路徑和文件與上面配置的一致。
TABLE scott.*:上面說過,哪些表的redo信息傳輸。

-------------------------------------------------------------------------------------------

查看配置的進程


查看源端所有進程狀態


第四步,配置目標端OGG配置信息

目標端用戶添加
create tablespace ogg_t datafile '/u01/app/oracle/oradata/PROD1/ogg_t01.dbf' size 50m autoextend on;
create user ogg identified by oracle default tablespace ogg_t temporary tablespace temp;
grant connect to ogg;
grant alter any table to ogg;
grant alter session to ogg;
grant create session to ogg;
grant flashback any table to ogg;
grant select any dictionary to ogg;
grant select any table to ogg;
grant resource to ogg;
grant select any transaction to ogg;

grant insert any table to ogg;
grant update any table to ogg;
grant delete any table to ogg;
grant create any index to ogg;
grant select any transaction to ogg;
-------------------------------------------------------------------------------------------


登陸目標端OGG:
爲replicat進程創建checkpoint表:
dblogin userid ogg,password oracle

add checkpointtable ogg.rep_demo_ckpt

-------------------------------------------------------------------------------------------
配置目標端replicate進程:
add replicat rep_demo,exttrail ./dirdat/t1,checkpointtable ogg.rep_demo_ckpt
分析:
exttrail:表示這個進程獲取數據的來源是什麼地方,是我們源端rmttrail所設置過的。

-------------------------------------------------------------------------------------------
配置目標端replicate參數:
edit param rep_demo
-------------------------------------------------------------------------------------------
REPLICAT rep_demo
SETENV (ORACLE_SID=DG)
SETENV (NLS_LANG = "AMERICAN_AMERICA.ZHS16GBK")
USERID ogg,PASSWORD oracle
REPORTCOUNT EVERY 30 MINUTES, RATE
REPERROR DEFAULT, ABEND
numfiles 5000
--HANDLECOLLISIONS
assumetargetdefs
DISCARDFILE ./dirrpt/rep_demo.dsc, APPEND, MEGABYTES 1000
ALLOWNOOPUPDATES
MAP scott.*, TARGET scott.*;

-------------------------------------------------------------------------------------------
分析:
重要的地方與上面基本一致,有興趣可以查查其他參數的信息。
MAP:源端和目標端的對應。
-------------------------------------------------------------------------------------------

目標端:
啓動並查看replicate進程是否運行:
start rep_demo

查看目標端所有進程狀態


第五步驗證是否成功

在源端scott用戶下,對dept表插入一條數據



在目標端查詢dept表發現也有條數據



搭建成功。





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章