Oracle CDC配置案例
异步部署
1. 环境的配置准备
1.1. 数据库版本
SQL> select * from v$version;
BANNER
-----------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1. - Production
PL/SQL Release 11.2.0.1. - Production
CORE 11.2.0.1. Production
TNS for Linux: Version 11.2.0.1. - Production
NLSRTL Version 11.2.0.1. - Production
1.2. 配置数据库参数
SQL> show parameter job_que
NAME TYPE VALUE
----------------------------------------------- job_queue_processes integer SQL> show parameter streams_pool_size
NAME TYPE VALUE
-----------------------------------------------
streams_pool_size big integer SQL> show parameter sga_targ
NAME TYPE VALUE
-----------------------------------------------
sga_target big integer SQL> show parameter memory_targ
NAME TYPE VALUE
----------------------------------------------
memory_target big integer 472M SQL> show parameter java_pool
NAME TYPE VALUE
------------------------------------ -----------
java_pool_size big integer
SQL> alter system set streams_pool_size=50m ; System altered. SQL> show parameter java_pool NAME TYPE VALUE
------------------------------------ -----------
java_pool_size big integer
SQL> alter system set java_pool_size=50m; System altered. SQL> show parameter undo_ret NAME TYPE VALUE
------------------------------------ -----------
undo_retention integer
SQL> alter system set undo_retention=; System altered.
SQL> show parameter streams_pool
NAME TYPE VALUE
------------------------------------ -----------
streams_pool_size big integer 52M SQL> show parameter java_pool
NAME TYPE VALUE
------------------------------------ -----------
java_pool_size big integer 52M SQL> show parameter undo_re
NAME TYPE VALUE
------------------------------------ -----------
undo_retention integer
1.3. 开启归档及补充日志
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u02/archivelog_dest
Oldest online log sequence
Next log sequence to archive
Current log sequence
SQL> alter database force logging; Database altered. SQL> alter database add supplemental log data; Database altered. SQL> select LOG_MODE,FORCE_LOGGING,SUPPLEMENTAL_LOG_DATA_MIN
from v$database; LOG_MODE FOR SUPPLEME
------------ --- --------
ARCHIVELOG YES YES
1.4. 准备测试的表
SQL> conn scott/tiger
Connected.
SQL> create table test(id int,name varchar2(),mark varchar2()); Table created. SQL> select * from tab; TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
BONUS TABLE
DEPT TABLE
EMP TABLE
GTT TABLE
SALGRADE TABLE
TEMP TABLE
TEST TABLE rows selected.
2. 创建发布者和订阅者
2.1. 创建发布者/授权
SQL> create tablespace cdc_tbsp
datafile '/u02/app/oradata/ORCL/cdc_tbsp01.dbf' size 200m; Tablespace created. SQL> create user cdc_publisher identified by cdc_publisher
default tablespace cdc_tbsp temporary tablespace temp; User created.
SQL> grant create session TO cdc_publisher; Grant succeeded. SQL> grant create table TO cdc_publisher; Grant succeeded. SQL> grant create sequence TO cdc_publisher; Grant succeeded. SQL> grant create procedure TO cdc_publisher; Grant succeeded. SQL> grant create any job TO cdc_publisher; Grant succeeded. SQL> grant execute_catalog_role TO cdc_publisher; Grant succeeded. SQL> grant select_catalog_role TO cdc_publisher; Grant succeeded. SQL> grant execute ON dbms_cdc_publish TO cdc_publisher; Grant succeeded. SQL> grant execute ON dbms_lock TO cdc_publisher; Grant succeeded. SQL> GRANT UNLIMITED TABLESPACE TO cdc_publisher; Grant succeeded. SQL> execute dbms_streams_auth.grant_admin_privilege('CDC_PUBLISHER'); PL/SQL procedure successfully completed. SQL> grant all on scott.test to cdc_publisher; Grant succeeded.
2.2. 创建订阅者/授权
SQL> create user cdc_subscriber identified by cdc_subscriber
default tablespace cdc_tbsp temporary tablespace temp; User created.
SQL> grant create session TO cdc_subscriber; Grant succeeded.
3. 发布/订阅具体数据
3.1. 发布:准备源表(Source Table)
SQL> conn cdc_publisher/cdc_publisher
Connected.
SQL> BEGIN
DBMS_CAPTURE_ADM.PREPARE_TABLE_INSTANTIATION(
TABLE_NAME => 'scott.test');
END;
/ PL/SQL procedure successfully completed.
3.2. 发布:创建变更集(Data Set)
SQL> conn cdc_publisher/cdc_publisher
Connected.
SQL> BEGIN
DBMS_CDC_PUBLISH.CREATE_CHANGE_SET(
change_set_name => 'CDC_SCOTT_TEST',
description => 'Change set for product info',
change_source_name => 'HOTLOG_SOURCE',
stop_on_ddl => 'y',
begin_date => sysdate,
end_date => sysdate+);
END;
/ PL/SQL procedure successfully completed.
3.3. 发布:创建变更表
SQL> BEGIN
DBMS_CDC_PUBLISH.CREATE_CHANGE_TABLE(
owner => 'cdc_publisher',
change_table_name => 'cdc_test',
change_set_name => 'CDC_SCOTT_TEST',
source_schema => 'SCOTT',
source_table => 'TEST',
column_type_list => 'ID NUMBER(5), NAME VARCHAR2(30),MARK VARCHAR2(50)',
capture_values => 'both',
rs_id => 'y',
row_id => 'n',
user_id => 'n',
timestamp => 'n',
object_id => 'n',
source_colmap => 'n',
target_colmap => 'y',
options_string => 'TABLESPACE CDC_TBSP');
END;
/ PL/SQL procedure successfully completed.
3.4. 发布:激活变更集
SQL> BEGIN
DBMS_CDC_PUBLISH.ALTER_CHANGE_SET(
change_set_name => 'CDC_SCOTT_TEST',
enable_capture => 'y');
END;
/ PL/SQL procedure successfully completed.
SQL> grant select on cdc_test to cdc_subscriber; Grant succeeded.
备注:其实到此cdc_subscriber用户已经可以检测到scott.test表的变更了
如下测试:
[oracle@std ~]$ sqlplus scott/tiger SQL*Plus: Release 11.2.0.1. Production on Wed Jan :: Copyright (c) , , Oracle. All rights reserved. Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1. - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> insert into test values(,'beijing',''); row created. SQL> commit; Commit complete. SQL> update test set name='shanghai' where id=; row updated. SQL> commit; Commit complete. SQL> delete test where id=; row deleted. SQL> commit; Commit complete.
SQL> conn cdc_subscriber/cdc_subscriber
Connected.
SQL> select t.operation$,t.commit_timestamp$,t.id,t.name,t.mark
from cdc_publisher.cdc_test t; OP COMMIT_TIMESTAMP$ ID NAME MARK
-- ------------------ ---------- ------------------------------
I -JAN- beijing
UO -JAN- beijing
UN -JAN- shanghai
D -JAN- shanghai
3.5. 订阅:创建订阅集
SQL> conn cdc_subscriber/cdc_subscriber
Connected.
SQL> BEGIN
dbms_cdc_subscribe.create_subscription(
change_set_name=>'CDC_SCOTT_TEST',
description=>'cdc scott subx',
subscription_name=>'CDC_SCOTT_SUB');
END;
/ PL/SQL procedure successfully completed.
3.6. 订阅:开始订阅表信息
SQL> BEGIN
dbms_cdc_subscribe.subscribe(
subscription_name=>'CDC_SCOTT_SUB',
source_schema=>'SCOTT',
source_table=>'TEST',
column_list=>'ID, NAME,MARK',
subscriber_view=>'TEST_TEMP');
END;
/ PL/SQL procedure successfully completed.
SQL> select * from tab; TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
TEST_TEMP VIEW
3.7. 订阅:激活订阅
SQL> BEGIN
dbms_cdc_subscribe.activate_subscription(
subscription_name=>'CDC_SCOTT_SUB');
END;
/ PL/SQL procedure successfully completed.
3.8. 订阅:扩展订阅窗口
SQL> conn cdc_subscriber/cdc_subscriber
Connected.
SQL> BEGIN
dbms_cdc_subscribe.extend_window(
subscription_name=>'CDC_SCOTT_SUB');
END;
/ PL/SQL procedure successfully completed.
SQL> conn cdc_subscriber/cdc_subscriber
Connected.
SQL> select t.operation$,t.commit_timestamp$,t.id,t.name,t.mark
from test_temp t; OP COMMIT_TIMESTAMP$ ID NAME MARK
-- ------------------ ---------- ------------------------------
I -JAN- beijing
UO -JAN- beijing
UN -JAN- shanghai
D -JAN- shanghai
4. 测试订阅发布
4.1. SCOTT表更改
SQL> conn scott/tiger
Connected.
SQL> insert into test values(,'renqinglei','aa'); row created. SQL> commit; Commit complete. SQL> update test set mark='tt' where id=; row updated. SQL> commit; Commit complete. SQL> delete test where id=; row deleted. SQL> commit; Commit complete.
4.2. 查询数据发布情况
SQL> conn cdc_publisher/cdc_publisher
Connected.
SQL> select t.operation$,t.commit_timestamp$,t.id,t.name,t.mark
from cdc_publisher.cdc_test t; OP COMMIT_TIMESTAMP$ ID NAME MARK
-- ------------------ ---------- ------------------------------
I -JAN- beijing
UO -JAN- beijing
UN -JAN- shanghai
D -JAN- shanghai
I -JAN- renqinglei aa
UO -JAN- renqinglei aa
UN -JAN- renqinglei tt
D -JAN- renqinglei tt rows selected.
4.3. 查询数据订阅情况
SQL> conn cdc_subscriber/cdc_subscriber
Connected.
SQL> select t.operation$,t.commit_timestamp$,t.id,t.name,t.mark
from test_temp t; OP COMMIT_TIMESTAMP$ ID NAME MARK
-- ------------------ ---------- ------------------------------
I -JAN- beijing
UO -JAN- beijing
UN -JAN- shanghai
D -JAN- shanghai
发现订阅的数据没有变化,扩展一下订阅窗口:
SQL> conn cdc_subscriber/cdc_subscriber
Connected.
SQL> BEGIN
dbms_cdc_subscribe.extend_window(
subscription_name=>'CDC_SCOTT_SUB');
END;
/ PL/SQL procedure successfully completed. SQL> select t.operation$,t.commit_timestamp$,t.id,t.name,t.mark
from test_temp t; OP COMMIT_TIMESTAMP$ ID NAME MARK
-- ------------------ ---------- ------------------------------
I -JAN- beijing
UO -JAN- beijing
UN -JAN- shanghai
D -JAN- shanghai
I -JAN- renqinglei aa
UO -JAN- renqinglei aa
UN -JAN- renqinglei tt
D -JAN- renqinglei tt rows selected.
4.4. 清除变更数据集
SQL> conn cdc_subscriber/cdc_subscriber
Connected.
SQL> BEGIN
DBMS_CDC_SUBSCRIBE.PURGE_WINDOW(
subscription_name => 'CDC_SCOTT_SUB');
END;
/ PL/SQL procedure successfully completed. SQL> select t.operation$,t.commit_timestamp$,t.id,t.name,t.mark
from test_temp t; no rows selected
4.5. 重新生成变化数据
SQL> conn scott/tiger
Connected.
SQL> insert into test values(,'shandong','hh'); row created. SQL> insert into test values(,'diankeyuan','hh'); row created. SQL> commit; Commit complete.
SQL> conn cdc_publisher/cdc_publisher
Connected.
SQL> select t.operation$,t.commit_timestamp$,t.id,t.name,t.mark
from cdc_publisher.cdc_test t; OP COMMIT_TIMESTAMP$ ID NAME MARK
-- ------------------ ---------- ------------------------------
I -JAN- beijing
UO -JAN- beijing
UN -JAN- shanghai
D -JAN- shanghai
I -JAN- renqinglei aa
UO -JAN- renqinglei aa
UN -JAN- renqinglei tt
D -JAN- renqinglei tt
I -JAN- shandong hh
I -JAN- diankeyuan hh rows selected.
SQL> conn cdc_subscriber/cdc_subscriber
Connected.
SQL> BEGIN
dbms_cdc_subscribe.extend_window(
subscription_name=>'CDC_SCOTT_SUB');
END;
/ PL/SQL procedure successfully completed. SQL> select t.operation$,t.commit_timestamp$,t.id,t.name,t.mark
from test_temp t; OP COMMIT_TIMESTAMP$ ID NAME MARK
-- ------------------ ---------- ------------------------------
I -JAN- shandong hh
I -JAN- diankeyuan hh
4.6. 删除发布的数据
SQL> conn cdc_publisher/cdc_publisher
Connected.
SQL> select t.operation$,t.commit_timestamp$,t.id,t.name,t.mark
from cdc_publisher.cdc_test t; OP COMMIT_TIMESTAMP$ ID NAME MARK
-- ------------------ ---------- ------------------------------
I -JAN- beijing
UO -JAN- beijing
UN -JAN- shanghai
D -JAN- shanghai
I -JAN- renqinglei aa
UO -JAN- renqinglei aa
UN -JAN- renqinglei tt
D -JAN- renqinglei tt
I -JAN- shandong hh
I -JAN- diankeyuan hh rows selected. SQL> truncate cdc_test;
truncate cdc_test
*
ERROR at line :
ORA-: Invalid truncate command - missing CLUSTER or TABLE keyword SQL> delete cdc_test; rows deleted. SQL> commit; Commit complete. SQL> select t.operation$,t.commit_timestamp$,t.id,t.name,t.mark
from cdc_publisher.cdc_test t; no rows selected
Oracle CDC配置案例的更多相关文章
- Oracle CDC简介及异步在线日志CDC部署示例
摘要 最近由于工作需要,花时间研究了一下Oracle CDC功能和LogMiner工具,希望能找到一种稳定.高效的技术来实现Oracle增量数据抽取功能.以下是个人的部分学习总结和部署实践. 1. O ...
- 使用mysql存放Ambari元数据的配置案例
使用mysql存放Ambari元数据的配置案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.环境准备 详情请参考我之前的笔记:离线方式部署Ambari2.6.0.0 中关 ...
- oracle odbc配置
oracle odbc配置 Win7 64位 下安装oracle odbc 不能使用控制面板中 “管理工具”->“数据源(OBDC)”中安装数据源. 而要在“ 运行” 中输入 C:\Windo ...
- SDE+ORACLE优化配置
原文 SDE+ORACLE优化配置 SDE的性能取决于: 首先操作系统的性能:其次是Oracle的性能,再次是SDE的性能. 第一:操作系统,无非是内存.CPU.带宽等. 可以有待提高的地方:第一.硬 ...
- ThinkPHP pdo连接Oracle的配置写法,提示报错
'DB_TYPE' => 'pdo', // 数据库类型 'DB_USER' => 'user101', // username 'DB_PWD' => 'zb~!@#$%', // ...
- Oracle数据库配置方式二--使用Net Manager配置数据库
在Oracle安装配置中使用Net Configuration配置了数据库,今天给大家介绍第二种配置方式,Net Manager配置. 先找到我们的Net Manager的快捷方式,如下面截图
- Oracle 客户端配置笔记
1.右击桌面的我的电脑 -> 高级 -> 环境变量,新建 1) 变量名:ORACLE_HOME 变量值:D:\app\instantclient_11_2 2) 变量名:TNS_ADMIN ...
- Oracle安装配置流程
Oracle安装流程 第一次自己动手安装oracle,之前对oracle安装配置一窍不通,最后最终弄好.总结下. 1. 安装oracle10gserver端 2. 安装oracle10gclien ...
- Nginx插件之openresty反向代理和日志滚动配置案例
Nginx插件之openresty反向代理和日志滚动配置案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.openresty介绍 1>.Nginx介绍 Nginx是一款 ...
随机推荐
- ecshop不同文章分类调用不同文章分类模板
根据需要,不同的文章分类会有不一样的页面风格.也就是说根据文章分类ID来判断,输出不同的文章分类模板. 重点就是文章分类的ID. 打开:article_cat.php $smarty->disp ...
- WinForm BaseClass类常用通用方法
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- Web应用性能优化思路
瓶颈是什么? 一条4车道的公路,运行非常顺畅,突然出了点事故,事故车导致某个地方只剩下1车道,然后就开始堵车,因为四辆车同时塞向一个车道里.把这个事故清除了,故障车拖走了,道路会开始恢复了通畅. 这个 ...
- Hamilton四元数群的表示
Hamilton四元数群$Q_8=\mathbb H=\{\pm e,\pm i,\pm j,\pm k\}$满足如下运算法则: $e$为单位元且同号得正.异号得负,此外$e=i^2=j^2=k^2, ...
- java.io.EOFException
错误代码如下: 严重: IOException while loading persisted sessions: java.io.EOFException java.io.EOFException ...
- 小白请教几个关于Java虚拟机内存分配策略的问题
最近在看周志明所著的<深入理解Java虚拟机>,有几个问题不太明白,希望对虚拟机有研究的哥们儿帮我解答一下.先说一下我进行试验的环境: 操作系统:Mac OS X 10.11.6 EI C ...
- (4)WebApi 跨域问题
在做Web开发中,常常会遇到跨域的问题,到目前为止,已经有非常多的跨域解决方案. 通过自己的研究以及在网上看了一些大神的博客,写了一个Demo 首先新建一个webapi的程序,如下图所示: 由于微软已 ...
- 使用Docker搭建Java Web运行环境
这周末体验了一下挺火的Docker技术,记录学习笔记. >Docker是干什么的 Docker 是一个基于Linux容器(LXC-linux container)的高级容器引擎,基于go语言开发 ...
- 剑指Offer-【面试题04:替换空格】
package com.cxz.question4; /* * 请实现一个函数,把字符串中的每个空格替换成"%20",例如"We are happy.",则输出 ...
- PHP扩展安装mcrypt 提示没有可用包(No package php-mcrypt available)
一.用CentOS的朋友基本在安装软件的时候默认都会想到用yum安装省事省时而且不会有错不需要担心依赖问题. php大部分的扩展都是可以再yum源里安装的,但是部分扩展是没有的,需要安装epel-re ...