Oracle GoldenGate軟件基于數據庫日志結構變化,通過解析源端在線日志或歸檔日志獲得數據增量,再將這些變化應用到目標數據庫,從而實現源庫和目標庫的數據同步。下面通過一個簡單的示例,詳細介紹利用GoldenGate實現Oracle數據庫之間的同步。基本架構如下圖所示:
1. 安裝
1.1 下載介質
GoldenGate的安裝介質可以從Oracle的官網上下載。
http://www.oracle.com/technetwork/middleware/goldengate/overview/index.html
1.2 配置GoldenGate用戶
下載完成后將其拷貝到源和目標的相應位置解壓完成后,即可以開始進行配置。
# useradd -g oinstall -G dba ggate
# su – ggate
$ mkdir /u01/app/oracle/ggate
$ cd /u01/app/oracle/ggate
$ tar ……
注意,如果使用Oracle 11g的數據庫,需要創建一個link文件。
$ ln -s /u01/app/oracle/product/11.2.0/db_1/lib/libnnz11.so -
/u01/app/oracle/product/11.2.0/db_1/lib/libnnz10.so$ vi ~/.bash_profile
添加如下的內容:
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/u01/app/oracle/ggate
export GGATE=/u01/app/oracle/ggate
1.3 創建目錄
使用ggsci工具,創建必要的目錄。
$ cd /u01/app/oracle/ggate
$ ./ggsciOracle GoldenGate Command Interpreter for Oracle
Version 11.1.1.0.0 Build 078
Linux, x86, 32bit (optimized), Oracle 10 on Jul 28 2010 13:24:18Copyright (C) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
GGSCI (gridcontrol) 1> create subdirs
至此,GoldenGate基本的安裝完成。
Note. 此部分需要在源端和目標端完成。
2. 源數據庫配置
GoldenGate主要通過抓取源端數據庫重做日志進行分析,將獲取的數據應用到目標端,實現數據同步。因此,為了讓GoldenGate能夠正常工作,源數據庫需要進行一定配置。
2.1 設置源庫為歸檔模式
SQL> shutdown immediate
SQL> startup mount
SQL> alter database archivelog;
SQL> alter database open;
2.2 開啟minimal supplemental logging
SQL> alter database add supplemental log data;
SQL> select SUPPLEMENTAL_LOG_DATA_MIN from v$database;
SUPPLEME
——–
YES
2.3 關閉數據庫的recyblebin
SQL> alter system set recyclebin=off scope=spfile;
如果數據庫是10g,需要關閉recyclebin并重啟;或者手工purge recyclebin。
2.4 配置復制的DDL支持
SQL> create user ggate identified by ggate default tablespace users temporary tablespace temp;
SQL> grant connect,resource,unlimited tablespace to ggate;
SQL> grant execute on utl_file to ggate;SQL> @$GGATE/marker_setup.sql;
SQL> @$GGATE/ddl_setup.sql;
SQL> @$GGATE/role_setup.sql;
SQL> grant GGS_GGSUSER_ROLE to ggate;
SQL> @$GGATE/ddl_enable.sql;
2.5 創建源端和目標端的測試用戶
source
SQL> create user sender identified by oracle default tablespace users temporary tablespace temp;
SQL> grant connect,resource,unlimited tablespace to sender;
destination
SQL> create user receiver identified by oracle default tablespace users temporary tablespace temp;
SQL> grant connect,resource,unlimited tablespace to receiver;
3. 配置manager
在源端和目標端分別執行下面的步驟。
3.1 創建manager
[ggate@gridcontrol gg]$ ./ggsci
GGSCI (gridcontrol) 1> info all
Program Status Group Lag Time Since Chkpt
MANAGER STOPPEDGGSCI (gridcontrol) 2> edit params mgr
PORT 7809
ggate (gridcontrol) 3> start manager
Manager started.
4. 配置源端復制隊列
GGSCI (gridcontrol) 1> add extract ext1, tranlog, begin now
EXTRACT added.
GGSCI (gridcontrol) 2> add exttrail /u01/app/oracle/ggate/dirdat/lt, extract ext1
EXTTRAIL added.
GGSCI (gridcontrol) 3> edit params ext1
extract ext1
userid ggate@source , password oracle
rmthost centos4, mgrport 7809
rmttrail /u01/app/oracle/ggate/dirdat/lt
ddl include mapped objname sender.*;
table sender.*;GGSCI (gridcontrol) 6> info all
Program Status Group Lag Time Since Chkpt
MANAGER STOPPED
EXTRACT STOPPED EXT1 00:00:00 00:10:55
5. 配置目標端同步隊列
5.1 在目標端添加checkpoint表
[oracle@centos4 ggate]$ ./ggsci
GGSCI (centos4) 1> edit params ./GLOBAL –添加下列內容
GGSCHEMA ggate
CHECKPOINTTABLE ggate.checkpoint
GGSCI (centos4) 2> dblogin userid ggate@target
Password:Successfully logged into database.
GGSCI (centos4) 3> add checkpointtable ggate.checkpoint
Successfully created checkpoint table GGATE.CHECKPOINT.
5.2 創建同步隊列
GGSCI (centos4) 4> add replicat rep1, exttrail /u01/app/oracle/ggate/dirdat/lt, checkpointtable ggate.checkpoint
REPLICAT added.GGSCI (centos4) 5> edit params rep1
replicat rep1
ASSUMETARGETDEFS
userid ggate@target , password ggate
discardfile /u01/app/oracle/ggate/dirdat/rep1_discard.txt, append, megabytes 10
DDL
map sender.*, target receiver.*;
6. 開啟同步
GGSCI (gridcontrol) 14> start extract ext1
GGSCI (gridcontrol) 15> info all
Program Status Group Lag Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING EXT1 00:00:00 00:00:05
GGSCI (centos4) 7> start replicat rep1
GGSCI (centos4) 8> info all
Program Status Group Lag Time Since Chkpt
MANAGER RUNNING
REPLICAT RUNNING REP1 00:00:00 00:00:00
7. 驗證結果
源端:
SQL> create table sender.test_tab_1 (id number,rnd_str varchar2(12));
SQL> insert into sender.test_tab_1 values (1,’test_1′);
SQL> commit;
目標端:
SQL> select * from receiver.test_tab_1;
ID RND_STR
———- ————
1 test_1
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
