主库为Oracle 11g数据库,针对需要同步的表建立增量数据临时表以及反向并通过水壶定时同步到PostgreSQL数据库
。1,主库创建快照表和快照
注意:快照表结构和源表结构必须一致!
--创建插入快照表
CREATE TABLE SPWUSER.WEB_CUSTOMER_INSERT_TMP
(ID NUMBER NOT NULL,NAME VARCHAR2(128 BYTE) NOT NULL,CREATED TIMESTAMP(6) WITH LOCAL TIME ZONE DEFAULT (current_timestamp) NOT NULL,MODIFIED TIMESTAMP(6) WITH LOCAL TIME ZONE DEFAULT (current_timestamp) NOT NULL
);
--创建更新快照表
CREATE TABLE SPWUSER.WEB_CUSTOMER_UPDATE_TMP
(ID NUMBER NOT NULL,NAME VARCHAR2(128 BYTE) NOT NULL,CREATED TIMESTAMP(6) WITH LOCAL TIME ZONE DEFAULT (current_timestamp) NOT NULL,MODIFIED TIMESTAMP(6) WITH LOCAL TIME ZONE DEFAULT (current_timestamp) NOT NULL
);
--创建删除快照表
CREATE TABLE SPWUSER.WEB_CUSTOMER_DELETE_TMP
(ID NUMBER NOT NULL,NAME VARCHAR2(128 BYTE) NOT NULL,CREATED TIMESTAMP(6) WITH LOCAL TIME ZONE DEFAULT (current_timestamp) NOT NULL,MODIFIED TIMESTAMP(6) WITH LOCAL TIME ZONE DEFAULT (current_timestamp) NOT NULL
);
--创建插入触发器
CREATE OR REPLACE TRIGGER SPWUSER.WEB_CUSTOMER_INSERT_TRIAFTER INSERTON SPWUSER.WEB_CUSTOMERFOR EACH ROW
BEGININSERT INTO WEB_CUSTOMER_INSERT_TMP (ID,NAME,CREATED,MODIFIED)VALUES (:new.id,:new.name,:new.created,:new.modified);
END;
/
--创建删除触发器
CREATE OR REPLACE TRIGGER SPWUSER.WEB_CUSTOMER_DELETE_TRIAFTER DELETEON SPWUSER.WEB_CUSTOMERFOR EACH ROW
BEGININSERT INTO WEB_CUSTOMER_DELETE_TMP (ID,NAME,CREATED,MODIFIED)VALUES (:old.ID,:old.NAME,:old.created,:old.modified);
END;
/
--创建更新触发器
CREATE OR REPLACE TRIGGER SPWUSER.WEB_CUSTOMER_UPDATE_TRIAFTER UPDATEON SPWUSER.WEB_CUSTOMERFOR EACH ROW
BEGININSERT INTO WEB_CUSTOMER_UPDATE_TMP (ID,NAME,CREATED,MODIFIED)VALUES (:old.ID,:old.NAME,:old.created,:old.modified);
END;
/
2,创建一个针对表增删改改的转换
从kettle菜单中依次选择“文件”->“新建”->“转换”或按ctrl + N快捷键创建。然后依次选择“输入”->“表输入”,“输出”->“插入/更新”和“输出”->“删除”,执行三次,如下图所示:
3,“表输入”控件,查询主库(Oracle)的快照表
4,“插入/更新”控件,插入数据到从库(PostgreSQL)的表,查询的关键字要求唯一
5,“删除”控件,将主库的快照表中的数据删除
6,新建“作业”控件
新建作业控件,将三个转换引用起来,总览如下图所示:
插入转换:
更新转换:
删除转换:
发送邮件: