OGG For Oracle To PostgreSQL

  本文檔描述OGG(Oracle goldengate)爲Oracle同步到PostgreSQL數據庫配置。在目前去「IOE」潮流。PostgreSQL確實是Oracle最好的替代品之一。html

實驗環境以下:sql

 1、軟件下載

下載OGG軟件地址數據庫

 2、數據庫配置

2.一、源端(Oracle)

2.1.一、建立 GoldenGate 操做系統用戶

專門用ogg用戶來維護操做GoldenGate。oracle

useradd ogg
passwd ogg

2.1.二、建立 GoldenGate 安裝目錄

mkdir -p /data/ogg
chown -R ogg:ogg /data/ogg

2.1.三、安裝 GoldenGate

unzip fbo_ggs_Linux_x64_ora11g_64bit.tar.zip
tar -xvf fbo_ggs_Linux_x64_ora11g_64bit.tar -C /data/ogg

2.1.四、配置 GoldenGate環境變量

export GGATE=/data/ogg
export ORACLE_BASE=/u01/app
export ORACLE_HOME=$ORACLE_BASE/oracle
export PATH=$PATH:$GGATE:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$GGATE:$LD_LIBRARY_PATH
alias sqlplus='rlwrap sqlplus'
alias ggsci='rlwrap ggsci'

2.1.五、配置Oracle數據庫

  因爲 GoldenGate 的原理是根據 Oracle 的日誌進行抽取複製。爲了保證日誌的完整性;須要打開 Oracle 數據庫歸檔;app

SQL> alter system set log_archive_dest_1 = 'LOCATION=/data/arch' scope = spfile;
SQL> shutdown immediate;
SQL> startup mount
SQL> alter database archivelog;
SQL> alter database open;
# 查看歸檔模式 SQL
> archive log list
# 還須要開啓 force log 和 supplemental log SQL
> alter database force logging; SQL> 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

2.1.六、oracle建立複製用戶ogg

# 建議使用單獨的表空間存放 GoldenGate 數據
create tablespace tsp_ogg datafile '/data/oracle/data/ogg01.dbf' size 512M autoextend on;
# 建立 GoldenGate 用戶並賦權
create user ogg identified by ogg default tablespace tsp_ogg;
grant dba to 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;

2.二、目標端(PostgreSQL)

2.2.一、建立 GoldenGate 操做系統用戶

  專門用ogg用戶來維護操做GoldenGate。ide

useradd ogg
passwd ogg

2.2.二、建立 GoldenGate 安裝目錄

mkdir -p /data/ogg
chown -R ogg:ogg /data/ogg

2.2.三、安裝 GoldenGate

unzip 122022_ggs_Linux_x64_PostgreSQL_64bit.zip 
tar -xvf ggs_Linux_x64_PostgreSQL_64bit.tar -C /data/ogg

2.2.四、配置 GoldenGate環境變量

export GGATE=/data/ogg
export PGHOME=/opt/pgsql10
export PGDATA=/data/postgres/data1                
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'

2.2.五、建立複製用戶ogg

create user ogg superuser identified by ogg;
\c lottu ogg
create schema ogg;

2.2.六、建立DSN

  生成odbc.ini文件post

[ODBC Data Sources]  
GG_Postgres=DataDirect 10 PostgreSQL Wire Protocol  
[ODBC]  
IANAAppCodePage=106
InstallDir=/data/ogg
[GG_Postgres] 
Driver=/data/ogg/lib/GGpsql25.so
Description=DataDirect 10 PostgreSQL Wire Protocol
Database=lottu
HostName=localhost
PortNumber=5432  
LogonID=ogg
Password=ogg

3、GoldenGate進程配置

3.一、源端(Oracle)

3.1.一、建立 GoldenGate 的工做目錄 

執行ggsci,登陸GoldenGate,只須要執行create subdirs命令就能夠了。測試

GGSCI (oracle221) 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

3.1.二、配置 MGR 進程組

  負責啓動GoldenGate進程,以及啓動動態進程,管理trail文件,錯誤信息。運行ggsci程序;輸入 「EDIT PARAMS MGR」 編輯參數文件:spa

GGSCI (oracle221) 2> edit params mgr

