oracle logminer example by oracle doc

1.  enable supplemental log

SQL> conn system/oracle
Connected.
SQL> select supplemental_log_data_min fromv$database;

SUPPLEMENTAL_LOG_DATA_MI
------------------------
NO

SQL> alter database add supplemental log data;

Database altered.

SQL> select supplemental_log_data_min fromv$database;

SUPPLEMENTAL_LOG_DATA_MI
------------------------
YES

2.  alter session from nls_data format

SQL> alter session set nls_date_format ='yyyy-mm-dd hh24:mi:ss';

Session altered.

SQL> select sysdate from dual;

SYSDATE
-------------------
2009-11-17 22:14:53


3.确认设置了初始化参数:UTL_FILE_DIR

 

SQL> show parameter utl

NAME                           TYPE        VALUE

------------------------------------ ----------- ------------------------------

utl_file_dir                        string      /dataoracle/oracle/logminer

 

 

可以看到该参数的当前设置。如果没有值,必须修改数据库的initsid.ora文件,或者使用如下命令:

 

SQL> alter system set utl_file_dir='/dataoracle/oracle/logminer' scope=spifle;

 

重新启动数据库,使新加的参数生效

创建字典文件的语句:

 

SQL>exec sys.dbms_logmnr_d.build(dictionary_filename=>'dictionary.ora', dictionary_location =>'/dataoracle/oracle/logminer ');

 

其中,dictionary.ora是给字典文件起的文件名(可任意)。

整个创建过程,可能需要十几分钟到一个小时,视该数据库的object 个数以及繁忙程度而定。完成后,会在/dataoracle/oracle/logminer目录下看到一个名为dictionary.ora的文件。


a1. Step 1 Determine which redo log file was mostrecently archived.

SQL> select name from v$archived_log wherefirst_time=(select max(first_time) fr
om v$archived_log);

NAME
--------------------------------------------------------------------------------

D:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\SADB\ARCHIVELOG\2009_11_17\O1_MF_1_

23_5J5C8H6T_.ARC

a2. Step 2 Specify the list of redo log files to beanalyzed.

SQL> executesys.DBMS_LOGMNR.ADD_LOGFILE(LOGFILENAME=>'D:\ORACLE\PRODUCT\10.2.0\
FLASH_RECOVERY_AREA\SADB\ARCHIVELOG\2009_11_17\O1_MF_1_23_5J5C8H6T_.ARC',options
=>sys.DBMS_LOGMNR.NEW);

PL/SQL procedure successfully completed.

SQL> show user
USER is "SYSTEM"

a3. Step 3 Start LogMiner.

SQL> executesys.dbms_logmnr.start_logmnr(OPTIONS=>SYS.DBMS_LOGMNR.DICT_FROM_ONL
INE_CATALOG);

PL/SQL procedure successfully completed.

a4. Step 4 Query the V$LOGMNR_CONTENTSview.

SQL> executesys.dbms_logmnr.start_logmnr(OPTIONS=>SYS.DBMS_LOGMNR.DICT_FROM_ONL
INE_CATALOG);

PL/SQL procedure successfully completed.

SQL> col USR  for a4

SQL> col XID for a8

SQL> col sql_redo for a30


SQL> col sql_undo for a30
SQL> SELECT username as USR,(XIDUSN||'.'||XIDSLT||'.'||XIDSQN) AS XID, SQL_REDO
,SQL_UNDO FROM V$LOGMNR_CONTENTS WHERE username IN ('HR','OE');

USR  XID     SQL_REDO                      SQL_UNDO
---- -------- ------------------------------------------------------------
HR 
  10.10.35 set transaction read write;
 
    8

HR   10.10.35 truncate table SYS_TEMP_FBT;
 
    8

HR   10.10.35 commit;
 
    8

HR   3.18.380 set transaction read write;
HR 
  3.18.380 commit;

USR  XID     SQL_REDO                      SQL_UNDO
---- -------- ------------------------------------------------------------
HR 
  5.23.386 set transaction read write;
