配置ogg從Oracle到PostgreSQL的同步複製json數據

標籤:goldengate postgresql oracle jsonhtml

測試環境說明

Oracle:Windows 8.1 + Oracle 12.2.0.1.0 + GoldenGate 12.3.0.1.2 for oracleweb

IP:10.155.4.150sql

PostgreSQL:CentOS7 + postgresql 10.10-1 + Goldengate 12.2.0.1 for PostgreSQL數據庫

IP: 10.155.5.178json

源端

(由於Oracle的數據庫和OGG安裝教程簡單,此處不作介紹)bash

數據庫配置

SQL> sqlplus / as sysdba; oracle

SQL>archive log list;dom

SQL>shutdown immediate;ide

SQL>startup mount;post

SQL>alter database archivelog; //打開歸檔模式

SQL>alter database open;

SQL> alter database force logging; //設置強制記錄日誌

SQL> alter database add supplemental log data; //增長附加日誌

SQL> alter system switch logfile; //切換日誌使附加日誌生效

SQL> select log_mode,supplemental_log_data_min,force_logging from v$database;

LOG_MODE         SUPPLEMENTAL_LOG FORCE_LOGGING

------------------------------------------------------------------------------

ARCHIVELOG         YES                YES

(這樣就配置好了)

SQL> alter system set enable_goldengate_replication=true scope=both;(源端纔有)

SQL> create user oracle identified by oracle; //建立源端被抽取用戶

SQL> grant dba to oracle; //賦權

SQL>conn oracle/oracle;

//建立源表

SQL>CREATE TABLE jsontest

( id VARCHAR2 (32) NOT NULL PRIMARY KEY,

po_document VARCHAR2 (3000)

CONSTRAINT ensure_json CHECK (po_document IS JSON));

OGG配置

進入oggs目錄啓動ggsci (默認port 7809,不用修改)

//登錄同步用戶

GGSCI (localhost) 1> dblogin userid oracle password oracle

//爲同步表添加trandata

add trandata oracle.jsontest

------添加Extract進程

GGSCI (localhost) 2> add extract ex2 integrated tranlog, begin now

GGSCI (localhost) 3> add exttrail ./dirdat/es extract ex2

GGSCI (localhost) 4> edit params ex2

EXTRACT ex2

extract ex2

dynamicresolution

userid oggs,password oggs

exttrail ./dirdat/es format release 12.2 //隊列文件版本須要與目標端一致

table oracle.jsontest2;

------添加Pump進程

GGSCI (localhost) 5> add extract pu2 exttrailsource ./dirdat/es, begin now

GGSCI (localhost) 6> add rmttrail ./dirdat/et extract pu2

GGSCI (localhost) 7> edit params pu2

extract pu2

RMTHOST 10.155.5.178, MGRPORT 7810

RMTTRAIL ./dirdat/et

TABLE oracle.jsontest2;

目標端

數據庫配置

PostgreSQL 安裝教程請參考:http://www.javashuo.com/article/p-xyzokduh-gp.html

建立用於同步的數據庫、用戶和Schema,並建立測試表

postgres=# create database smandar;

postgres=# create user smandar superuser password ‘smandar‘;

postgres=# \c smandar smandar

smandar=# create schema smandar;

CREATE SCHEMA

smandar=# \dn

List of schemas

Name | Owner

---------+---------

public | smandar

smandar | smandar

(2 rows)

smandar=# CREATE TABLE jsontest

smandar-# (

smandar(# id varchar primary key,

smandar(# po_document json

smandar(# );

CREATE TABLE

smandar=# \d

List of relations

Schema | Name | Type | Owner

---------+-----------+-------+---------

smandar | jsontest | table | smandar

(1 rows)

OGG安裝

(如下的全部$表明smandar用戶)

一、解壓安裝:

$ cd /home/smandar/Oracle/Installation_package

$ unzip 122022_ggs_Linux_x64_PostgreSQL_64bit.zip

$ cd ..

$ mkdir ogg

$ mv Installation_package /ggs_Linux_x64_PostgreSQL_64bit.tar ogg/

$ tar vxf ggs_Linux_x64_PostgreSQL_64bit.tar

Odbc配置

投遞到postgresql須要使用odbc方式

配置odbc數據源,goldengate 使用ODBC鏈接Postgres Database

$ cd /home/smandar/Oracle /ogg

$ vi odbc.ini

----------------------------------------------------

[ODBC Data Sources]

GG_Postgres=DataDirect 10.10 PostgreSQL Wire Protocol

[ODBC]

IANAAppCodePage=106

InstallDir=/home/smandar/Oracle/ogg

[GG_Postgres]

Driver=/home/smandar/Oracle/ogg/lib/GGpsql25.so

Description=DataDirect 10.10 PostgreSQL Wire Protocol

Database=smandar

HostName=127.0.0.1

PortNumber=5432

LogonID=smandar

Password=smandar

--------------------------------------------------

[ODBC Data Sources]裏邊配置該ODBC的別名,本文件中也就是GG_Postgres 後邊的配置文件中的targetdb須要與這個對應

[ODBC]:

IANAAppCodePage指的是字符集的設置 這裏的106值得是UTF8,若是是4則爲ISO-8859-1,注意這個應該始終和postgres的字符集設置相同,不一樣字符集對應的值見附件。

InstallDir對應ogg的安裝目錄

[GG_Postgres]:這裏的名稱對應的是上邊ODBC的別名

Driver這裏指向的是ogg安裝目錄下的lib/GGpsql25.so

Description是描述

Database填寫數據庫名稱

HostName填寫本機的hostname,能夠解析的便可。

PosrNumber是postgres的監聽端口。

LogonID填寫postgres的用戶名

password填寫postgres的密碼

配置環境變量

三、修改環境變量 vi ~/.bashrc

export LD_LIBRARY_PATH=/home/smandar/Oracle/ogg/lib:$LD_LIBRARY_PATH

export PATH=$PATH:/home/smandar/Oracle/ogg

export ODBCINI=/home/smandar/Oracle/ogg/odbc.ini

配置OGG參數

$ cd /home/smandar/Oracle /ogg

$ ./ggsci

------建立子目錄:

GGSCI (localhost.localdomain) 1>create subdirs

------配置mgr端口(與源端端口不能相同)

GGSCI (localhost.localdomain) 2> edit param mgr

PORT 7810

------配置replicat進程

GGSCI (localhost.localdomain) 3> dblogin sourcedb gg_postgres userid smandar

Password: //輸入密碼

GGSCI (localhost.localdomain) 4>add add replicat re2, exttrail ./dirdat/et,nodbcheckpoint

GGSCI (localhost.localdomain) 5>edit param re2

REPLICAT re2

targetdb GG_Postgres, USERID smandar, PASSWORD smandar

ASSUMETARGETDEFS

MAP oracle.jsontest2, target smandar.jsontest2;

啓動測試

啓動源端的mgr進程、ex2進程、pu2進程

clip_image002

啓動目標端的mgr,re2進程

clip_image004

源端原始數據

clip_image005

目標端原始數據:

clip_image007

源端插入數據:

SQL>INSERT INTO jsontest2

VALUES ('001',

'{"PONumber" : 1600,

"Reference" : "ABULL-20140421",

"Requestor" : "Alexis Bull",

"User" : "ABULL"}');

SQL>commit;

clip_image008

目標端查詢數據:

clip_image010

對json數據進行查詢

clip_image011

clip_image013

小結

    能夠看到,使用OGG,除了標準的數據類型同步外,還能夠將oracle db中的json實時同步到 postgresql db中。

相關文章
相關標籤/搜索