10.Oracle Golden Date(ogg)的搭建和管理
一. GoldenGate 概述
GoldenGate現在是業內成熟的數據容災與復制產品;GoldenGate是一種基於日誌的結構化數據復制方式,它通過解析源數據庫在線日誌或歸檔日誌獲得數據的增刪改變化(數據量只有日誌的四分之一左右),再將這些變化應用到目標數據庫,實現源數據庫與目標數據庫同步、雙活。
二. GoldenGate 搭建
目標在linux系統下安裝Oracle;利用GoldenGate 實現數據同步;可復制DML和DDL操作
環境如下:本環境目標端是源端的克隆;步驟請參考第8篇
源端 | 目標端 | |
操作系統 | linux6.5 | linux6.5 |
IP | 192.168.1.235 | 192.168.1.221 |
數據庫版本 | 11.2.0.4.0 | 11.2.0.4.0 |
GoldenGate版本 | 11.2.1.0.1 | 11.2.1.0.1 |
useradd -u 1003 -g oinstall -G dba ogg passwd ogg
2.2 修改 GoldenGate 系統用戶環境變量
source /home/oracle/.bash_profile # or export ORACLE_BASE=/u01/app export ORACLE_HOME=$ORACLE_BASE/oracle export ORACLE_SID=ora221 export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin/data/ogg export NLS_LANG=AMERICAN_AMERICA.UTF8 export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH alias sqlplus=‘rlwrap sqlplus‘ alias ggsci=‘rlwrap ggsci‘
mkdir -p /data/ogg chown -R ogg:oinstall /data/ogg
unzip fbo_ggs_Linux_x64_ora11g_64bit.tar.zip tar -xvf fbo_ggs_Linux_x64_ora11g_64bit.tar -C /data/ogg
create tablespace tsp_ogg datafile ‘/data/oracle/data/ogg01.dbf‘ size 100M autoextend on;
create user ogg identified by ogg default tablespace tsp_ogg; grant dba to ogg; GRANT CREATE TABLE,CREATE SEQUENCE TO OGG;
alter system set log_archive_dest_1 = ‘LOCATION=/data/arch‘ scope = spfile; shutdown immediate; startup mount alter database archivelog; alter database open;
還需要開啟 force log 和 supplemental log
alter database force logging; alter database add SUPPLEMENTAL log data;
最後查詢結果如下:
SQL> select NAME,OPEN_MODE,FORCE_LOGGING,SUPPLEMENTAL_LOG_DATA_MIN from v$database; NAME OPEN_MODE FOR SUPPLEME --------- -------------------- --- -------- ORA235 READ WRITE YES YES
@marker_setup.sql @ddl_setup.sql @role_setup.sql @ddl_enable.sql
在11.2.0.4.0版本;需要設置
ALTER SYSTEM SET ENABLE_GOLDENGATE_REPLICATION = TRUE SCOPE=BOTH;
只有commit之後的日誌信息才會被Capture進程捕獲,未提交的事務OGG不會捕獲。
[ogg@oracle235 ogg]$ ggsci Oracle GoldenGate Command Interpreter for Oracle Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230_FBO Linux, x64, 64bit (optimized), Oracle 11g on Apr 23 2012 08:32:14 Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved. GGSCI (oracle235) 1> create subdirs Creating subdirectories under current directory /data/ogg Parameter files /data/ogg/dirprm: already exists Report files /data/ogg/dirrpt: created Checkpoint files /data/ogg/dirchk: created Process status files /data/ogg/dirpcs: created SQL script files /data/ogg/dirsql: created Database definitions files /data/ogg/dirdef: created Extract data files /data/ogg/dirdat: created Temporary files /data/ogg/dirtmp: created Stdout files /data/ogg/dirout: created
GGSCI (oracle235) 2> EDIT PARAMS ./GLOBALS CHECKPOINTTABLE ogg.ggschkpt GGSCI (oracle235) 3> exit [ogg@oracle235 ogg]$ ggsci Oracle GoldenGate Command Interpreter for Oracle Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230_FBO Linux, x64, 64bit (optimized), Oracle 11g on Apr 23 2012 08:32:14 Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved. GGSCI (oracle235) 1> DBLOGIN USERID ogg, PASSWORD ogg Successfully logged into database. GGSCI (oracle235) 2> ADD CHECKPOINTTABLE No checkpoint table specified, using GLOBALS specification (ogg.ggschkpt)... Successfully created checkpoint table ogg.ggschkpt.
[ogg@oracle235 ogg]$ ggsci Oracle GoldenGate Command Interpreter for Oracle Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230_FBO Linux, x64, 64bit (optimized), Oracle 11g on Apr 23 2012 08:32:14 Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved. GGSCI (oracle235) 1> EDIT PARAMS MGR
輸入內容如下:
PORT 7809 DYNAMICPORTLIST 7800-8000 AUTORESTART EXTRACT *, WAITMINUTES 2, RESETMINUTES 5 PURGEOLDEXTRACTS /data/ogg/dirdat, USECHECKPOINTS, MINKEEPDAYS 3
GGSCI (oracle235) 2> start mgr Manager started. GGSCI (oracle235) 3> info mgr Manager is running (IP port oracle235.7809).
GGSCI (oracle235) 1> EDIT PARAMS EORA_1 EXTRACT EORA_1 SETENV (NLS_LANG=AMERICAN_AMERICA.UTF8) USERID ogg, PASSWORD ogg EXTTRAIL /data/ogg/dirdat/aa TABLE lottu.*;
在源端用 add extract 命令創建 extract 組;用add exttrail 命令創建本地 trail 文件
GGSCI (oracle235) 2> ADD EXTRACT EORA_1, TRANLOG, BEGIN NOW EXTRACT added. GGSCI (oracle235) 3> ADD EXTTRAIL /data/ogg/dirdat/aa, EXTRACT EORA_1, MEGABYTES 5 EXTTRAIL added.
啟動 extract 進程;在 ggsci 中:可以使用 add, alter, cleanup, delete, info, kill命令管理extract進程
GGSCI (oracle235) 4> start extract eora_1 Sending START request to MANAGER ... EXTRACT EORA_1 starting GGSCI (oracle235) 5> info eora_1 EXTRACT EORA_1 Last Started 2018-08-23 00:52 Status RUNNING Checkpoint Lag 00:06:20 (updated 00:00:04 ago) Log Read Checkpoint Oracle Redo Logs 2018-08-23 00:46:36 Seqno 12, RBA 34652672 SCN 0.0 (0)
GGSCI (oracle235) 6> EDIT PARAMS PORA_1 EXTRACT PORA_1 SETENV (NLS_LANG=AMERICAN_AMERICA.UTF8) PASSTHRU RMTHOST 192.168.1.221, MGRPORT 7809 RMTTRAIL /data/ogg/dirdat/pa TABLE lottu.*;
用 add extract 指定本地 trail 文件
GGSCI (oracle235) 7> ADD EXTRACT PORA_1, EXTTRAILSOURCE /data/ogg/dirdat/aa EXTRACT added.
用 add rmttrail 指定遠程 trail 文件
GGSCI (oracle235) 8> ADD RMTTRAIL /data/ogg/dirdat/pa, EXTRACT PORA_1, MEGABYTES 5 RMTTRAIL added.
啟動 pump 進程
GGSCI (oracle235) 9> START EXTRACT PORA_1 Sending START request to MANAGER ... EXTRACT PORA_1 starting GGSCI (oracle235) 11> info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING EXTRACT RUNNING EORA_1 00:00:00 00:00:07 EXTRACT RUNNING PORA_1 00:00:00 00:00:02
GGSCI (oracle221) 2> EDIT PARAMS RORA_1 REPLICAT RORA_1 SETENV (NLS_LANG=AMERICAN_AMERICA.UTF8) USERID ogg, PASSWORD ogg HANDLECOLLISIONS ASSUMETARGETDEFS DISCARDFILE /data/ogg/dirrpt/RORA_aa.rpt, append MAP lottu.*, TARGET lottu.*;
在目標端使用 add replicat 添加 Replicat 進程
GGSCI (oracle221) 8> add replicat RORA_1, exttrail /data/ogg/dirdat/pa REPLICAT added.
使用 start replicat 啟動 Replicat 進程
GGSCI (oracle221) 11> start REPLICAT RORA_1 Sending START request to MANAGER ... REPLICAT RORA_1 starting GGSCI (oracle221) 12> info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING REPLICAT RUNNING RORA_1 00:00:00 00:00:00
alter system set recyclebin=off scope=both;
GGSCI (oracle235) 19> view params ./GLOBALS GGSCHEMA OGG
停MGR,Extract進程;
配置Extract配置文件;在配置文件添加一下內容:
DDL INCLUDE ALL
DDLOPTIONS ADDTRANDATA,REPORT
停MGR,Replicat進程;
配置Replicat配置文件;在配置文件添加一下內容:
DDL INCLUDE MAPPED
DDLOPTIONS REPORT
配置完成;在重啟各進程進行驗證。
10.Oracle Golden Date(ogg)的搭建和管理