Oracle9i Change Data Capture Oracle9i Change Data Capture Oracle9i Change Data Capture Oracle9i Change Data Capture
Oracle9i Change Data Capture Oracle9i Change Data Capture Oracle9i Change Data Capture Oracle9i Change Data Capture
Oracle9i Change Data Capture Oracle9i Change Data Capture Oracle9i Change Data Capture Oracle9i Change Data Capture
arcplan
ICI At OracleWorld
Dan White - Oracle 9i Change data Capture- A technical Overview
Monday Nov 11, 2002 1:00pm 2:00pm
Agenda
What is Change Data Capture? Traditional Data Capture Methods. CDC Architecture. Functional Overview of the DBMS_CDC packages. CDC Publish Methods. CDC Subscribe Methods. Conclusions.
Triggers
Introduce a point of failure Have to maintain multiple objects on other systems
Triggers Capture Tables Database Links. Custom code
You have to extract very large amounts of data every time. Very complex compare code
CDC Architecture
CDC Architecture
Source System
Source Databases Redo Logs PDML triggers Change Tables Subscription Views
Functional Overview
Yes
No
drop subscription
DBA
Typically uses the DBMS_CDC_PUBLISH package Creates change tables Maintains change tables
Using alter change table **Note** The change table is a physical object so it must be maintained by the DBA or development staff
ETL developers
Uses DBMS_CDC_SUBSCRIBE Sets up and maintains subscriptions Sets up and maintains subscription views Maintains the subscription windows
Innovative Consulting, Inc., 2001
DBMS_CDC_PUBLISH
Methods
DBMS_CDC_PUBLISH
Create_change_table Alter_change_table Drop_change_table Drop_subscriber_view Drop_Subscription Purge
The Publisher can control the change tables physical properties. Do not attempt to control a change tables partitioning properties. CDC Manages partitions.
Create_change_Table
DBMS_CDC_PUBLISH.CREATE_CHANGE_TABLE (OWNER => CDC, CHANGE_TABLE_NAME => SALES_CDC', CHANGE_SET_NAME => 'SYNC_SET', SOURCE_SCHEMA => SRC1', SOURCE_TABLE => SALES, COLUMN_TYPE_LIST =. prod_id NUMBER(6), cust_id NUMBER, time_id DATE, channel_id CHAR(1), promo_id NUMBER(6), quantity_sold NUNBER(3), amount_sold NUMBER(10,2) ', CAPTURE_VALUES => BOTH', RS_ID => N' , ROW_ID => N', USER_ID => Y', TIMESTAMP => Y', OBJECT_ID => N', SOURCE_COLMAP => N', TARGET_COLMAP => N', OPTIONS_STRING => TABLESPACE DW STORAGE INITIAL 50M NEXT 12M);
Change tables
SQL> desc SALES_CDC Name Null? Type ----------------------------------------- -------- -----------OPERATION$ CHAR(2) CSCN$ NUMBER COMMIT_TIMESTAMP$ DATE USERNAME$ VARCHAR2(30) TIMESTAMP$ DATE SOURCE_COLMAP$ RAW(128) TARGET_COLMAP$ RAW(128) PROD_ID NUMBER(6) CUST_ID NUMBER TIME_ID DATE CHANNEL_ID CHAR(1) PROMO_ID NUMBER(6) QUANTITY_SOLD NUMBER(3) AMOUNT_SOLD NUMBER(10,2) SQL>
Innovative Consulting, Inc., 2001
Alter_change_table
Allows you to add or drop change columns Allows you to add or drop metadata columns You can not add and drop user columns in the same call, these schema changes require separate calls Do not specify the name of the control columns in the user column lists
*** NOTE *** Force flag = Y will drop a change table even if there are subscriptions referencing it
DBMS_CDC_SUBSCRIBE.DROP_SUBSCRIBER_VIEW
Drop subscription
This procedure will drop a subscription Same as DBMS_CDC_SUBSCRIBE.DROP_SUBSCRIPTION Why Can we do this from the publish?
DBMS_CDC_PUBLISH.DROP_SUBSCRIPTION ( SUBSCRIPTION_HANDLE => :subhandle);
Purge
This procedure will purge data from change tables Automatically monitors subscriptions You can run this procedure in 2 ways Manual at command line Run in a script to proactively maintain change tables Again do not attempt to control a change tables partition properties DBMS_CDC_PUBLISH.PURGE
WAKE UP !!!!!!!!!!!
DBMS_CDC_SUBSCRIBE
Methods
DBMS_CDC_SUBSCRIBE
GET_SUBSCRIPTION_HANDLE SUBSCRIBE ACTIVATE_SUBSCRIPTION EXTEND_WINDOW PREPARE_SUBSCRIBER_VIEW DROP_SUBSCRIBER_VIEW PURGE_WINDOW DROP_SUBSCRIPTION
Innovative Consulting, Inc., 2001
GET_SUBSCRIPTION_HANDLE
Creates a subscription handle This is the first step in obtaining a subscription Subscription handles:
Never get reused Are tracked from the time of creation Not shared by subscribers Validated against the users login id Can be used to access multiple change tables
Innovative Consulting, Inc., 2001
GET_SUBSCRIPTION_HANDLE
SUBSCRIBE
Specifies source table for change data Specifies source columns for change data Subscribe procedure is overloaded
Version1: If you know the publication_id Version2: If you do not know the publication_id
Allows you to subscribe to one or more source tables and select columns in each table To see all published columns and tables query the ALL_PUBLISHED_COLUMNS view
Subscribe
SQL> desc ALL_PUBLISHED_COLUMNS Name ----------------------------------------CHANGE_SET_NAME SOURCE_SCHEMA_NAME SOURCE_TABLE_NAME PUB_ID COLUMN_NAME DATA_TYPE DATA_LENGTH DATA_PRECISION DATA_SCALE NULLABLE SQL> Null? -------NOT NULL NOT NULL NOT NULL NOT NULL NOT NULL Type -------------VARCHAR2(30) VARCHAR2(30) VARCHAR2(30) NUMBER VARCHAR2(30) VARCHAR2(106) NOT NULL NUMBER NUMBER NUMBER VARCHAR2(1)
Subscribe
Must be created before before you need the data You can subscribe to published columns only
SUBSCRIBE
DBMS_CDC_SUBSCRIBE.SUBSCRIBE( SUBSCRIPTION_HANDLE=>:subhandle, SOURCE_SCHEMA=>SRC1, SOURCE_TABLE=>SALES, COLUMN_LIST=>prod_id ,cust_id, time_id, channel_id ,promo_id ,quantity_sold);
DBMS_CDC_SUBSCRIBE.SUBSCRIBE ( subscription_handle => :subhandle, publication_id =>31310, COLUMN_LIST=>prod_id ,cust_id, time_id, channel_id ,promo_id ,quantity_sold);
ACTIVATE_SUBSCRIPTION
Will signify that we are ready to access data
DBMS_CDC_SUBSCRIBE.ACTIVATE_SUBSCRIPTION( SUBSCRIPTION_HANDLE=>:subhandle);
EXTEND_WINDOW
Sets subscription window boundaries First call will establish boundaries Subsequent call will extend High Water Mark
DBMS_CDC_SUBSCRIBE.EXTEND_WINDOW( subscription_handle=>:subhandle);
PREPARE_SUBSCRIBER_VIEW
Creates a subscriber view You can now access data defined within your window
DBMS_CDC_SUBSCRIBE.PREPARE_SUBSCRIBER_VIEW( SUBSCRIPTION_HANDLE =>:subhandle, SOURCE_SCHEMA =>SRC1', SOURCE_TABLE => SALES, VIEW_NAME => :viewname);
PURGE_WINDOW
Used to purge the subscription window Sets low watermark to zero
DBMS_CDC_SUBSCRIBE.PURGE_WINDOW( SUBSCRIPTION_HANDLE=>:subhandle);
DROP_SUBSCRIBER_VIEW
Same as
DBMS_CDC_PUBLISH.DROP_SUBSCRIBER_VIEW
Subscription must have been created by prepare_subscriber_view Must drop the subscriber view before dropping subscription
DBMS_CDC_SUBSCRIBE.DROP_SUBSCRIBER_VIEW( SUBSCRIPTION_HANDLE =>:subhandle, SOURCE_SCHEMA =>SRC1', SOURCE_TABLE => SALES');
Innovative Consulting, Inc., 2001
DROP_SUBSCRIPTION
Drops a subscription Must use the drop subscriber view first Same as DBMS_CDC_PUBLISH.DROP_SUBSCRIPTION
Conclusions
Thank you
[email protected]