HR 
  5.23.386 alter table flash_back_test en
 
            able row movement;

HR   5.23.386Unsupported                   Unsupported
HR 
  5.23.386 update "SYS"."OBJ$" set "OBJ#" update"SYS"."OBJ$" set "OBJ#"
 
             = '52819', "DATAOBJ#" = '5281  = '52819', "DATAOBJ#" ='5281
 
            9', "TYPE#" = '2', "CTIME" = T 9', "TYPE#" = '2', "CTIME" = T
 
            O_DATE('2009-11-16 23:34:21', O_DATE('2009-11-16 23:34:21',
 
            'yyyy-mm-dd hh24:mi:ss'), "MTI'yyyy-mm-dd hh24:mi:ss'),"MTI
 
            ME" = TO_DATE('2009-11-16 23:5 ME" =TO_DATE('2009-11-16 23:3

USR  XID     SQL_REDO                      SQL_UNDO
---- -------- ------------------------------------------------------------
 
            3:20', 'yyyy-mm-ddhh24:mi:ss' 4:21','yyyy-mm-dd hh24:mi:ss'
 
            ), "STIME" = TO_DATE('2009-11- ), "STIME" = TO_DATE('2009-11-
 
            16 23:34:21', 'yyyy-mm-dd hh24 1623:34:21', 'yyyy-mm-dd hh24
 
            :mi:ss'), "STATUS" = '1', "FLA:mi:ss'), "STATUS" = '1',"FLA
 
            GS" = '0', "OID$" = NULL, "SPA GS" = '0', "OID$" = NULL, "SPA
 
            RE1" = '6', "SPARE2" = '1' whe RE1" = '6', "SPARE2" = '1' whe
 
            re "OBJ#" = '52819' and "DATAO re "OBJ#" = '52819' and "DATAO
 
            BJ#" = '52819' and "TYPE#" = ' BJ#" = '52819' and "TYPE#" = '
 
            2' and "CTIME" = TO_DATE('2009 2' and "CTIME" = TO_DATE('2009
 
            -11-16 23:34:21', 'yyyy-mm-dd -11-16 23:34:21', 'yyyy-mm-dd
 
            hh24:mi:ss') and "MTIME" = TO_hh24:mi:ss') and "MTIME" = TO_

USR  XID     SQL_REDO                      SQL_UNDO
---- -------- ------------------------------------------------------------
 
            DATE('2009-11-16 23:34:21', 'yDATE('2009-11-16 23:53:20','y
 
            yyy-mm-dd hh24:mi:ss') and "STyyy-mm-dd hh24:mi:ss') and"ST
 
            IME" = TO_DATE('2009-11-16 23: IME" =TO_DATE('2009-11-16 23:
 
            34:21', 'yyyy-mm-ddhh24:mi:ss 34:21','yyyy-mm-dd hh24:mi:ss
 
            ') and "STATUS" = '1' and "FLA ') and "STATUS" = '1' and "FLA
 
            GS" = '0' and "OID$" IS NULL a GS" = '0' and "OID$" IS NULL a
 
            nd "SPARE1" = '6' and "SPARE2" nd "SPARE1" = '6' and "SPARE2"
 
             = '1' and ROWID = 'AAAAASAABA  = '1' and ROWID ='AAAAASAABA
 
            AAMTtAAf';                    AAMTtAAf';

HR   5.23.386 commit;

USR  XID     SQL_REDO                      SQL_UNDO
---- -------- ------------------------------------------------------------
HR 
  8.2.381  set transaction read write;
HR 
  8.2.381  truncate table SYS_TEMP_FBT;
HR 
  8.2.381  commit;
HR 
  6.15.406 set transaction read write;
HR 
  6.15.406
HR 
  6.15.406 commit;
HR 
  6.20.406 set transaction read write;
HR 
  6.20.406 truncate table SYS_TEMP_FBT;
HR 
  6.20.406 commit;
