Example 2: Mining the Redo Log Files in a Given SCN Range

This example shows how to specify an SCN range of interest and mine the redo log files that satisfy that range. You can use LogMiner to see all committed DML statements whose effects have not yet been made permanent in the data files.

Note that in this example (unlike the other examples) it is not assumed that you have set the NLS_DATE_FORMAT parameter.

  1. Determine the SCN of the last checkpoint taken.

    SELECT CHECKPOINT_CHANGE#, CURRENT_SCN FROM V$DATABASE;
    
    CHECKPOINT_CHANGE#  CURRENT_SCN
    ------------------  ---------------
              56453576         56454208
    
  2. Start LogMiner and specify the CONTINUOUS_MINE option.

    EXECUTE DBMS_LOGMNR.START_LOGMNR(-
    
       STARTSCN => 56453576, -
       ENDSCN   => 56454208, -
       OPTIONS  => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG + -
                   DBMS_LOGMNR.COMMITTED_DATA_ONLY + -
                   DBMS_LOGMNR.PRINT_PRETTY_SQL + -
                   DBMS_LOGMNR.CONTINUOUS_MINE);
    
  3. Display the list of archived redo log files added by LogMiner.

    SELECT FILENAME name, LOW_SCN, NEXT_SCN FROM V$LOGMNR_LOGS;
    
    NAME                                           LOW_SCN   NEXT_SCN
    --------------------------------------------   --------  --------
    /usr/oracle/data/db1arch_1_215_482701534.dbf   56316771  56453579
    

    Note that the redo log file that LogMiner added does not contain the whole SCN range. When you specify the CONTINUOUS_MINE option, LogMiner adds only archived redo log files when you call the DBMS_LOGMNR.START_LOGMNR procedure. LogMiner will add the rest of the SCN range contained in the online redo log files automatically, as needed during the query execution. Use the following query to determine whether the redo log file added is the latest archived redo log file produced.

    SELECT NAME FROM V$ARCHIVED_LOG 
       WHERE SEQUENCE# = (SELECT MAX(SEQUENCE#) FROM V$ARCHIVED_LOG);
    
    NAME
    -------------------------------------------- 
    /usr/oracle/data/db1arch_1_215_482701534.dbf 
    
  4. Query the V$LOGMNR_CONTENTS view for changes made to the user tables.

    The following query does not return the SET TRANSACTION READ WRITE and COMMIT statements associated with transaction 1.6.1911 because these statements do not have a segment owner (SEG_OWNER) associated with them.

    Note that the default NLS_DATE_FORMAT, 'DD-MON-RR', is used to display the column MODIFIED_TIME of type DATE.

    SELECT SCN, (XIDUSN || '.' || XIDSLT || '.' ||  XIDSQN) as XID, SQL_REDO 
        FROM V$LOGMNR_CONTENTS
        WHERE SEG_OWNER NOT IN ('SYS', 'SYSTEM');
    
    
    SCN        XID        SQL_REDO
    ---------- ---------- -------------
    56454198   1.6.1911   update "OE"."PRODUCT_INFORMATION"
                            set
                              "WARRANTY_PERIOD" = TO_YMINTERVAL('+05-00')
                            where
                              "PRODUCT_ID" = 2430 and
                              "WARRANTY_PERIOD" = TO_YMINTERVAL('+02-00') and
                              ROWID = 'AAAHTKAABAAAY9AAAC';
    
    56454199   1.6.1911   insert into "OE"."PRODUCT_TRACKING"
                            values
                              "PRODUCT_ID" = 2430,
                              "MODIFIED_TIME" = TO_DATE('17-JAN-03', 'DD-MON-RR'),
                              "OLD_LIST_PRICE" = 175,
                              "OLD_WARRANTY_PERIOD" = TO_YMINTERVAL('+02-00');
    
    56454204   1.6.1911    update "OE"."PRODUCT_INFORMATION"
                             set
                               "WARRANTY_PERIOD" = TO_YMINTERVAL('+05-00')
                             where
                               "PRODUCT_ID" = 2302 and
                               "WARRANTY_PERIOD" = TO_YMINTERVAL('+02-00') and
                               ROWID = 'AAAHTKAABAAAY9QAAA';
    56454206   1.6.1911    insert into "OE"."PRODUCT_TRACKING"
                             values
                               "PRODUCT_ID" = 2302,
                               "MODIFIED_TIME" = TO_DATE('17-JAN-03', 'DD-MON-RR'),
                               "OLD_LIST_PRICE" = 150,
                               "OLD_WARRANTY_PERIOD" = TO_YMINTERVAL('+02-00');
    
  5. End the LogMiner session.

    EXECUTE DBMS_LOGMNR.END_LOGMNR();