#!/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 < -u -l -qn -rs -strmadmin -start/stop -ti -si -min_si -abort -so -t -la [ -id ] -cpt -lstb -lr -lrp -prm -par -trace <127|0> -cn -ret -ckf -chk -reset -cn -get_curr_scn -v -ab : Abort instantiation -prm : List capture parameters -cn : Capture name -qn : Queue name -create : Create a capture process using DBMS_CAPTURE_ADM -rs : Rule set name -chk : Set Check point frequency for capture process -ret : change checkpoint retention time -drop : Drop a capture process -s : Show capture streams execution server stats -i : Tables prepared for instantiation -sga : Set SGA_SIZE for logminser session -l : List capture process -si : Prepare schema instantiation -la : List min mandatory present on disk archive -so : source Owner of the table for logminer and the restart capture scn -start/stop : Start or stop capture process -lr : List rule associate with the capture -t : table name -lrp : List archived registered for purge -ti : Prepare table instantiation -lck : List required checkpoint scn -trace : Set trace on a capture, 127 to trace, 0 to trace off -min_si : show lowest Prepared scn -u : Owner of the table or capture process -par : Set parallelism of capture process -cpt : Count rows in system.logmnr_restart_ckpt\$ -fk : force a stream checkpoint (_CHECKPOINT_FORCE) -reset : Reset the capture scn to . last applied SCN used if SCN not given -rcfg : Remove streams configuration -lg : List logminers sessions -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 -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 Stream administrator admin and his password can be deduced by smenu if you defined one for this instance in SM/3.8 ortherwise it will try to default to STRMADMIN/STRMADMIN To Create a capture process : cap -create -cn -qn -u -rs To start/stop : cap -start cap -stop To abort a capture process : cap -abort -so Advance First SCN to default: cap -rest To set parallelism capture : cap -par -cn To set trace on capture : cap -trace 127 -cn off : cap -trace 0 -cn To set checkpoint frequency : cap -chk -cn 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 Do one of the 2 below then retrieve an SCN with -get_curr_scn and perform on remote 'app -si ' prepare schema instantiation: cap -si -so Prepare table instantiation : cap -ti -so -t
-u EOF exit } # ------------------------------------------------------------------------------------- function do_execute { $SETXV 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 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 'Overead (sec)' set lines 190 select SESSION_ID,ROLE,SID,spid,LATCHWAIT,LATCHSPIN,WORK_MICROSEC/1000000,OVERHEAD_MICROSEC/1000000 from V\$LOGMNR_PROCESS; " # ...................................... # 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 positionning" 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 'Requiered |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 a20 col name format a50 select consumer_name,SEQUENCE# , FIRST_SCN , to_char(FIRST_TIME,'DD-MM-YYYY HH24:MI:SS') FIRST_TIME, name, PURGEABLE,DICTIONARY_BEGIN, DICTIONARY_END from SYS.DBA_REGISTERED_ARCHIVED_LOG 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); 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 BREAK="break on table_owner" SQL=" prompt Type cap -lck to see catpure start scn prompt select TABLE_OWNER,TABLE_NAME,SCN,to_char(TIMESTAMP,'DD-MM-YYYY HH24:MI:SS') ti from dba_capture_prepared_tables 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 catpure 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 'Logminer|ID' 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 / 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.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; SELECT 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#; 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 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