HR 
  3.19.380 set transaction read write;
HR 
  3.19.380

USR  XID     SQL_REDO                      SQL_UNDO
---- -------- ------------------------------------------------------------
HR 
  3.19.380 commit;

22 rows selected.

a5 . Step 5 End the LogMiner session.

SQL> execute sys.dbms_logmnr.end_logmnr();

PL/SQL procedure successfully completed.

Example 2: Grouping DML Statements intoCommitted Transactions

SQL> insert into employees(employee_id,first_name, last_name, email, phone_numb
er,hire_date,job_id,salary,commission_pct,manager_id,department_id)values('306'
,'Nandini','Shastry','nshastry','1234567890',to_date('10-jan-2003','dd-mon-yyyy'
),'HR_REP','120000','.05','105','10');

1 row created.

SQL> insert into employees(employee_id,first_name, last_name, email, phone_numb
er,hire_date,job_id,salary,commission_pct,manager_id,department_id)values('307'
,'Johne','Simth','JSM','1234567890',to_date('10-jan-2003','dd-mon-yyyy'),'HR_REP
','120000','.05','105','10');

1 row created.

SQL> commit;

Commit complete.

====================== test 2 the online log test============================

=====================================================================

b1. the prepare steps

SQL> show parameter UTL_FILE_DIR;

NAME                                TYPE   VALUE
------------------------------------ ------------------------------------
utl_file_dir 
                       string D:\oracle\product\10.2.0\logminer

SQL> select supplemental_log_data_min fromv$database;

SUPPLEMENTAL_LOG_DATA_MI
------------------------
YES

IF UTL_FILE_DIR IS NULL

SQL> alter system SET UTL_FILE_DIR ='D:\oracle\product\10.2.0\logminer'scope=spfile;

SQL> shutdown immediate;

SQL> startup;

IF the system does not have dbms_logmnr, dbms_logmnr_dpackage

Please execute the follwong sql with sys user.

$ORACLE_HOME/rdbms/admin/dbmslm.sql

$ORACLE_HOME/rdbms/admin/dbmslmd.sql

$ORACLE_HOME/rdbms/admin/dbmslms.sql

b2). build the log dictionary file and add the onlinelog.

SQL> select group#, sequence#, archived, statusfrom v$log;

    GROUP#  SEQUENCE# ARCHIVED STATUS
---------- ---------- ---------------------------------------------------------

                23YES       INACTIVE
 
               24NO        CURRENT
 
               22YES       INACTIVE

SQL> col member for a40
SQL> col status for a9

SQL> col type for a6
SQL> col is_recove for a4
SQL> select * from v$logfile;

    GROUP# STATUS   TYPE  MEMBER                                                             IS_RECOVE
---------- --------- ---------------------------------------------- 
                     ---------
 
         3STALE     ONLINED:\ORACLE\PRODUCT\10.2.0\ORADATA\SADB\REDO03.LOGNO
 
                    ONLINED:\ORACLE\PRODUCT\10.2.0\ORADATA\SADB\REDO02.LOG   NO            
 
         1STALE     ONLINED:\ORACLE\PRODUCT\10.2.0\ORADATA\SADB\REDO01.LOG NO

SQL> execsys.dbms_logmnr_d.build('test.ora','D:\oracle\product\10.2.0\logminer'
);

PL/SQL procedure successfully completed.