PORT 7809
DYNAMICPORTLIST 7800-8000
AUTOSTART ER *
AUTORESTART EXTRACT *,WAITMINUTES 2, RESETMINUTES 5
PURGEOLDEXTRACTS /data/ogg/dirdat/*,USECHECKPOINTS,MINKEEPDAYS 3
LAGREPORTHOURS 1
LAGINFOMINUTES 30
LAGCRITICALMINUTES 45
SYSLOG ERROR,WARN

GGSCI (oracle221) 3> start mgr
Manager started.

GGSCI (oracle221) 4> info all
Program     Status      Group       Lag at Chkpt  Time Since Chkpt
MANAGER     RUNNING 
  • PORT:指定服務監聽端口;默認端口爲7809
  • DYNAMICPORTLIST:動態端口:能夠制定最大256個可用端口的動態列表,當指定的端口不可用時,管理進程將會從列表中選擇一個可用的端口,源端和目標段的Collector、Replicat、GGSCI進程通訊也會使用這些端口
  • AUTORESTART:自動重啓參數設置:本處設置表示每2分鐘嘗試從新啓動全部EXTRACT進程;之後5分鐘清零。
  • PURGEOLDEXTRACTS:按期清理trail文件設置:本處設置表示對於超過3天的trail文件進行刪除

3.1.三、配置 Extract 進程

  負責抓取須要傳輸數據;下面在源端配置抽取進程。操作系統

GGSCI (oracle221) 5> edit params EORA_1
EXTRACT EORA_1
SETENV (NLS_LANG=AMERICAN_AMERICA.UTF8)
SETENV (ORACLE_HOME="/u01/app/oracle")
SETENV (ORACLE_SID="ora221")
USERID ogg, PASSWORD ogg
DISCARDFILE /data/ogg/dirrpt/EORA_1.dsc,APPEND,MEGABYTES 1024
EXTTRAIL /data/ogg/dirdat/aa 
TABLE lottu.*;

# 在源端用 add extract 命令建立 extract 組;
GGSCI (oracle221) 6> ADD EXTRACT EORA_1, TRANLOG, BEGIN NOW
EXTRACT added.

# 用add exttrail 命令建立本地 trail 文件
GGSCI (oracle221) 7> ADD EXTTRAIL /data/ogg/dirdat/aa, EXTRACT EORA_1, MEGABYTES 5
EXTTRAIL added.

# 啓動extract進程
GGSCI (oracle221) 8> start extract eora_1
Sending START request to MANAGER ...
EXTRACT EORA_1 starting

GGSCI (oracle221) 9> info all
Program     Status      Group       Lag at Chkpt  Time Since Chkpt
MANAGER     RUNNING                                           
EXTRACT     RUNNING     EORA_1      00:00:33      00:00:0

3.1.四、配置 Pump 進程

  extract進程負責將抓取的數據寫入本地trail文件;而須要Pump進程把trail文件傳輸到目標端。使用 EDIT PARAMS PORA_1 添加配置文件

GGSCI (oracle221) 10> EDIT PARAMS PORA_1
EXTRACT PORA_1
SETENV (NLS_LANG=AMERICAN_AMERICA.UTF8)
PASSTHRU
RMTHOST 192.168.1.235, MGRPORT 7809
RMTTRAIL /data/ogg/dirdat/pa
TABLE lottu.*;

# 用 add extract 指定本地 trail 文件
ADD EXTRACT PORA_1, EXTTRAILSOURCE /data/ogg/dirdat/aa

# 用 add rmttrail 指定遠程 trail 文件
ADD RMTTRAIL /data/ogg/dirdat/pa, EXTRACT PORA_1, MEGABYTES 5

# 啓動Pump 進程
START EXTRACT PORA

3.1.五、生成define文件

  在異構的同步複製;須要生成define文件。用於數據兼容不一樣數據庫。

# 1. 進入ggsci命令行
GGSCI (oracle221) 16> edit params defgen
defsfile ./dirdef/defgen.def
userid ogg, password ogg
TABLE lottu.*;

GGSCI (oracle221) 17> exit
# 退出ggsci命令;生成文件 defgen paramfile .
/dirprm/defgen.prm
# 並傳送到目標端 scp
/data/ogg/dirdef/defgen_postgres.prm ogg@192.168.1.235:/data/ogg/dirdef

3.二、目標端(PostgreSQL)

3.2.一、建立GoldenGate的工做目錄

create subdirs

3.2.二、配置MGR進程組

# 編輯mgr
edit param mgr
PORT 7809
# 啓動mgr start mgr

3.2.三、添加checkpiont表

爲了保證源和目標端在傳數據的時候不會重複或者少傳,在目標端添加checkpoin表

dblogin sourcedb GG_Postgres userid ogg
add checkpointtable ogg.checkpointtab

3.2.四、配置Replicat 進程

# 配置rora_1進程
GGSCI (lottu02) 1> EDIT PARAMS RORA_1

REPLICAT RORA_1
SOURCEDEFS /data/ogg/dirdef/defgen.def
SETENV(PGCLIENTENCODING = "UTF8" )
SETENV(ODBCINI="/data/ogg/odbc.ini" )
SETENV(NLS_LANG="AMERICAN_AMERICA.AL32UTF8")
TARGETDB GG_Postgres,userid ogg,password ogg
DISCARDFILE /data/ogg/dirrpt/RORA_aa.rpt, append
MAP lottu.*, TARGET lottu.*;

# 在目標端使用 add replicat 添加 Replicat 進程
add replicat RORA_1,exttrail /data/ogg/dirdat/pa,begin now,checkpointtable ogg.checkpointtab

# 使用 start replicat 啓動 Replicat 進程
start REPLICAT ROR

4、驗證同步

4.一、查看GoldenGate進程狀態

# 源端
GGSCI (oracle221) 1> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt
MANAGER     RUNNING                                           
EXTRACT     RUNNING     EORA_1      00:00:00      00:00:02    
EXTRACT     RUNNING     PORA_1      00:00:00      00:00:09    

# 目標端
GGSCI (lottu02) 2> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt
MANAGER     RUNNING                                           
REPLICAT    RUNNING     RORA_1      00:00:00      00:00:03  

4.二、測試同步

# oracle
insert into tbl_lottu values (1001,'lottu');
# PostgreSQL
lottu=> select * from tbl_lottu;
  id  | name  
------+-------
 1001 | lottu

5、FAQ

在目標端啓動mgr進程;出現啓動失敗;日誌以下

2019-09-04 14:10:39  INFO    OGG-00987  Oracle GoldenGate Command Interpreter:  GGSCI command (postgres): start mgr.
2019-09-04 14:10:40  ERROR   OGG-06551  Oracle GoldenGate Manager, mgr.prm:  Could not translate host name lottu02 into an Internet address.
2019-09-04 14:10:40  ERROR   OGG-01668  Oracle GoldenGate Manager, mgr.prm:  PROCESS ABENDING.

解決方案配置/etc/hosts

相關文章
相關標籤/搜索