如何安裝使用goldengate
一.環境:OS:linux CentOS_Final_5.5(64bit)DB:oracle11gR2(單機模式)goldengate: ggs_Linux_x64_ora11g_64bit_v11_1_1_0_0_078.tar網路:區域網路,源端IP 192.168.128.100 鏡像端IP 192.168.128.101二.目標:
實現源端到鏡像端的資料同步(單向)
三.源端資料庫實施:1資料庫準備1.1開啟資料庫歸檔日誌
查看資料庫當前記錄模式
archive log list;
更改為歸檔模式
shutdown immediate;
start mount;
alter database archivelog;
alter database open;
開啟第二歸檔路徑(可選)
alter system set log_archive_dest_2=’location=/archive_2OPTIONAL’ scope=spfile;
alter system archive log start tolog_archive_dest_2;
查看第二歸檔日誌是否生效(重啟資料庫)
show parameter archive;
1.2開啟supplemental logging和force logging
查看當前資料庫是否開啟supplementallogging
select SUPPLEMENTAL_LOG_DATA_MIN fromv$database;
開啟資料庫層級的最小supplementallogging
alter database add supplemental log data;
查看當前資料庫forcelogging的狀態
select force_logging from v$database;
開啟forcelogging
alter database force logging;
1.3建立goldengate系統管理使用者,並賦予相關許可權
建立系統管理使用者的資料表空間
create tablespace tbs_ggmgr datafiel ‘/u01/app/oracle/goldengate/ggmgr.dbf’size 50M autoextend on;
建立goldengate系統管理使用者
create user ggmgr identified by oracledefault tablespace tbs_ggmgr temporary tablespace TEMP quota unlimited ontbs_ggmgr;
賦予ggmgr相關許可權(想簡單的話,可以賦予DBA許可權)
grant CONNECT,RESOURCE to ggmgr;
grant CREATE SESSION,ALTER SESSION toggmgr;
grant SELECT ANY DICTIONARY,SELECT ANYTABLE to ggmgr;
grant CREATE TABLE,ALTER ANY TABLE to ggmgr;
1.4建立測試使用者和表
create user test identified by test;
conn test/test;
create table test(
stuid number(8),
stuname varchar2(20),
stupasswd varchar2(20)
);
insert into test values(1,’test1’,’test1);
insert into test values(2,’test2’,’test2’);
commit;
2goldengate安裝及參數設定2.1設定goldengate運行所需的環境變數
編輯oracle的home目錄下.bash_profile檔案
vi .bash_profile
添加如下內容
exportLD_LIBRARY_PATH=$ORACLE_BASE/goldengate:$ORACLE_HOME/lib
2.2建立goldengate安裝目錄
通常將goldengate安裝在ORACLE_BASE目錄下
mkdir –p /u01/app/oracle/goldengate/
2.3解壓並初始化goldengate
將goldengate壓縮檔解壓到goldengate得安裝目錄
tar vxf ggs_Linux_x64_ora11g_64bit_v11_1_1_0_0_078.tar
執行./ggsci進入GGSCI
建立目錄結構
create subdirs --只在第一次啟動執行
2.4 添加trandata
在GGSCI中
dbloign userid ggmgr,password oracle
對要進行複製的表添加表級supplemental logging
add trandata test.*
查看
info trandata test.*
2.5添加並配置mgr進程
edit param mgr
添加如下內容
port 7809
purgeoldextracts ./dirdat/*,usecheckpoints, minkeepfiles 20
2.6添加並配置extract進程
添加一個extract進程
add extract exts100,tranlog,begin now
給extract進程指定trail檔案
add exttrail ./dirdat/s1,extract exts100,megabytes 100
配置extract的參數
edit param exts100
添加如下內容(開啟第二歸檔的情況下)
extract exts100
userid ggmgr,password oracle
tranlogoptions archivedlogonly
tranlogoptions altarchivelogdest instanceorcl /archive_2
tranlogoptions altarchivedlogformat%t_%s_%r.dbf
gettruncates
reportcount every 30 minutes,rate
discardfile./dirrpt/exts100.dsc,APPEND,MEGABYTES 100
exttail ./dirdat/s1
table TEST.TEST;
2.7添加並配置pump進程
add extract dps100 exttrailsource./dirdat/s1
add rmttrail ./dirdat/t1,extract dps100
配置pump進程參數
edit param dps100
extract dps100
userid ggmgr,password oracle
rmthost 192.168.128.101,mgrport7809,compress
numfiles 5000
DYNAMICRESOLUTION
rmttrail ./dirdat/t1
table TEST.TEST;
2.8檢查進程是否能夠成功啟動
start <進程名>
start mgr
start exts100
start dps100
查看進程狀態
info all
四.鏡像端資料庫的初始化1.從源端資料庫匯出相關的資料和表結構(需要相關許可權,可以使用有DBA許可權的使用者)
exp username/password file=test_1203013.dmpowner=test triggers=n indexes=n log=test_120313.log;
2.將匯出的資料檔案傳到鏡像端
可以使用ftp
3.在鏡像端建立和源端對應的使用者和資料表空間,要保持資料表空間的名字一致
create user test identified by test;
4.在鏡像端匯入資料檔案(需要相關許可權,可以使用有DBA許可權的使用者)
imp username/password file=test_120313.dmpfromuser=test touser=test log=test_120313.log;
查看資料是否匯入成功
五.鏡像端資料庫實施1資料庫準備
建立系統管理使用者的資料表空間
create tablespace tbs_ggmgr datafiel ‘/u01/app/oracle/goldengate/ggmgr.dbf’size 50M autoextend on;
建立goldengate系統管理使用者
create user ggmgr identified by oracledefault tablespace tbs_ggmgr temporary tablespace TEMP quota unlimited ontbs_ggmgr;
賦予ggmgr相關許可權(想簡單的話,可以賦予DBA許可權)
grant CONNECT,RESOURCE to ggmgr;
grant CREATE SESSION,ALTER SESSION toggmgr;
grant SELECT ANY DICTIONARY,SELECT ANYTABLE to ggmgr;
grant CREATE TABLE to ggmgr;
2goldengate安裝及參數設定
2.1.設定goldengate運行所需的環境變數
編輯oracle的home目錄下.bash_profile檔案
vi .bash_profile
添加如下內容
exportLD_LIBRARY_PATH=$ORACLE_BASE/goldengate:$ORACLE_HOME/lib
2.2.建立goldengate安裝目錄
通常將goldengate安裝在ORACLE_BASE目錄下
mkdir –p /u01/app/oracle/goldengate/
2.3.解壓並初始化goldengate
將goldengate壓縮檔解壓到goldengate得安裝目錄
tar vxf ggs_Linux_x64_ora11g_64bit_v11_1_1_0_0_078.tar
執行./ggsci進入GGSCI
建立目錄結構
create subdirs --只在第一次啟動執行
2.4編輯全域參數檔案
dblogin userid ggmgr,password oracle
edit params ./GLOBALS
添加如下內容
checkpointtable ggmgr.ogg_checkpointtable
添加檢查點表
add checkpointtableggmgr.ogg_checkpointtable
2.5.添加並配置mgr進程
edit param mgr
添加如下內容
port 7809
(這裡沒有加入清除trail檔案的設定)
2.6.添加並配置replicat進程
add replicat rept101,exttrail ./dirdat/t1
編輯replicat進程的參數檔案
edit param rept101
添加如下內容
replicat rept101
userid ggmgr,password oracle
ASSUMETARGETDEFS
DISCARDFILE ./dirrpt/rept101.dsc,PURGE
MAP TEST.TEST, TARGET TEST.TEST;
2.7檢查進程能否成功啟動
start <進程名>
start mgr
start rept101
查看進程狀態
info all
六.測試1.在源端資料庫插入資料
insert into test values(3,’test3,’test3’);
commit;
2.產生歸檔日誌
alter system switch logfile;
3.查看鏡像端資料庫
select * from test;