OGG19.1 oracle12c到oracle12c經典和整合模式配置實施
-
目的說明
本文提供Oracle GoldenGate在Oracle db到Oracle db的資料複製安裝配置指導,適用於入門練習使用,生產環境配置,在關鍵步驟和重要引數設定需要小心對待。
OGG19.1 oracle12c到oracle12c經典和整合模式配置實施 ---- 支援DDL複製配置。 -
參考文件
《叱吒風雲GoldenGate企業級運維實戰》
Oracle GoldenGate Document 12.3.0/19.1.0 -
準備系統
準備好兩套已經裝好Oracle db和Oracle GoldenGate for Oracle的環境。
-- 安裝步驟略
-- https://docs.oracle.com/en/middleware/goldengate/core/19.1/installing/installing-classic-architecture.html
-- ./runInstaller -silent -responseFile /tmp/trace/fbo_ggs_Linux_x64_shiphome/Disk1/response/oggcore.rsp
-- /orabin/oraInventory/logs/installActions2020-07-06_04-46-55PM.log
--
source db:
ip:192.168.6.20
db type:Oracle db 12.2.0.1.0
target db:
ip:192.168.6.20
db type:Oracle db 12.2.0.1.0
GoldenGate:
ogg type:GoldenGate for Oracle 19.1.0.0.4
-
配置source db
4.1 配置source db引數
source db的配置主要是歸檔模式修改、附加日誌的新增、強制日誌和--ddl語句的支援。--#源端DB開啟歸檔模式和最小附加日誌 --4.1.1 源端DB開啟歸檔模式 archive log list --#啟用主動歸檔 -- 關閉並mount資料庫 shutdown immediate startup mount -- 開啟歸檔日誌 alter database archivelog; -- 設定本地歸檔路徑 alter system set log_archive_dest_1='location=/oradata/oggsdb/archive' scope=spfile; -- 設定歸檔日誌檔名格式 show parameter log_archive_format ----default %t_%s_%r.dbf alter system set log_archive_format='oggsdb_%t_%s_%r.arc' scope=spfile; --關閉資料庫,再啟動資料庫 ,使引數 log_archive_dest_1生效 shutdown immediate startup --檢查配置和引數生效 archive log list show parameter log_archive_dest_1 show parameter log_archive_format -- 4.1.2 強制日誌變更 alter database force logging; --實時生效 強制日誌 --ALTER DATABASE NO FORCE LOGGING; -- 4.1.3 開啟最小附加日誌 和 檢視最小附加日誌 alter database add supplemental log data; --實時生效 最小附加日誌 --alter database drop supplemental log data; --檢視source db歸檔、附加日誌和強制日誌: select supplemental_log_data_min from v$database; select db.LOG_MODE, db.SUPPLEMENTAL_LOG_DATA_MIN, db.FORCE_LOGGING from v$database db; select db.NAME, db.LOG_MODE, db.FLASHBACK_ON, db.FORCE_LOGGING, db.supplemental_log_data_min, db.supplemental_log_data_pk, db.supplemental_log_data_ui, db.supplemental_log_data_ui, db.supplemental_log_data_fk, db.supplemental_log_data_all, db.supplemental_log_data_pl from v$database db; -- 4.1.4 修改GoldenGate引數 show parameter enable_goldengate_replication alter system set enable_goldengate_replication = true scope = both; show parameter enable_goldengate_replication -- 4.1.5 建立GoldenGate使用者 create tablespace ogg_data datafile '/oradata/oggsdb/ogg_data01.dbf' size 50M autoextend on next 8M; create user ogg identified by Password123 default tablespace ogg_data quota unlimited on ogg_data; 授權GoldeGate使用者 : grant connect, resource to ogg; grant alter any table, alter system,alter user, create session, alter session to ogg; grant select any dictionary, SELECT ANY TRANSACTION,select any table,flashback any table to ogg; --grant DBA to ogg; -- DDL and sequence support --GRANT FLASHBACK ANY TABLE TO db_user --GRANT FLASHBACK ON schema.table TO db_user --11.2.0.4 or later需要執行以下package 許可權 : begin dbms_goldengate_auth.grant_admin_privilege(grantee => 'OGG', privilege_type => 'CAPTURE', grant_select_privileges => TRUE, do_grants => TRUE); END; / /*----此包dbms_goldengate_auth.grant_admin_privilege授予許可權如下18個許可權: -- Grant/Revoke object privileges grant execute on LOGMNR$COL_GG_TABF_PUBLIC to OGG; grant execute on LOGMNR$GSBA_GG_TABF_PUBLIC to OGG; grant execute on LOGMNR$KEY_GG_TABF_PUBLIC to OGG; grant execute on LOGMNR$SEQ_GG_TABF_PUBLIC to OGG; grant execute on LOGMNR$TAB_GG_TABF_PUBLIC to OGG; grant insert on LOGMNR_RESTART_CKPT$ to OGG; -- Grant/Revoke role privileges grant select_catalog_role to OGG; -- Grant/Revoke system privileges grant alter any table to OGG; grant alter session to OGG; grant create evaluation context to OGG with admin option; grant create job to OGG; grant create rule to OGG with admin option; grant create rule set to OGG with admin option; grant dequeue any queue to OGG with admin option; grant execute any rule set to OGG with admin option; grant flashback any table to OGG; grant logmining to OGG; grant select any table to OGG; */ --4.1.6 配置DDL語句支援 ( Support for DDL Capture in Classic Capture Mode ) --Classic capture mode requires the use of the Oracle GoldenGate DDL trigger to --capture DDL from an Oracle Database. Native DDL capture is not supported by classic capture mode. --授權GoldeGate使用者 :(除以上 4.1.5 授權部分外,還需要 DBA 許可權 支援 DDL and sequence 捕獲) --a. --建立存放ddl資訊的GoldenGate使用者: ( 如上 共用 ogg 使用者 ) --create tablespace ogg_data datafile '/oradata/oggsdb/ogg_data01.dbf' size 50M autoextend on next 8M; --create user ogg identified by Password123 default tablespace ogg_data quota unlimited on ogg_data; --b. 此可暫時忽略 -- (Optional)To cause user DDL activity to fail when the DDL tablespace fills up, edit the params.sql script -- and set the ddl_fire_error_in_trigger parameter to TRUE. As a best practice, make certain to size the tablespace appropriately in the first place. #params.sql內容 define the ddl_fire_error_in_trigger = 'TRUE' define allow_invisible_index_keys = 'TRUE' #To enable trigger-based DDL replication to recognize Oracle invisible indexes as #unique identifiers, set the following parameter to TRUE in the params.sql script: --c. 此可暫時忽略 --#at the root of the Oracle GoldenGate directory. Do not alterthe file name or location. EDIT PARAMS ./GLOBALS # 內容 GGSCHEMA schema_name ##Save and close the GLOBALS file and the params.sql file. --d. grant dba to ogg ; GRANT EXECUTE ON utl_file TO ogg; #Change directories to the Oracle GoldenGate installation directory. # ----The specific location is: oggma_install_home/lib/sql/legacy. #Exit all Oracle sessions. Prevent the start of any new sessions. 進入GoldenGate目錄,呼叫SQL指令碼: cd $OGG_HOME sqlplus / as sysdba SQL> @marker_setup.sql; #輸入準備好的使用者ogg SQL> @ddl_setup.sql; #輸入準備好的使用者ogg SQL> @role_setup.sql; #輸入準備好的使用者ogg #Grant the role that was created (default name is GGS_GGSUSER_ROLE) to all Oracle GoldenGate Extract users. #根據上面執行結果的提示授權角色給ogg使用者 SQL> grant GGS_GGSUSER_ROLE to ogg; SQL> @ddl_enable.sql; ##To Install and Use the Optional Performance Tool SQL> @ddl_pin ogg 至此,ddl語句的支援配置完成。 #驗證DDL安裝 --執行marker_status.sql校驗DDL的狀態 SQL> @marker_status.sql ------------------------------------ -- Removing the DDL Objects from the System -- 解除安裝 DDL 複製 支援 -- cd $OGG_HOME -- ggsci -- ggsci> STOP EXTRACT group1 -- ggsci> STOP REPLICAT group1 -- -- sqlplus / as sysdba -- SQL> @ddl_disable.sql; -- SQL> @ddl_remove.sql -- SQL> @marker_remove.sql
4.2 配置source db manager程式
--EXTRACT exoggs
--SETENV (ORACLE_HOME="/orabin/product/12.2.0.1")
--SETENV (ORACLE_SID = "OGGSDB")
進入GoldenGatean安裝目錄,建立工作區目錄:
cd $OGG_HOME
./ggsci
GGSCI (dbserver) 1> create subdirs
Creating subdirectories under current directory /oradata/ogg
Parameter file /oradata/ogg/dirprm: created.
Report file /oradata/ogg/dirrpt: created.
Checkpoint file /oradata/ogg/dirchk: created.
Process status files /oradata/ogg/dirpcs: created.
SQL script files /oradata/ogg/dirsql: created.
Database definitions files /oradata/ogg/dirdef: created.
Extract data files /oradata/ogg/dirdat: created.
Temporary files /oradata/ogg/dirtmp: created.
Credential store files /oradata/ogg/dircrd: created.
Masterkey wallet files /oradata/ogg/dirwlt: created.
Dump files /oradata/ogg/dirdmp: created.
GGSCI (dbserver) 2>
--建立資料目錄(可在dirdat目錄下為 oggsdb的抽取程式建立一個單獨資料存放目錄 )
--cd $OGG_HOME
--oracle[/oradata/ogg]$mkdir -p dirdat/oggsdb
---- /oradata/ogg/dirdat/oggsdb
編輯配置manager引數檔案 :
GGSCI > edit params mgr
新增以下內容
PORT 7809
DYNAMICPORTLIST 7800-7900
ACCESSRULE, PROG , IPADDR 192.168.6.20, ALLOW
ACCESSRULE, PROG SERVER, ALLOW
--PURGEOLDEXTRACTS ./dirdat/oggsdb/ex, usecheckpoints, minkeephours 12 #### 引數 minkeepdays 2
PURGEOLDEXTRACTS ./dirdat//, usecheckpoints, minkeepdays 2 #### 同一臺主機,源和目標庫共用一個MGR
AUTORESTART EXTRACT *, RETRIES 5, WAITMINUTES 2, RESETMINUTES 60
lagreporthours 1
laginfominutes 30
lagcriticalminutes 45
*/
對需要的表新增trandata
cd $OGG_HOME
./ggsci
GGSCI > dblogin userid ogg@oggsdb password Password123
Successfully logged into database.
GGSCI > add trandata scott.emp
--info trandata scott.emp
--select * from DBA_LOG_GROUPS
4.3 配置source db extract程式
--select * from nls_database_parameters
新增一個extract程式 :
GGSCI > add extract exggsdb,tranlog,begin now ----, threads 2
編輯extract引數檔案:
GGSCI (dbserver) 13> edit params exggsdb
新增以下內容
extract exggsdb
setenv (ORACLE_SID = "OGGSDB")
setenv (NLS_LANG = "AMERICAN_AMERICA.AL32UTF8")
userid ogg@oggsdb, password Password123
TRANLOGOPTIONS DBLOGREADER
reportcount every 30 minutes, rate
discardrollover at 3:00
warnlongtrans 2h, checkinterval 300
exttrail /oradata/ogg/dirdat/oggsdb/ex
discardfile /oradata/ogg/dirdat/exggsdb.dsc, append, megabytes 100
--gettruncates ---- DDL support parameter
getupdatebefores
nocompressdeletes
nocompressupdates
--LOGALLSUPCOLS
dboptions allowunusedcolumn
fetchoptions nousesnapshot
fetchoptions fetchpkupdatecols
table SCOTT.EMP;
建立本地trail檔案 :
GGSCI > add exttrail /oradata/ogg/dirdat/oggsdb/ex, extract exggsdb
EXTTRAIL added.
4.4 配置source db pump程式
新增一個pump程式(本質上也是extract程式),並指定遠端trail檔案:
GGSCI > add extract ppggsdb,exttrailsource /oradata/ogg/dirdat/oggsdb/ex
EXTRACT added.
編輯pump引數檔案:
GGSCI (dbserver) 16> edit params ppggsdb
新增以下內容
extract ppggsdb
passthru
rmthost 192.168.6.20, mgrport 7809 ---- target db主機ip,管理程式埠號 ##共用同一臺主機的mgr程式 測試
rmttrail /oradata/ogg/dirdat/oggtdb/pp
--ddl -- DDL support parameter
table scott.emp;
指定遠端trail檔案:
GGSCI > add rmttrail /oradata/ogg/dirdat/oggtdb/pp, extract ppggsdb
RMTTRAIL added.
4.5 啟動source程式
檢視extrac程式,啟動程式後注意檢視ggserr.log的日誌資訊,確認無警告錯誤,啟動pump程式需先啟動target db的mgr程式,否則會報錯無法啟動:
開一個命令列:
cd $OGG_HOME
tail -f 50 ggserr.log
再開一個命令列:
cd $OGG_HOME
./ggsci
GGSCI > info all
GGSCI > start mgr
GGSCI > start exggsdb
GGSCI > start ppggsdb
GGSCI > info all
##########同一臺主機,兩個oracle資料庫測試(source --> target), 可以共用OGG MGR 程式?!
##########若 源資料庫 和 目標資料庫 在不同主機,目標端也需要安裝OGG ,並配置OGG 資料目錄。
- 配置target db
5.1 配置target db引數
5.1.1 建立GoldenGate使用者
建立GoldenGate使用者
create tablespace ogg_data datafile '/oradata/oggtdb/ogg_data01.dbf' size 50M autoextend on next 8M;
create user ogg identified by Password123 default tablespace ogg_data quota unlimited on ogg_data;
設定enable_goldengate_replication引數為true
alter system set enable_goldengate_replication = true scope = both;
授權GoldeGate使用者 :
grant connect, resource to ogg;
grant alter any table, alter system,alter user, create session, alter session to ogg;
grant select any dictionary, SELECT ANY TRANSACTION,select any table,flashback any table to ogg;
授權GoldeGate使用者 :
grant dba to ogg; ---- 支援DDL replicate配置
5.1.2 新增checkpoint表
GGSCI> edit params ./GLOBALS
新增以下內容
ggschema ogg
checkpointtable ogg.checkpoint
登陸target db新增checkpoint表
export ORACLE_SID=OGGTDB
./ggsci
GGSCI > dblogin userid ogg@OGGTDB, password Password123
Successfully logged into database.
GGSCI (dbserver as ogg@OGGTDB) > add checkpointtable ogg.checkpoint
Successfully created checkpoint table ogg.checkpoint.
5.1 配置target db manager程式
----編輯manager引數檔案: ---- 同一臺主機,兩個oracle資料庫,可以共用同一個 MGR
----GGSCI (dbserver as ogg@orcl) > edit params mgr
----#新增以下內容
----PORT 7809
----DYNAMICPORTLIST 7800-7900
----ACCESSRULE, PROG , IPADDR 192.168.6.20, ALLOW
----PURGEOLDEXTRACTS ./dirdat/oggtdb/, usecheckpoints, minkeepdays 2 #### 引數 minkeepdays 2 #minkeephours 12
----AUTORESTART ER *, RETRIES 5, WAITMINUTES 2, RESETMINUTES 60
----lagreporthours 1
----laginfominutes 30
----lagcriticalminutes 45
5.2 配置target db replicat程式
新增一個replicat程式 :
GGSCI (dbserver) 2>
GGSCI (dbserver) 2>
GGSCI (dbserver as ogg@oggtdb) 4> add replicat repggtdb,exttrail /oradata/ogg/dirdat/oggtdb/pp
編輯replicat引數檔案:
GGSCI (dbserver as ogg@oggtdb) 6> edit params repggtdb
新增以下內容
replicat repggtdb
setenv (ORACLE_SID = "OGGTDB")
setenv (NLS_LANG = "AMERICAN_AMERICA.AL32UTF8")
userid ogg@oggtdb, password Password123
dboptions deferrefconst
gettruncates
report at 06:00
reportcount every 30 minutes, rate
reportrollover at 02:00
--reperror default, abend
REPERROR DEFAULT,DISCARD
DBOPTIONS NOSUPPRESSTRIGGERS
--handlecollisions
allownoopupdates
--assumetargetdefs
discardfile /oradata/ogg/dirdat/oggtdb/repggtdb.dsc, append, megabytes 100
discardrollover at 02:00
--DDL
map scott.emp, target scott.emp;
----啟動 MGR 和 REPLICATE 程式。
-
故障排查trouble shooting
-
測試case