使用GoldenGate 遷移Oracle到PostgreSQL/LightDB
說明
1.1資料庫國產化背景Oracle遷移到PostgreSQL/LightDB
OGG軟體介質:Oracle GoldenGate V11.2.1.0.1 for Oracle 10g on Linux x86-64 84.7 MB
利用OGG+ora2pg遷移
源 庫:centos 7 單節點Oracle 19c
目標庫:centos 7 單節點LightDB22.1
搭建目標資料庫和OGG軟體
2.1建立OGG安裝目錄(兩端)
源和目標兩臺伺服器都需要建立ogg的安裝目錄 ggs_Linux_x64_PostgreSQL_64bit.tar
V983658-01.zip
2.2建立ogg的管理使用者,使用oracle作為ogg的管理使用者。(源端)
在oracle環境變數配置檔案中增加以下內容:
export EDITOR=vi export GGATE=/home/oracle/ogg19c export NLS_LANG=AMERICAN_AMERICA.AL32UTF8 export ORACLE_BASE=/u01/app/oracle export ORACLE_HOME=/home/oracle export ORACLE_SID=test export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$GGATE:$PATH export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib:$GGATE:$LD_LIBRARY_PATH alias sqlplus='rlwrap sqlplus' alias ggsci='rlwrap ggsci'
2.3建立OGG表空間和使用者(源端)
create tablespace ogg datafile '/data2/oradata/TEST/ogg01.dbf' size 50M autoextend on; create user ogg identified by ogg default tablespace ogg; grant connect, resource TO ogg; grant select any dictionary, select any table TO ogg; grant flashback any table TO ogg; grant execute on dbms_flashback TO ogg; grant ALTER ANY TABLE to ogg; grant insert any table to ogg; grant update any table to ogg; grant delete any table to ogg; grant create table,create sequence to ogg; grant execute on utl_file to ogg;
2.4新增附加日誌和force logging,並切換日誌(源端)
如果源端不開啟歸檔,需新增多組日誌。
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 FORCE_LOGGING SUPPLEME --------- -------------------- ------------------- -------- ORCL READ WRITE YES YES
2.5 建立OGG的管理工作目錄(源端)
在配置OGG程式之前,首先需要建立OGG的管理目錄,執行以下操作:
ggsci GGSCI (hs-10-20-30-199) 2> create subdirs ##19c會預設建立,無需執行
只有提交事務的record才會被捕獲。抽取、投遞、應用日誌的單位是record,而不是trail檔案。
2.6配置MGR引數檔案,並啟動mgr(源端)
mgr程式是這些程式的管理和守護程式,目標端的mgr程式還與源端進行通訊
源端: edit params mgr PORT 7809 PURGEOLDEXTRACTS /home/oracle/ogg19c/dirdat/*,USECHECKPOINTS, minkeepdays 7 --不清除trail檔案 AUTORESTART EXTRACT *, RETRIES 3, WAITMINUTES 5, RESETMINUTES 60 GGSCI (hs-10-20-30-199) 6> start mgr GGSCI (hs-10-20-30-199) 7> info all
2.7新增extract程式(源端)
抽取程式:負責抓取需要傳輸的資料(新增程式的時候為抽取點,而不是啟動程式的時候)
從21開始OGG需要配置tns
Goldengate DBLOGIN Issue OCI Error ORA (status = 12545-ORA-12545 (Doc ID 2847434.1)
TEST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.20.30.199)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = test) ) )
配置extract程式
edit params ext_1 EXTRACT ext_1 SETENV (NLS_LANG=AMERICAN_AMERICA.UTF8) SETENV (ORACLE_HOME=/home/oracle) SETENV (ORACLE_SID=test) USERID ogg, PASSWORD ogg DISCARDFILE /home/oracle/ogg19c/dirrpt/ext_1.dsc,APPEND,MEGABYTES 1024 EXTTRAIL /home/oracle/ogg19c/dirdat/aa TABLE ta6_pub11*; # 建立 extract 組; ADD EXTRACT ext_1, TRANLOG, BEGIN NOW # 建立本地 trail 檔案 ADD EXTTRAIL /home/oracle/ogg19c/dirdat/aa, EXTRACT ext_1, MEGABYTES 5 # 啟動extract程式 start extract ext_1 GGSCI (hs-10-20-30-199) 16> info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING EXTRACT RUNNING EXT_1 00:00:15 00:00:02
2.8投遞程式(源端)
投遞程式:
EDIT PARAMS pump_1 # 複製如下內容至檔案內,酌情修改引數儲存 EXTRACT pump_1 SETENV (NLS_LANG=AMERICAN_AMERICA.UTF8) PASSTHRU RMTHOST 10.20.30.199, MGRPORT 7810 RMTTRAIL /home/lightdb/ogg/dirdat/pa TABLE ta6_pub11.*; # 用 add extract 指定本地 trail 檔案 ADD EXTRACT pump_1, EXTTRAILSOURCE /home/oracle/ogg19c/dirdat/aa # 用 add rmttrail 指定遠端 trail 檔案 ADD RMTTRAIL /home/lightdb/ogg/dirdat/pa, EXTRACT pump_1, MEGABYTES 5 # 啟動Pump 程式 START EXTRACT pump_1
2.9生成define檔案
在異構的同步複製;需要生成define檔案。用於資料相容不同資料庫。
# 編輯引數檔案 GGSCI (oracle221) 16> edit params defgen # 引數檔案內容 defsfile /home/oracle/ogg19c/dirdef/defgen.def userid ogg, password ogg TABLE ta6_pub11.*; # 退出ggsci命令 GGSCI (oracle221) 17> exit # root使用者下生成檔案 defgen paramfile /home/oracle/ogg19c/dirprm/defgen.prm [oracle@hs-10-20-30-199 ogg19c]$ defgen paramfile /home/oracle/ogg19c/dirprm/defgen.prm *********************************************************************** Oracle GoldenGate Table Definition Generator for Oracle Version 19.1.0.0.4 OGGCORE_19.1.0.0.0_PLATFORMS_191017.1054 Linux, x64, 64bit (optimized), Oracle 19c on Oct 17 2019 15:32:20 Copyright (C) 1995, 2019, Oracle and/or its affiliates. All rights reserved. Starting at 2022-06-30 10:31:23 *********************************************************************** Operating System Version: Linux Version #1 SMP Wed Apr 28 21:49:45 UTC 2021, Release 3.10.0-1160.25.1.el7.x86_64 Node: hs-10-20-30-199 Machine: x86_64 soft limit hard limit Address Space Size : unlimited unlimited Heap Size : unlimited unlimited File Size : unlimited unlimited CPU Time : unlimited unlimited Process id: 106662 *********************************************************************** ** Running with the following parameters ** *********************************************************************** defsfile /home/oracle/ogg19c/dirdef/defgen.def userid ogg, password *** TABLE ta6_pub11.*; Expanding wildcard table specification ta6_pub11.*: Retrieving definition for ta6_pub11.BONUS. 2022-06-30 10:31:24 WARNING OGG-06439 No unique key is defined for table BONUS. All viable columns will be used to represent the key, but may not guarantee uniqueness. KEYCOLS may be used to define the key. Retrieving definition for ta6_pub11.DEPARTMENTS. 2022-06-30 10:31:24 WARNING OGG-06439 No unique key is defined for table DEPARTMENTS. All viable columns will be used to represent the key, but may not guarantee uniqueness. KEYCOLS may be used to define the key. Retrieving definition for ta6_pub11.DEPT. Retrieving definition for ta6_pub11.EMP. Retrieving definition for ta6_pub11.ORDERS. Retrieving definition for ta6_pub11.SALGRADE. 2022-06-30 10:31:25 WARNING OGG-06439 No unique key is defined for table SALGRADE. All viable columns will be used to represent the key, but may not guarantee uniqueness. KEYCOLS may be used to define the key. Retrieving definition for ta6_pub11.USERS. Definitions generated for 7 tables in /home/oracle/ogg19c/dirdef/defgen.def. # 傳送到目標端 scp /home/oracle/ogg19c/dirdef/defgen.def lightdb@10.20.30.199:/home/lightdb/ogg/dirdef
第三章 LightDB端ogg配置
3.1解壓軟體並配置環境變數(目標端)
配置環境變數
# User specific aliases and functions export LD_LIBRARY_PATH=$PGHOME/lib:$PGHOME/lib/ltext:$LD_LIBRARY_PATH export PATH=$PGHOME/bin:$PATH export LIGHTDB_PORT=5435 export PGUSER=lightdb export LIGHTDB_HOST=10.20.30.199 export PGHOME=/data1/customer_do_not_delete/ta/lightdb-x/13.3-22.1/ export PGDATA=/data1/customer_do_not_delete/ta/lightdb-x/13.3-22.1/data/defaultCluster export PATH=${PGHOME}/bin:${PGHOME}/tools/bin:${PGHOME}/tools/sbin:${PATH} export LD_LIBRARY_PATH=${PGHOME}/lib:${PGHOME}/lib/ltext:${PGHOME}/tools/lib64:${LD_LIBRARY_PATH} export GGATE=/home/oracle/ogg export PATH=$PGHOME/bin:$HOME/bin:$GGATE:$PATH export LD_LIBRARY_PATH=$PGHOME/lib:$GGATE/lib:$LD_LIBRARY_PATH export ODBCINI=$GGATE/odbc.ini alias ggsci='rlwrap ggsci'
3.2建立目標端ogg使用者
lightdb@postgres=# create database ogg; CREATE DATABASE lightdb@postgres=# create user ogg superuser password 'ogg'; CREATE ROLE lightdb@postgres=# lightdb@postgres=# lightdb@postgres=# lightdb@postgres=# \c ogg ogg You are now connected to database "ogg" as user "ogg". ogg@ogg=# create schema ogg; CREATE SCHEMA
3.3建立DSN
ogg for postgresql使用的是ODBC來連線資料庫,因此需要指明ODBC dirver
vi /home/lightdb/ogg/odbc.ini [ODBC Data Sources] //定義的資料庫別名,後面的【postgre】部分與之對應 GG_Postgres=DataDirect 22.1 LightDB Wire Protocol [ODBC] IANAAppCodePage=106 //字符集,應該與資料庫的字符集對應,106代表UTF-8 InstallDir=/home/lightdb/ogg //ogg安裝目錄 [GG_Postgres] Driver=/home/lightdb/ogg/lib/GGpsql25.so //OGG安裝包裡有內建ODBC驅動 Description=DataDirect LightDB Wire Protocol //介紹 Database=ta6_pub11 //表空間 HostName=10.20.30.199 //一般是本地地址 PortNumber=5435 //埠 LogonID=ta6_pub11 //資料庫使用者名稱 Password=ta6_pub11 //資料庫密碼
3.4建立GoldenGate工作目錄
cd /home/lightdb/ogg ggsci GGSCI (hs-10-20-30-199) 2> create subdirs Creating subdirectories under current directory /home/lightdb/ogg Parameter file /home/lightdb/ogg/dirprm: created. Report file /home/lightdb/ogg/dirrpt: created. Checkpoint file /home/lightdb/ogg/dirchk: created. Process status files /home/lightdb/ogg/dirpcs: created. SQL script files /home/lightdb/ogg/dirsql: created. Database definitions files /home/lightdb/ogg/dirdef: created. Extract data files /home/lightdb/ogg/dirdat: created. Temporary files /home/lightdb/ogg/dirtmp: created. Credential store files /home/lightdb/ogg/dircrd: created. Master encryption key wallet files /home/lightdb/ogg/dirwlt: created. Dump files /home/lightdb/ogg/dirdmp: created.
3.5配置MGR程式組
# 編輯mgr GGSCI (oracle221) 1>EDIT param mgr # 複製以下內容,儲存(此埠要與源端Pump程式裡配置的對應) PORT 7810 # 啟動mgr GGSCI (hs-10-20-30-199) 4> start mgr GGSCI (hs-10-20-30-199) 5> info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING
3.6新增checkpoint表
為了保證源和目標端在傳資料的時候不會重複或者少傳,在目標端新增checkpoin表
dblogin sourcedb gg_Postgres userid ogg , password ogg add checkpointtable public.checkpointtab
3.7配置replicate程式
# 編輯引數檔案 edit params rep_1 # 複製如下內容,酌情修改引數,儲存 REPLICAT rep_1 SOURCEDEFS /home/lightdb/ogg/dirdef/defgen.def SETENV(PGCLIENTENCODING = "UTF8" ) SETENV(ODBCINI="/home/lightdb/ogg/odbc.ini" ) SETENV(NLS_LANG="AMERICAN_AMERICA.AL32UTF8") TARGETDB GG_Postgres,userid ogg,password ogg DISCARDFILE /home/lightdb/ogg/dirrpt/rep_1.rpt, append MAP ta6_pub11.*, TARGET ta6_pub11.*; # 新增 Replicat 程式 add replicat rep_1,exttrail /home/lightdb/ogg/dirdat/pa,begin now,checkpointtable public.checkpointtab # 啟動 Replicat 程式 GGSCI (lottu02) 1> start REPLICAT rep_1 GGSCI (hs-10-20-30-199) 1> info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING REPLICAT RUNNING REP_1 00:00:00 00:00:07
第四章 資料驗證
源端執行
SQL> delete from TBFUNDCHANGELIMIT; 1379 rows deleted. SQL> commit; Commit complete.
目標端
ta6_pub11@ta6_pub11=# select count(*) from tbfundchangelimit; count ------- 1379 (1 row) ta6_pub11@ta6_pub11=# select count(*) from tbfundchangelimit; count ------- (1 row)
資料初始同步,可以使用ora2pg
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29990276/viewspace-2903813/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- LightDB/Postgres 使用ora2pg遷移Oracle到LightDB/PostgresOracle
- LightDB/PostgreSQL 相容Oracle儲存過程SQLOracle儲存過程
- Oracle/MySQL透過odbc訪問PostgreSQL for LightDBOracleMySql
- 遷移oracle使用者密碼Oracle密碼
- 1.0 ORACLE到MYSQL資料遷移方式選型OracleMySql
- LightDB/postgresql內建特性之訪問oracle之oracle_fdw介紹SQLOracle
- oracle遷移OCR盤Oracle
- Oracle遷移文件大全Oracle
- Oracle遷移文章大全Oracle
- Oracle使用RMAN從Windows遷移資料到LinuxOracleWindowsLinux
- oracle xtts遷移 AIX to LinuxOracleTTSAILinux
- lightdb -- Oracle相容 -- rownumOracle
- LightDB/PostgreSQL等待事件 Lock transactionidSQL事件
- LightDB/PostgreSQL 客戶端部署SQL客戶端
- About the Oracle GoldenGate TrailOracleGoAI
- ORACLE GoldenGate Initial LoadOracleGo
- ORACLE GoldenGate 使用技巧-容錯處理等OracleGo
- Oracle rman duplicate遷移測試Oracle
- AWS RDS Oracle資料遷移Oracle
- oracle 19c pdb遷移Oracle
- LightDB相容掃描 - 事前SQL相容遷移評估工具24.1支援MySQL --> TDSQL-PostgreSQL相容性掃描MySql
- 從 Oracle 到 TiDB,全鏈路資料遷移平臺核心能力和杭州銀行遷移實踐OracleTiDB
- lightdb -- merge into insert 相容 OracleOracle
- 【BUILD_ORACLE】使用Oracle資料泵線上不停機克隆/遷移PDBUIOracle
- LightDB/PostgreSQL 設定LightDB訪問白名單pg_hba.confSQL
- Oracle GoldenGate安裝(一)OracleGo
- Oracle GoldenGate安裝(二)OracleGo
- Oracle GoldenGate安裝(三)OracleGo
- Oracle GoldenGate 18.1釋出OracleGo
- Oracle RAC 遷移替換 OCR 盤Oracle
- 連載一:Oracle遷移文件大全Oracle
- 連載二:Oracle遷移文章大全Oracle
- Oracle到PostgreSQL等價改寫OracleSQL
- PostgreSQL/Lightdb 更改列屬性語法SQL
- Oracle GoldenGate Veridata 12.2.1.4安裝配置使用全手冊OracleGo
- 【XTTS】Oracle XTTS V4--Oracle11.2.0.4+ 遷移升級TTSOracle
- Microsoft SQL Server 遷移利器,Babelfish for Aurora PostgreSQL 上線!ROSSQLServerBabel
- Oracle資料庫(DataGuard)遷移方案(下)Oracle資料庫