SQL> execsys.dbms_logmnr.add_logfile('D:\ORACLE\PRODUCT\10.2.0\ORADATA\SADB\RED
O02.LOG',sys.dbms_logmnr.new);

PL/SQL procedure successfully completed.

SQL> execsys.dbms_logmnr.add_logfile('D:\ORACLE\PRODUCT\10.2.0\ORADATA\SADB\RED
O01.LOG',sys.dbms_logmnr.addfile);

PL/SQL procedure successfully completed.

SQL> execsys.dbms_logmnr.add_logfile('D:\ORACLE\PRODUCT\10.2.0\ORADATA\SADB\RED
O03.LOG',sys.dbms_logmnr.addfile);

PL/SQL procedure successfully completed.

b3). Start the logmnr to analysit the onlinelog.

SQL> executesys.dbms_logmnr.start_logmnr(dictfilename=>'D:\oracle\product\10.2.
0\logminer\test.ora');

PL/SQL procedure successfully completed.

SQL> COL OPERATION FOR A8
SQL> col sql_undo for a30
SQL> col sql_redo for a30
SQL> select operation, sql_redo, sql_undo fromv$logmnr_contents where seg_name=
'EMPLOYEES';

OPERATIOSQL_REDO                      SQL_UNDO
-------- ------------------------------------------------------------
INSERT 
  insert into "HR"."EMPLOYEES"(" delete from"HR"."EMPLOYEES" w
 
       EMPLOYEE_ID","FIRST_NAME","LAS here "EMPLOYEE_ID" = '306' and
 
       T_NAME","EMAIL","PHONE_NUMBER"  "FIRST_NAME" = 'Nandini'and
 
       ,"HIRE_DATE","JOB_ID","SALARY" "LAST_NAME" = 'Shastry' and "E
 
       ,"COMMISSION_PCT","MANAGER_ID" MAIL" = 'nshastry' and "PHONE_
 
        ,"DEPARTMENT_ID")values ('306 NUMBER" = '1234567890' and "HI
 
       ','Nandini','Shastry','nshastr RE_DATE" = TO_DATE('2003-01-10
 
       y','1234567890',TO_DATE('2003- 00:00:00', 'yyyy-mm-ddhh24:m
 
        01-1000:00:00', 'yyyy-mm-dd hi:ss') and "JOB_ID" = 'HR_REP'
 
       h24:mi:ss'),'HR_REP','120000', and "SALARY" = '120000' and "
 
       '.05','105','10');            COMMISSION_PCT" = '.05' and "M

OPERATIOSQL_REDO                      SQL_UNDO
-------- ------------------------------------------------------------
 
                                      ANAGER_ID" = '105' and "DEPART
 
                                      MENT_ID" = '10' and ROWID = 'A
 
                                      AAMg6AAFAAAABVAAA';

INSERT   insert into "HR"."EMPLOYEES"(" delete from"HR"."EMPLOYEES" w
 
       EMPLOYEE_ID","FIRST_NAME","LAS here "EMPLOYEE_ID" = '307' and
 
       T_NAME","EMAIL","PHONE_NUMBER"  "FIRST_NAME" = 'Johne' and"L
 
       ,"HIRE_DATE","JOB_ID","SALARY" AST_NAME" = 'Simth' and "EMAIL
 
       ,"COMMISSION_PCT","MANAGER_ID" " = 'JSM' and "PHONE_NUMBER" =
 
        ,"DEPARTMENT_ID")values ('307  '1234567890' and "HIRE_DATE"
 
       ','Johne','Simth','JSM','12345 = TO_DATE('2003-01-1000:00:00

OPERATIOSQL_REDO                      SQL_UNDO
-------- ------------------------------------------------------------
 
       67890',TO_DATE('2003-01-10 00: ', 'yyyy-mm-ddhh24:mi:ss') an
 
       00:00', 'yyyy-mm-ddhh24:mi:ss d "JOB_ID" = 'HR_REP'and "SAL
 
       '),'HR_REP','120000','.05','10 ARY" = '120000' and "COMMISSIO
 
       5','10');                     N_PCT" = '.05' and "MANAGER_ID
 
                                      " = '105' and "DEPARTMENT_ID"
 
                                      = '10' and ROWID = 'AAAMg6AAFA
 
                                      AAABVAAB';

SQL> execute sys.dbms_logmnr.end_logmnr();

PL/SQL procedure successfully completed.

refer site: http://space.itpub.net/?uid-12045182-action-viewspace-itemid-432982

and oracle document (/b14215/logminer.htm)

你可能感兴趣的:(oracle logminer example by oracle doc)