Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
Oracle Streams Step By Step

Oracle Streams Step By Step

Ratings: (0)|Views: 84 |Likes:
Published by Lewis Cunningham
SOUG 2007
SOUG 2007

More info:

Published by: Lewis Cunningham on Jan 10, 2013
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less





I have been playing with Oracle Streams again lately. My goal is to capture changes in10g and send them to a 9i database.  Below is the short list for setting up Change Data Capture using Oracle Streams. Thesesteps are mostly from the docs with a few tweaks I have added. This entry only coverssetting up the local capture and apply. I'll add the propagation to 9i later this week or nextweekend.First the set up: we will use the HR account's Employee table. We'll capture all changesto the Employee table and insert them into an audit table. I'm not necessarily saying thisis the way you should audit your database but it makes a nice example.I'll also add a monitoring piece to capture process. I want to be able to see exactly what isbeing captured when it is being captured.You will need to have sysdba access to follow along with me. Your database must also bein archivelog mode. The changes are picked up from the redo log.So, away we go!The first step is to create out streams administrator. I will follow the guidelines from theoracle docs exactly for this:Connect as sysdba:
sqlplus / as sysdba
Create the streams tablespace (change the name and/or location to suit):
create tablespace streams_tbs datafile 'c:\temp\stream_tbs.dbf' size25M reuse autoextend on maxsize unlimited;
Create our streams administrator:
create user strmadmin identified by strmadmindefault tablespace streams_tbsquota unlimited on streams_tbs;
I haven't quite figured out why, but we need to grant our administrator DBA privs. I think this is a bad thing. There is probably a work around where I could do some direct grantsinstead but I haven't had time to track those down.
 grant dba to strmadmin;
We also want to grant streams admin privs to the user.
BEGINDBMS_STREAMS_AUTH.GRANT_ADMIN_PRIVILEGE(grantee => 'strmadmin',grant_privileges => true);END;/
The next steps we'll run as the HR user.
conn hr/hr
Grant all access to the employee table to the streams admin:
grant all on hr.employees to strmadmin;
We also need to create the employee_audit table. Note that I am adding three columns inthis table that do not exist in the employee table.
CREATE TABLE employee_audit(employee_id NUMBER(6),first_name VARCHAR2(20),last_name VARCHAR2(25),email VARCHAR2(25), phone_number VARCHAR2(20),hire_date DATE,job_id VARCHAR2(10),salary NUMBER(8,2),commission_pct NUMBER(2,2), manager_id NUMBER(6),department_id NUMBER(4),upd_date DATE,user_name VARCHAR2(30),action VARCHAR2(30));
Grant all access to the audit table to the streams admin user:
grant all on hr.employee_audit to strmadmin;
 We connect as the streams admin user:
conn strmadmin/strmadmin
We can create a logging table. You would NOT want to do this in a high-volume  production system. I am doing this to illustrate user defined monitoring and show howyou can get inside the capture process.
CREATE TABLE streams_monitor (date_and_time TIMESTAMP(6) DEFAULT systimestamp,txt_msg CLOB );
Here we create the queue. Unlike AQ, where you have to create a separate table, this stepcreates the queue and the underlying ANYDATA table.
BEGINDBMS_STREAMS_ADM.SET_UP_QUEUE(queue_table => 'strmadmin.streams_queue_table',queue_name => 'strmadmin.streams_queue');END;/
This just defines that we want to capture DML and not DDL.
BEGINDBMS_STREAMS_ADM.ADD_TABLE_RULES(table_name => 'hr.employees',streams_type => 'capture',streams_name => 'capture_emp',queue_name => 'strmadmin.streams_queue',include_dml => true,include_ddl => false,inclusion_rule => true);END;/
Tell the capture process that we want to know who made the change:

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->