#!/usr/bin/ksh # set -xv # author : B. Polarski # program : smenu_stream_capture.ksh # date : 15 Decembre 2005 # 09 October 2007 Added -lck -lrp options # 17 October 2007 Added -lr # 22 November 2007 added -reset, -ckf, -chk, -cpt HOST=`hostname` HOST=`echo $HOST | awk '{ printf ("%-+15.15s",$1) }'` # ------------------------------------------------------------------------------------- function help { cat | more < -u -l -qn -rs -strmadmin cap -la [ -id ] cap -cn -cpt -lstb -lr -lrp -prm -par -trace <127|0> -ret -ckf -chk -reset cap -get_curr_scn | -lx | -rx -cn | -lo cap -t [-so -to -tt -tbs cao -d [ -n ] [ -cn ] -v List: cap -l : List capture process cap -lrp : List archived registered for purge cap -la : List min mandatory present on disk archive cap -lr : List rule associate with the capture cap -lg : List logminers sessions cap -prm : List capture parameters cap -lck : List required checkpoint scn for logminer and the restart capture scn cap -cpt : Count rows in system.logmnr_restart_ckpt\$ cap -s : Show capture streams execution server stats cap -min_si : show lowest Prepared scn cap -i : List table prepared for instantiation Alter capture: cap -chk : Set Check point frequency for capture process cap -ret : change checkpoint retention time cap -reset [] : Reset the capture scn to . last applied SCN used if SCN not given cap -trace : Set trace on a capture, 127 to trace, 0 to trace off Create capture: cap -create -cn -qn -u -rs prepare schema instantiation: cap -si -so Prepare table instantiation : cap -ti -so -t
-u Stop/abort capture: cap -start/stop -x : Start or stop capture process cap -abort -so [-t
] : To cancel schema instantiation, add -t to cancel on the table cap -drop : Drop a capture process cap -rcfg : Remove streams configuration -so -t
Misc: -u : Owner of the table or capture process -t : table name -par : Set parallelism of capture process -sga : Set SGA_SIZE for logminser session -fk : force a stream checkpoint (_CHECKPOINT_FORCE) -reset : Reset the capture scn to . last applied SCN used if SCN not given -gm : Count rows from system.logmnr data dictionary -pckp : Purge Restart_logmnr_ckpt\$ -lstb : List archives with build in dict above first_scn -build : Export the data dictionary to redo (dbms_capturea_adm.build) -ses : List logminer sessions and the capture it is attached -id : Logminer id -shrk : Shrink and analyse table system.logmnr_restart_ckpt\$ -v : Verbose -lx : List transaction processed by capture process -rx : Remove transaction from capture (v\$stream_transaction) -lo : List Object replication path -rms : Remove rule set [neg or pos] -d : capture activity Overview -n : repeat time the action -cn : Capture name -qn : Queue name -get_curr_scn : show the current scn. to be used to initialize remote apply process -strmadmin : Use the user in argument to perform the operation To set parallelism capture : cap -par -cn | To set checkpoint frequency : cap -chk -cn To set trace on capture : cap -trace 127 -cn | off : cap -trace 0 -cn Remove negative rule set : cap -rms neg | Remove positive rule set : cap -rms pos To SGA of logminer : cap -sga -cn # n is expressed in bytes List min SCN requiered for capture : cap -la or cap -la -id if mutliple capture process are present Retrive current system scn : -get_curr_scn and perform on remote 'app -si ' Streams activity (capture->propagation->apply), Delta of 1 sec, repeat 5 time : cap -d 1 -n 5 EOF exit } # ------------------------------------------------------------------------------------- function do_execute { $SETXV echo echo $NN "MACHINE $HOST - ORACLE_SID : $ORACLE_SID $NC" sqlplus -s "$CONNECT_STRING" <propagation->apply -- declaration type section type rec_sess is record ( id number, -- logminer id cap_name varchar2(30), cap_msg_scanned number, cap_msg_enqueued number, cap_spill number, prop_name varchar2(30), prop_msg number, app_name varchar2(30), app_deq number, reader_rcv number, coor_app number, app_err number, app_spill number ) ; type typ_rec is table of rec_sess INDEX BY BINARY_INTEGER; a typ_rec; -- a contains first measurement b typ_rec; -- b contains second measurement key number:=0; v_cpt number:=0; sqlcmd varchar2(1024) ; v_msg_deq number; v_msg_app number; v_msg_rcv number; v_msg_err number; v_app_spill number; v_app_name varchar2(30); v_delta number:='$DELTA_SEC' ; procedure show_result is v_old_cap varchar2(30); v_cap varchar2(30); v_prop varchar2(30); v_app varchar2(30); var number; begin FOR i in b.FIRST .. b.LAST LOOP if b.exists(i) then if a.exists(i) then -- we found a match of keys between A and B dbms_output.put_line(rpad(b(i).cap_name,24,' ') || ' ' || rpad(to_char(b(i).cap_msg_scanned - a(i).cap_msg_scanned ,99990),6,' ') || ' ' || rpad(to_char(b(i).cap_msg_enqueued - a(i).cap_msg_enqueued,99990),6,' ') || ' ' || rpad(to_char(b(i).cap_spill - a(i).cap_spill,99990),6,' ') || ' ' || rpad(b(i).prop_name,24,' ') || ' ' || rpad(to_char(b(i).prop_msg - a(i).prop_msg,99990),6,' ') || ' ' || rpad(b(i).app_name,24,' ') || ' ' || rpad(to_char(b(i).app_deq - a(i).app_deq,99990),6,' ') || ' ' || rpad(to_char(b(i).reader_rcv - a(i).reader_rcv,99990),6,' ') || ' ' || rpad(to_char(b(i).coor_app - a(i).coor_app,99990),6,' ') || ' ' || rpad(to_char(b(i).app_err - a(i).app_err,99990),6,' ') || ' ' || rpad(to_char(b(i).app_spill - a(i).app_spill,99990),6,' ') ); end if; end if; end loop ; end ; function take_measurement return typ_rec is row typ_rec; begin for c in ( select l.DB_LINK, a.USERNAME stream_admin , p.propagation_name, p.source_queue_name, p.destination_queue_name destination_queue_name, c.capture_name, c.logminer_id, nvl(sc.total_messages_captured,0) msg_scanned, nvl(sc.total_messages_enqueued,0) msg_enqueued, ps.TOTAL_MSGS msg_prop, bq.spill_msgs cap_spill from dba_db_links l, dba_streams_administrator a, dba_propagation p, dba_capture c, gv\$streams_capture sc, gv\$propagation_sender ps, gv\$buffered_queues bq where l.username = a.username and p.destination_dblink = l.db_link and p.source_queue_name = c.queue_name and p.source_queue_owner = c.queue_owner and sc.LOGMINER_ID (+) = c.logminer_id and sc.capture_name = c.capture_name and ps.queue_name = c.queue_name and ps.QUEUE_SCHEMA = c.QUEUE_OWNER and bq.queue_name = c.queue_name and bq.QUEUE_SCHEMA = c.QUEUE_OWNER $AND_CAP ) loop sqlcmd:='select a.apply_name,total_messages_dequeued, total_received,' ||' total_applied, total_errors, bq.spill_msgs ' ||' from gv\$streams_apply_reader@' || c.db_link || ' r, ' || ' dba_apply@' || c.db_link ||' a,' || ' gv\$streams_apply_coordinator@' || c.db_link || ' c, ' || ' gv\$buffered_queues@' || c.db_link ||' bq ' ||' where ' ||' r.apply_name (+) = a.apply_name and ' ||' a.queue_name = ''' || c.destination_queue_name|| ''' and ' ||' c.apply_name (+) = a.apply_name and ' ||' bq.queue_name(+) = a.queue_name' ; execute immediate sqlcmd into v_app_name, v_msg_deq,v_msg_rcv, v_msg_app, v_msg_err,v_app_spill; key := c.logminer_id ; row(key).id := c.logminer_id ; row(key).cap_name := c.capture_name ; row(key).cap_msg_scanned := c.msg_scanned ; row(key).cap_msg_enqueued := c.msg_enqueued ; row(key).cap_spill := c.cap_spill ; row(key).prop_name := c.propagation_name ; row(key).prop_msg := c.msg_prop ; row(key).app_name := v_app_name ; row(key).app_deq := v_msg_deq ; row(key).reader_rcv := v_msg_rcv ; row(key).coor_app := v_msg_app ; row(key).app_err := v_msg_err ; row(key).app_spill := v_app_spill ; end loop; return row; end ; -- end procedure take measurement begin -- First measurement a:=take_measurement ; dbms_lock.sleep(v_delta); -- Second measurement b:=take_measurement ; show_result; end; / EOF echo "`date +%H'h'%M:%S`" done exit # ...................................... # Remove rules sets # ...................................... elif [ "$CHOICE" = "REMOVE_RULE_SET" ];then if [ -z "$RMS_TYPE" ];then echo "Add 'neg' or 'pos' to determine which rules to remove" exit fi if [ "$RMS_TYPE" = 'pos' ];then BOL=TRUE else BOL=FALSE fi SQL=" col v_rs_name new_value v_rs_name noprint col v_rs_owner new_value v_rs_owner noprint select v_rs_name, v_rs_owner from ( select RULE_SET_NAME v_rs_name ,RULE_SET_OWNER v_rs_owner from dba_capture where capture_name = upper('$fcapture') and 'pos' = '$RMS_TYPE' union select NEGATIVE_RULE_SET_NAME v_rs_name ,NEGATIVE_RULE_SET_OWNER v_rs_owner from dba_capture where capture_name = upper('$fcapture') and 'neg' = '$RMS_TYPE' ) / prompt doing exec dbms_streams_adm.remove_rule(rule_name => '&v_rs_owner.&v_rs_name', streams_type=>'capture', streams_name =>'$fcapture', inclusion_rule => $BOL ); exec dbms_streams_adm.remove_rule(rule_name => '&v_rs_owner..&v_rs_name', streams_type=>'capture', streams_name =>'$fcapture', inclusion_rule => $BOL ); " # ...................................... # List Objects paths # ...................................... elif [ "$CHOICE" = "LIST_DIFF" ];then if [ -n "$ftable" ];then AND_TABLE=" and table_name = '$ftable' " fi SQL=" set serveroutput on size unlimited declare v_capture varchar2(30); v_cap_q varchar2(30); v_cap_qo varchar2(30); v_prop varchar2(30); v_dest_q varchar2(30); v_dest_qo varchar2(30); v_dblink varchar2(30); begin for c in ( select TABLE_OWNER, TABLE_NAME from dba_capture_prepared_tables where SCN is not null ) loop -- Get the caputre for this table select STREAMS_NAME into v_capture from SYS.DBA_STREAMS_TABLE_RULES where STREAMS_TYPE = 'CAPTURE' and TABLE_OWNER = c.TABLE_OWNER and TABLE_NAME = c.TABLE_NAME ; dbms_output.put_line(rpad('--> Owner.Table',20,' ') || ': ' || c.table_owner||'.'|| c.table_name ) ; dbms_output.put_line(rpad('--> Capture',20,' ') || ': '|| v_capture ) ; select QUEUE_NAME, QUEUE_OWNER into v_cap_q,v_cap_qo from sys.dba_capture where CAPTURE_NAME = v_capture ; dbms_output.put_line(rpad('--> Queue name',20,' ')|| ': '||v_cap_qo||'.'||v_cap_q ) ; select PROPAGATION_NAME, DESTINATION_QUEUE_OWNER, DESTINATION_QUEUE_NAME, DESTINATION_DBLINK into v_prop, v_dest_q, v_dest_qo, v_dblink from SYS.DBA_PROPAGATION where SOURCE_QUEUE_OWNER = v_cap_qo and SOURCE_QUEUE_NAME = v_cap_q; dbms_output.put_line(rpad('--> Propagation name',20,' ')|| ': '||v_prop ) ; dbms_output.put_line(rpad('--> Dblink',20,' ')|| ': '||v_dblink ) ; dbms_output.put_line(rpad('--> Destination queueq',20,' ')|| ': '||v_dest_qo||'.'||v_dest_q ) ; dbms_output.put_line('---------------------' ); /* dbms_output.put_line(rpad('--> Destination queueq',20,' ')|| ': '||v_dest_qo||'.'||v_dest_q ) ; dbms_output.put_line(rpad('--> Destination table',20,' ')|| ': $ftarget_owner.$ftarget_table') ; dbms_output.put_line(rpad('--> Source diff table',20,' ')|| ': $fsource_owner.$tbl_dif1') ; dbms_output.put_line(rpad('--> Target diff table',20,' ')|| ': $fsource_owner.$tbl_dif2') ; -- First diff table select count(1) into v_cpt from dba_tables where owner = '$fsource_owner' and table_name = upper('$tbl_dif1'); if v_cpt = 0 then v_cmd:='drop table $fsource_owner.$tbl_dif1' ; execute immediate v_cmd ; v_cmd:='create table $fsource_owner.$tbl_dif1 $TBS as select * from $fsource_owner.$ftable where 1=2'; dbms_output.put_line(v_cmd) ; execute immediate v_cmd ; dbms_output.put_line(' table $tbl_dif1 created $TBS'); else dbms_output.put_line(' table $tbl_dif1 already exists '); end if; -- Second diff table select count(1) into v_cpt from dba_tables where owner = '$fsource_owner' and table_name = upper('$tbl_dif2'); if v_cpt = 0 then v_cmd:='drop table $fsource_owner.$tbl_dif2' ; execute immediate v_cmd ; v_cmd:='create table $fsource_owner.$tbl_dif2 $TBS as select * from $fsource_owner.$ftable where 1=2 '; dbms_output.put_line(v_cmd) ; execute immediate v_cmd ; dbms_output.put_line('--> table $tbl_dif2 created $TBS'); else dbms_output.put_line(' table $tbl_dif2 already exists '); end if; dbms_rectifier_diff.differences( sname1 => '$fsource_owner' , oname1 => '$ftable' , reference_site => v_global_name , sname2 => '$ftarget_owner' , \ oname2 => '$ftarget_table', comparison_site => v_dblink, where_clause => NULL, column_list => '', \ missing_rows_sname => '$fsource_owner', missing_rows_oname1 => '$tbl_dif1', missing_rows_oname2 => '$tbl_dif2', \ missing_rows_site => '', max_missing => 10000000, commit_rows => 500 ); dbms_output.put_line('v_cmd='||v_cmd); execute immediate v_cmd ; */ end loop; end; / " # ...................................... # Remove transaction in v$streams_transaction # ...................................... elif [ "$CHOICE" = "REMOVE_TX" ];then SQL=" prompt WARNING: prompt You must stop capture before remove TX and restat when it is done prompt prompt Doing execute dbms_capture_adm.set_parameter('$fcapture','_ignore_transaction','$TX_ID');; execute dbms_capture_adm.set_parameter('$fcapture','_ignore_transaction','$TX_ID'); " # ...................................... # List transaction in v$streams_transaction # ...................................... elif [ "$CHOICE" = "LIST_TX" ];then SQL="set lines 190 pages 66 col Streams_type head 'Streams|Type' col CUMULATIVE_MESSAGE_COUNT head 'LCR since|start TX' justify l col FIRST_MESSAGE_TIME for a19 head 'First LCR|Time' justify l col LAST_MESSAGE_TIME for a19 head 'Last LCR|Time' justify l col fn for 99999999999 head 'SCN at start of TX' col ln for 99999999999 head 'Last SCN in this TX' col tx_id for a16 select streams_name,streams_type, to_char(XIDUSN)||'.'||to_char(XIDSLT)||'.'||to_char(XIDSQN) tx_id, CUMULATIVE_MESSAGE_COUNT, to_char(FIRST_MESSAGE_TIME,'YYYY-MM-DD HH24:MI:SS') FIRST_MESSAGE_TIME, to_char(last_MESSAGE_TIME,'YYYY-MM-DD HH24:MI:SS') last_MESSAGE_TIME -- ,FIRST_MESSAGE_NUMBER fn , LAST_MESSAGE_NUMBER ln from V\$STREAMS_TRANSACTION ;" # ...................................... # List Logminser sessions # ...................................... elif [ "$CHOICE" = "LIST_SES" ];then SQL="col SESSION_NAME format a20 select SESSION_NAME, SESSION#, CLIENT#, START_SCN, END_SCN , SPILL_SCN,SPILL_TIME,OLDEST_SCN,RESUME_SCN from system.LOGMNR_SESSION\$ /" # ...................................... # Export the dictionary to redo # ...................................... elif [ "$CHOICE" = "BUILD" ];then SQL="set serveroutput on variable f_scn number; begin :f_scn := 0; dbms_capture_adm.build(:f_scn); dbms_output.put_line('the first_scn value is ' || :f_scn); end; / " # ...................................... # List archives with built in dictionary above the first SCN # ...................................... elif [ "$CHOICE" = "LSTB" ];then SQL="prompt The following archives is suitable new first_scn for capture. If name is empty then archive is not more on disk prompt col first_change# head SCN col name format a80 set lines 190 select sequence#, first_change#,FIRST_TIME, name from v\$archived_log where DICTIONARY_BEGIN = 'YES' and first_change# > (select min(first_scn) from dba_capture) order by FIRST_TIME desc ; " # ...................................... # Purge Logminer CKPT # ...................................... elif [ "$CHOICE" = "PURGE_CKP" ];then if [ -z "$fcapture" ];then var=`sqlplus -s "$CONNECT_STRING" <" exit fi fi SQL="set serveroutput on size unlimited prompt Before : prompt set head on select /*+ index_ffs(a LOGMNR_RESTART_CKPT\$_PK) */ count(*) from system.LOGMNR_RESTART_CKPT\$ a ; DECLARE hScn number := 0; lScn number := 0; sScn number; ascn number; alog varchar2(1000); v_session number; begin select min(start_scn), min(applied_scn) into sScn, ascn from dba_capture where capture_name = '$fcapture' ; select logminer_id into v_session from dba_capture where capture_name = '$fcapture' ; -- DBMS_OUTPUT.ENABLE(2000); for cr in (select distinct(a.ckpt_scn) from system.logmnr_restart_ckpt\$ a where a.ckpt_scn <= ascn and a.valid = 1 and session# = v_session and exists (select * from system.logmnr_log\$ l where a.ckpt_scn between l.first_change# and l.next_change#) order by a.ckpt_scn desc) loop if (hScn = 0) then hScn := cr.ckpt_scn; else lScn := cr.ckpt_scn; exit; end if; end loop; if lScn = 0 then lScn := sScn; end if; dbms_output.put_line('dbms_capture_adm.alter_capture( capture_name => ''$fcapture'',first_scn=> ' ||to_char(lScn)||');') ; dbms_capture_adm.alter_capture( capture_name => '$fcapture',first_scn=> lScn ); end; / prompt After : prompt set head on select /*+ index_ffs(a LOGMNR_RESTART_CKPT\$_PK) */ count(*) from system.LOGMNR_RESTART_CKPT\$ a ; prompt " # ...................................... # List logminer tables contents # ...................................... elif [ "$CHOICE" = "GM" ];then SQL=" set serveroutput on size unlimited declare var number:=0 ; begin for t in (select table_name from dba_tables where owner = 'SYSTEM' and table_name like 'LOGM%'order by table_name) loop execute immediate('select count(*) from system.' || t.table_name) into var ; dbms_output.put_line(t.table_name ||':' || to_char(var)); end loop ; end ; / " # ...................................... # List logminer sessions # ...................................... elif [ "$CHOICE" = "LIST_LG" ];then if [ -n "$LOGMNR_ID" ];then WHERE_LOGMNR_ID=" where SESSION_ID = $LOGMNR_ID " fi SQL="col ROLE format a16 col SESSION_ID format 99999 head 'Logmr|id' justify c col WORK_MICROSEC format 9999990.99 head 'Work(sec)' col OVERHEAD_MICROSEC format 9999990.99 head 'Waiting or|Overead (sec)' justify c col ROLE format a22 col SID for 99999 col latchwait head 'Address latch|Process waiting' col latchspin head 'Address latch|Process spinning' set lines 190 select SESSION_ID, ROLE ,SID, spid , WORK_MICROSEC/1000000 WORK_MICROSEC, OVERHEAD_MICROSEC/1000000 OVERHEAD_MICROSEC , LATCHWAIT,LATCHSPIN from V\$LOGMNR_PROCESS $WHERE_LOGMNR_ID order by session_id ; " # ...................................... # Remove streams configuration # ...................................... elif [ "$CHOICE" = "RCFG" ];then if $SBIN/scripts/yesno.sh "to remove streams configuration" then EXECUTE=YES SQL="prompt Doing exec dbms_streams_adm.remove_streams_configuration;; exec dbms_streams_adm.remove_streams_configuration;" else SQL="prompt cancelled" fi # ...................................... # Shrink and analyse table system.logmnr_restart_ckpt\$ # ...................................... elif [ "$CHOICE" = "SHRINK" ];then $SBIN/module2/s4/smenu_desc_table.ksh -u system -t logmnr_restart_ckpt\$ sqlplus -s "$CONNECT_STRING" < 0) First scn must be <= required chkpoint SCN EOF TITTLE="Report Streams SCN positioning" SQL="break on capture_name on report col start_scn for 999999999999 head 'Start scn' col first_scn for 999999999999 head 'First scn' col CAPTURED_SCN for 999999999999 head 'Captured scn' col las for 999999999999 head 'Applied scn' col LAST_ENQUEUED_SCN for 999999999999 head 'Last scn|Enqueued' justify c col REQUIRED_CHECKPOINT_SCN for 999999999999 head 'Required |Checkpoint scn' justify c col MAX_CHECKPOINT_SCN for 999999999999 head 'Max |Checkpoint scn' justify c col capture_name for a22 head 'Capture name' set linesize 150 select CAPTURE_NAME, FIRST_SCN, start_scn, APPLIED_SCN las, CAPTURED_SCN, CHECKPOINT_RETENTION_TIME, LAST_ENQUEUED_SCN, REQUIRED_CHECKPOINT_SCN, MAX_CHECKPOINT_SCN from SYS.DBA_CAPTURE; " # ...................................... # List archive purge status # ...................................... elif [ "$CHOICE" = "REGISTERED" ];then SQL="set linesize 150 break on consumer_name on report col consumer_name format a23 col name format a55 col sequence# for 999999 head 'Arch#' col first_scn for 999999999999 col R noprint select consumer_name,SEQUENCE# , FIRST_SCN , to_char(FIRST_TIME,'MM-DD HH24:MI:SS') first_time, name, PURGEABLE,DICTIONARY_BEGIN, DICTIONARY_END , r from ( select consumer_name,SEQUENCE# , FIRST_SCN , FIRST_TIME, name, PURGEABLE,DICTIONARY_BEGIN, DICTIONARY_END , row_number() over (order by FIRST_TIME desc, thread#) r from SYS.DBA_REGISTERED_ARCHIVED_LOG ) where r between 1 and $ROWNUM order by SEQUENCE# desc ; " # ...................................... # List capture server status # ...................................... elif [ "$CHOICE" = "CAPTURE_SERVER" ];then SQL="col state format a19 select CAPTURE_NAME cap, state,ELAPSED_CAPTURE_TIME ect,ELAPSED_ENQUEUE_TIME eet,ELAPSED_LCR_TIME elt, CAPTURE_MESSAGE_NUMBER cmn ,ENQUEUE_MESSAGE_NUMBER emn, total_messages_captured tmc, TOTAL_MESSAGES_ENQUEUED tme from v\$streams_capture / select CAPTURE_NAME cap,to_char(STARTUP_TIME,'MM/DD HH24:MI:SS') startup, to_char(CAPTURE_TIME,'MM/DD HH24:MI:SS') lct, to_char(CAPTURE_MESSAGE_CREATE_TIME,'MM/DD HH24:MI:SS') cmct, to_char(ENQUEUE_TIME,'MM/DD HH24:MI:SS')ltme, to_char(ENQUEUE_MESSAGE_CREATE_TIME,'MM/DD HH24:MI:SS') emct from v\$streams_capture / " # ...................................... # Set checkpoint frequency # ...................................... elif [ "$CHOICE" = "LOGMINER" ];then # bpa : in 10g this is also good # SELECT NVL(MAX(A.SPARE1), 0) FROM SYSTEM.LOGMNR_RESTART_CKPT$ A WHERE A.SESSION# = :b AND A.VALID = 1 AND EXISTS # (SELECT B.CKPT_SCN FROM SYSTEM.LOGMNR_RESTART_CKPT$ B WHERE B.CKPT_SCN = A.SPARE1 AND B.SESSION# = A.SESSION# AND B.VALID = 1) if [ -n "$LOGMNR_ID" ];then WHERE_LOGMNR_ID=" where LOGMINER_ID = $LOGMNR_ID " AND_LOGMNR_ID=" and session# = $LOGMNR_ID " fi SQL=" set serveroutput on DECLARE hScn number := 0; lScn number := 0; sScn number; ascn number; alog varchar2(1000); begin select min(start_scn), min(applied_scn) into sScn, ascn from dba_capture $WHERE_LOGMNR_ID; DBMS_OUTPUT.ENABLE(2000); for cr in (select distinct(a.ckpt_scn) from system.logmnr_restart_ckpt\$ a where a.ckpt_scn <= ascn and a.valid = 1 $AND_LOGMNR_ID and exists (select * from system.logmnr_log\$ l where a.ckpt_scn between l.first_change# and l.next_change#) order by a.ckpt_scn desc) loop if (hScn = 0) then hScn := cr.ckpt_scn; else lScn := cr.ckpt_scn; exit; end if; end loop; if lScn = 0 then lScn := sScn; end if; -- select min(name) into alog from v\$archived_log where lScn between first_change# and next_change#; -- dbms_output.put_line('Capture will restart from SCN ' || lScn ||' in log '||alog); dbms_output.put_line('Capture will restart from SCN ' || lScn ||' in the following file:'); for cr in (select name, first_time , SEQUENCE# from DBA_REGISTERED_ARCHIVED_LOG where lScn between first_scn and next_scn order by thread#) loop dbms_output.put_line(to_char(cr.SEQUENCE#)|| ' ' ||cr.name||' ('||cr.first_time||')'); end loop; end; / " # ...................................... # Set SGA_SIZE # ...................................... elif [ "$CHOICE" = "SET_SGA" ];then SQL="execute dbms_capture_adm.set_parameter(capture_name=> '$fcapture' , parameter=> '_SGA_SIZE', value => ${sga_size}); " # ...................................... # Set checkpoint frequency # ...................................... elif [ "$CHOICE" = "CHECK_FREQ" ];then SQL="execute dbms_capture_adm.set_parameter(capture_name=> '$fcapture' , parameter=> '_CHECKPOINT_FREQUENCY', value => $check_freq); " # ...................................... # Set retention checkpoint time # ...................................... elif [ "$CHOICE" = "SET_RET" ];then SQL="execute dbms_capture_adm.alter_capture(capture_name=> '$fcapture' , checkpoint_retention_time=> $value ); " elif [ "$CHOICE" = "SET_PAR" ];then SQL="execute dbms_capture_adm.set_parameter(capture_name=> '$fcapture' , parameter=> '$PAR', value => $value); " # ...................................... # Table prepared for instantion # ...................................... elif [ "$CHOICE" = "TBL_INS" ];then if [ -n "$fowner" ];then WHERE=" where TABLE_OWNER=upper('$fowner')" fi BREAK="break on table_owner" SQL=" prompt Type cap -lck to see capture start scn prompt select TABLE_OWNER, TABLE_NAME,SCN, to_char(TIMESTAMP,'DD-MM-YYYY HH24:MI:SS') ti from dba_capture_prepared_tables $WHERE order by table_owner;" # ...................................... # Show lowest prepared SCN # ...................................... elif [ "$CHOICE" = "MIN_SI" ];then if [ -n '$fowner' ];then WHERE_OWNER=" where table_owner=upper('$fowner') " AND_OWNER=" and table_owner=upper('$fowner') " fi BREAK="break on table_owner" SQL="prompt Type cap -lck to see capture start scn prompt select TABLE_OWNER,TABLE_NAME,SCN min_scn,to_char(TIMESTAMP,'DD-MM-YYYY HH24:MI:SS') ti from dba_capture_prepared_tables where scn = (select min(scn) from dba_capture_prepared_tables $WHERE_OWNER) $AND_OWNER;" # ...................................... # Create capture process # ...................................... elif [ "$CHOICE" = "CREATE" ];then if [ -n "$frsname" ];then SQL="execute DBMS_CAPTURE_ADM.CREATE_CAPTURE(queue_name => '$fowner.$fqueue', capture_name => '$fcapture', rule_set_name => '$fowner.$frsname');" fi # ...................................... # List capture process # ...................................... elif [ "$CHOICE" = "LIST" ];then if [ -n "$fcapture" ];then AND_CAPTURE_NAME=" and capture_name = upper('$fcapture') " AND_CAPTURE_NAME_A=" and a.capture_name = upper('$fcapture') " WHERE=" where 1=1" elif [ -n "$LOGMNR_ID" ];then AND_LOGMNR_ID=" and LOGMINER_ID = $LOGMNR_ID " AND_LOGMNR_ID_A=" and a.LOGMINER_ID = $LOGMNR_ID " WHERE=" where 1=1" fi SQL=" col LOGMINER_ID head 'Log|ID' for 999 select LOGMINER_ID, CAPTURE_USER, start_scn ncs, to_char(STATUS_CHANGE_TIME,'DD-MM HH24:MI:SS') change_time ,CAPTURE_TYPE,RULE_SET_NAME, negative_rule_set_name , status from dba_capture $WHERE $AND_CAPTURE_NAME $AND_LOGMNR_ID order by logminer_id / set lines 190 col rsname format a22 head 'Rule set name' col delay_scn head 'Delay|Scanned' justify c col delay2 head 'Delay|Enq-Applied' justify c col state format a24 col process_name format a8 head 'Process|Name' justify c col LATENCY_SECONDS head 'Lat(s)' col total_messages_captured head 'total msg|Captured' col total_messages_enqueued head 'total msg|Enqueue' col ENQUEUE_MESG_TIME format a17 head 'Row creation|initial time' col CAPTURE_TIME head 'Capture at' select a.logminer_id , a.CAPTURE_NAME cap, queue_name , AVAILABLE_MESSAGE_NUMBER, CAPTURE_MESSAGE_NUMBER lcs, AVAILABLE_MESSAGE_NUMBER-CAPTURE_MESSAGE_NUMBER delay_scn, last_enqueued_scn , applied_scn las , last_enqueued_scn-applied_scn delay2 from dba_capture a, v\$streams_capture b where a.capture_name = b.capture_name (+) $AND_CAPTURE_NAME_A $AND_LOGMNR_ID_A order by logminer_id ; SELECT c.logminer_id, SUBSTR(s.program,INSTR(s.program,'(')+1,4) PROCESS_NAME, c.sid, c.serial#, c.state, to_char(c.capture_time, 'HH24:MI:SS MM/DD/YY') CAPTURE_TIME, to_char(c.enqueue_message_create_time,'HH24:MI:SS MM/DD/YY') ENQUEUE_MESG_TIME , (SYSDATE-c.capture_message_create_time)*86400 LATENCY_SECONDS, c.total_messages_captured, c.total_messages_enqueued FROM V\$STREAMS_CAPTURE c, V\$SESSION s WHERE c.SID = s.SID $AND_CAPTURE_NAME $AND_LOGMNR_ID AND c.SERIAL# = s.SERIAL# order by logminer_id ; set head off select ERROR_MESSAGE from dba_capture;" # ...................................... # abort instantiation # ...................................... elif [ "$CHOICE" = "ABORT_INSTANTIATE" ];then if [ -n "$ftable" ];then if [ -z "$fsource_owner" ];then echo "I need the table owner, user 'cap -abort -so OWNER -t TABLE'" exit fi SQL="execute DBMS_CAPTURE_ADM.${ACTION}_TABLE_INSTANTIATION( table_name => '$fsource_owner.$ftable'); " elif [ -n "$fsource_owner" ];then SQL="execute DBMS_CAPTURE_ADM.${ACTION}_SCHEMA_INSTANTIATION( schema_name => '$fsource_owner'); " else echo "Need to be more precise for instantiation : give a owner or owner+table name" exit fi # ...................................... # Prepare instantiation # ...................................... elif [ "$CHOICE" = "PREPARE" ];then if [ -z "$fsource_owner" ];then echo "I need a schema, use 'cap -so OWNER'" exit fi if [ -z "$ftable" ];then SQL="execute DBMS_CAPTURE_ADM.PREPARE_SCHEMA_INSTANTIATION( schema_name => '$fsource_owner'); " else src_sid=${src_sid:-$ORACLE_SID} SQL="show user prompt execute dbms_capture_adm.prepare_table_instantiation('$fsource_owner.$ftable') ; execute DBMS_CAPTURE_ADM.PREPARE_TABLE_INSTANTIATION(table_name => '$fsource_owner.$ftable'); " fi # ...................................... # Start / stop / drop capture # ...................................... elif [ "$CHOICE" = "START_STOP_DROP" ];then SQL=" execute DBMS_CAPTURE_ADM.${ACTION}_CAPTURE( capture_name => '$fcapture');" fi if [ "$EXECUTE" = "YES" ];then do_execute else echo "$SQL" fi