本篇內(nèi)容介紹了“OGG怎么實現(xiàn)兩臺Oracle數(shù)據(jù)庫的同步”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細閱讀,能夠?qū)W有所成!
站在用戶的角度思考問題,與客戶深入溝通,找到海晏網(wǎng)站設(shè)計與海晏網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:成都網(wǎng)站制作、做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、國際域名空間、虛擬空間、企業(yè)郵箱。業(yè)務(wù)覆蓋海晏地區(qū)。
首先我們看看實驗環(huán)境
環(huán)境
源端是一個單實例
Oracle CENTOS 6+ ORACLE 10.2.0.4
IP :192.168.56.101
目標端是一個單實例
Oracle CENTOS 6+ ORACLE 10.2.0.4
IP :192.168.56.102
兩臺主機均已創(chuàng)建數(shù)據(jù)庫,sid分別為devdb 和 emrep
配置devdb 到 emrep的數(shù)據(jù)同步
goldengate版本11.2.1.0
1.配置數(shù)據(jù)庫信息
在源端數(shù)據(jù)庫中打開歸檔模式
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/archive1
Oldest online log sequence 180
Next log sequence to archive 181
Current log sequence 181
若處于非歸檔模式,則改為歸檔模式:
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
SQL> alter database archivelog;
Database altered.
SQL> alter database open;
Database altered.
在源端數(shù)據(jù)庫中打開force logging
SQL> select force_logging from v$database;
FOR
---
NO
SQL> alter database force logging;
Database altered.
SQL> select force_logging from v$database;
FOR
---
YES
在源端數(shù)據(jù)庫中打開supplemental log
SQL> select supplemental_log_data_min from v$database;
SUPPLEME
--------
NO
SQL> alter database add supplemental log data;
Database altered.
切換日志,使更改生效
SQL> alter system switch logfile;
System altered.
SQL> select supplemental_log_data_min from v$database;
SUPPLEME
--------
YES
在源端數(shù)據(jù)庫中關(guān)閉回收站
官方的說明是,由于一個已知的問題,回收站會對DDL觸發(fā)器產(chǎn)生影響,因此需要關(guān)閉。由此可見,我們只需要在源庫中關(guān)閉回收站即可。
SQL> show parameter recyclebin
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
recyclebin string on
SQL> alter system set recyclebin=off;
System altered.
SQL> show parameter recyclebin
NAME TYPE VALUE
------------------------------------ -------------------------------
recyclebin string OFF
創(chuàng)建goldengate數(shù)據(jù)庫用戶(源和目標)
注意:源和目標端都需要
[oracle@rac1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.4.0 - Production on Fri Jan 9 11:56:28 2015
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 32bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> create tablespace goldengate;
Tablespace created.
SQL> create user goldengate identified by goldengate default tablespace goldengate;
User created.
SQL> grant connect,resource to goldengate;
Grant succeeded.
SQL> grant execute on utl_file to goldengate;
Grant succeeded.
SQL>
抽取進程使用的數(shù)據(jù)庫用戶需要額外的權(quán)限,我們將這些權(quán)限也授予數(shù)據(jù)庫用戶goldengate(在源端數(shù)據(jù)庫中執(zhí)行)
SQL> exec dbms_streams_auth.grant_admin_privilege('GOLDENGATE');
PL/SQL procedure successfully completed.
SQL> grant insert on system.logmnr_restart_ckpt$ to goldengate;
Grant succeeded.
SQL> grant update on sys.streams$_capture_process to goldengate;
Grant succeeded.
SQL> grant become user to goldengate;
Grant succeeded.
SQL>
為了確保GoldenGate正常運行,特別是在目標端,賦予goldengate用戶DBA權(quán)限:
SQL> grant dba to goldengate;
2.GoldenGate安裝環(huán)境
解壓goldengate安裝文件到安裝目錄
安裝GoldenGate軟件很簡單,解壓即可
以goldengate用戶登錄
[goldengate@rac1 goldengateMedia]$ mkdir /opt/gg/goldengate、
[goldengate@rac1 goldengateMedia]$ cp ggs_Linux_ora10g_.tar /opt/gg/goldengate
[goldengate@rac1 goldengateMedia]$ cd /opt/gg/goldengate
[goldengate@rac1 goldengate]$ tar -xvf ggs_Linux_ora10g.tar
配置環(huán)境變量
源端和目標端:
修改goldengate用戶的環(huán)境變量配置文件(ORACLE_SID按實際情況修改)
cat>>/home/goldengate/.bashrc<
export ORACLE_HOME
ORACLE_SID=devdb
export ORACLE_SID
GG_HOME=/opt/gg/goldengate
export GG_HOME
PATH=\$ORACLE_HOME/bin:$GG_HOME:\$PATH
export PATH
LD_LIBRARY_PATH=\$ORACLE_HOME/lib:\$GG_HOME:\$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
EOF
應(yīng)用剛剛修改的環(huán)境變量,然后進入GoldenGate安裝目錄,執(zhí)行l(wèi)dd ggsci,確定需要的庫文件都能夠找到。如果出現(xiàn)共享庫文件無法找到,例如libnnz10.so => not found,檢查LD_LIBRARY_PATH環(huán)境變量的設(shè)置
[goldengate@ggdb goldengate]$ source ~/.bashrc
[goldengate@ggdb goldengate]$ cd $GG_HOME
[goldengate@ggdb goldengate]$ ldd ggsci
我們可以認為ogg的安裝其實就是一個解壓。非常簡單。
創(chuàng)建goldengate工作目錄
源端和目標端:
[goldengate@rac1 goldengate]$ cd $GG_HOME
[goldengate@rac1 goldengate]$ ./ggsci
GGSCI (rac1) 1> create subdirs
Creating subdirectories under current directory /opt/gg/goldengate
Parameter files /opt/gg/goldengate/dirprm: created
Report files /opt/gg/goldengate/dirrpt: created
Checkpoint files /opt/gg/goldengate/dirchk: created
……
GGSCI (gg1) 2> exit
源和目標端:
[goldengate@rac1 ~]$ mkdir /opt/gg/trails
[goldengate@rac1 ~]$ ls -l /opt/gg | grep trails
源端和目標端:
DYNAMICPORTLIST中配置了GoldenGate(extract和replicat)進程使用的端口范圍
PORT參數(shù)指定MANAGER使用的端口
AUTORESTART參數(shù)使抽取/復(fù)制進程失敗后自動重啟
配置MANAGER的參數(shù),PURGEOLDEXTRACTS參數(shù)指定:當(dāng)根據(jù)checkpoint發(fā)現(xiàn)已經(jīng)完成抽取和復(fù)制的trail文件將被自動刪除,但保留最近10個。
PURGEDDLHISTORY和PURGEMARKERHISTORY分別刪除DDL歷史表和marker表中的過期數(shù)據(jù),以控制它們不會變得過于龐大。
GGSCI (gg1) 1> edit params mgr
PORT 5898
PURGEOLDEXTRACTS /opt/gg/trails/w1*, USECHECKPOINTS, MINKEEPFILES 10
AUTORESTART ER *, RETRIES 3, WAITMINUTES 5
PURGEDDLHISTORY MINKEEPDAYS 3, MAXKEEPDAYS 5, FREQUENCYMINUTES 30
PURGEMARKERHISTORY MINKEEPDAYS 3, MAXKEEPDAYS 5, FREQUENCYMINUTES 30
源端:
GGSCI (rac1) 2> edit params ./globals
GGSCHEMA goldengate
目標端:
創(chuàng)建一個checkpoint表
replicat通過這個表來維護trail文件中的read position。這不是個必須的操作,如果沒有這個表,則通過一個磁盤文件來維護
GGSCI (ggdb) 2> dblogin userid goldengate,password goldengate
Successfully logged into database.
GGSCI (ggdb) 3> add checkpointtable goldengate.chkpoint
Successfully created checkpoint table GOLDENGATE.CHKPOINT.
GGSCI (ggdb) 4> edit params ./globals
“OGG怎么實現(xiàn)兩臺Oracle數(shù)據(jù)庫的同步”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!