Oracle Logminer
For more informationg referencing
http://docs.oracle.com/cd/B28359_01/server.111/b28319/logminer.htm
or google: 17 Using LogMiner to Analyze Redo Log Files
1)easy example for logmnr
1@@@@prepare the dictionary for logminer
@@@logminer is a oracle built-in package.
@@@$ORACLE_HOME/rdmbs/admin/dbmslm.sql dbmslmd.sql
@@@the dmbslm.sql is used to analyzing the logfile.
@@@the dbmslmd.sql is uesed to creating the data dictionary file.
[oracle@station78 admin]$ pwd
/u01/app/oracle/product/10.2.0/db_1/rdbms/admin
[oracle@station78 admin]$ ls dbmslm.sql
dbmslm.sql
[oracle@station78 admin]$ ls dbmslmd.sql
dbmslmd.sql
@@@do as the user oracle.
@@@add the onlinelog file directory to the "utl_file_dir"
$ORACLE_SID=orcl
$ORACLE_BASE=/u01/app/oracle
$ORACLE_HOME=/u01/app/oracle/product/10.2.0/db1
[oracle@station78 dbs]$ pwd
/u01/app/oracle/product/10.2.0/db_1/dbs
[oracle@station78 dbs]$ tail -n 1 initorcl.ora
*.utl_file_dir='/u01/app/oracle/oradata/orcl' @@@add this line.
@@@apply the new initorcl.ora to initialize instance.
[oracle@station78 admin]$ sqlplus /nolog
SQL> conn /as sysdba;
SQL> create pfile from spfile;
SQL> shutdown immediate;
SQL> create spfile from pfile;
SQL> startup
@@@it is a whole line below, for literal tidy
SQL> execute dbms_logmnr_d.build(
dictionary_filename => 'test1.dat',
dictionary_location => '/u01/app/oracle/oradata/orcl');
PL/SQL procedure successfully completed.
2@@@@add the onlinelog to data dictionary
@@@My instance has 3 onlinelog group. add all.
[oracle@station78 orcl]$ ls /u01/app/oracle/oradata/orcl/*.log
/u01/app/oracle/oradata/orcl/redo01.log
/u01/app/oracle/oradata/orcl/redo02.log
/u01/app/oracle/oradata/orcl/redo03.log
[oracle@station78 orcl]$ ls /u01/app/oracle/oradata/orcl/*.dat
/u01/app/oracle/oradata/orcl/test1.dat
BEGIN
dbms_logmnr.add_logfile(
LogFileName => '/u01/app/oracle/oradata/orcl/redo01.log',
Options => dbms_logmnr.new);
END;
/
SQL> /
PL/SQL procedure successfully completed
BEGIN
dbms_logmnr.add_logfile(
LogFileName => '/u01/app/oracle/oradata/orcl/redo02.log',
Options => dbms_logmnr.addfile);
END;
/
SQL> /
PL/SQL procedure successfully completed
BEGIN
dbms_logmnr.add_logfile(
LogFileName => '/u01/app/oracle/oradata/orcl/redo03.log',
Options => dbms_logmnr.addfile);
END;
/
SQL> /
PL/SQL procedure successfully completed
3@@@@analyze the onlinelog.
@@@
@@@option:
@@@modify the time format for to_date
@@@then you could run "select sysdate from dual" to check;
[oracle@station78 ~]$ tail -n 1 .bash_profile
export NLS_DATE_FORMAT="yyyy-mm-dd:hh24:mi:ss"
[oracle@station78 ~]$ . .bash_profile
@@@all the loginfo in the v$logmnr_contents.
@@@
BEGIN
dbms_logmnr.start_logmnr(
DictFileName => '/u01/app/oracle/oradata/orcl/test1.dat',
StartTime => to_date('2012-05-07:16:34:53','yyyy-mm-dd:hh24:mi:ss'),
EndTime => to_date('2012-05-08:16:34:53','yyyy-mm-dd:hh24:mi:ss'));
END;
/
SQL> /
PL/SQL procedure successfully completed.
@@@
SQL> select operation, sql_redo, sql_undo from v$logmnr_contents;
@@@it is a big table......
@@@you could check in the isqlplus, or sql developer, or tora, or toad.
SQL> desc v$logmnr_contents
Name Null? Type
----------------------------------------- -------- ----------------------------
SCN NUMBER
CSCN NUMBER
TIMESTAMP DATE
COMMIT_TIMESTAMP DATE
.................................
4@@@@complementary example
@@@write a sql for logminor
@@@
@@@First: create table.
@@@
SQL> create table test_logmnr(a number);
SQL> conn hr/hr
Connected.
SQL> create table test_logmnr(a number);
Table created.
SQL> insert into test_logmnr values(1);
1 row created.
SQL> insert into test_logmnr values(2);
1 row created.
SQL> insert into test_logmnr values(3);
1 row created.
SQL> insert into test_logmnr values(4);
1 row created.
SQL> commit;
Commit complete.
@@@
@@@Second: create a shell for check
@@@
[oracle@station78 ~]$ vim logminor_redo_undo.sh
####begin_4-1######################################################
#!/bin/sh
#@$ORACLE_HOME/rdbms/admin/dbmslm.sql
#@$ORACLE_HOME/rdbms/admin/dbmslmd.sql
sqlplus /nolog <<EOF > /home/oracle/redo.sql
conn /as sysdba;
set heading off;
@/home/oracle/logmnr.sql
select sql_redo from v\$logmnr_contents where username = 'HR';
quit
EOF
sqlplus /nolog <<EOF > /home/oracle/undo.sql
conn /as sysdba;
set heading off;
@/home/oracle/logmnr.sql
select sql_undo from v\$logmnr_contents where username = 'HR';
quit
EOF
######end_4-1###############################################
@@@
[oracle@station78 ~]$ vim logmnr.sql
####begin_4-2##########################################
execute dbms_logmnr_d.build( -
dictionary_filename => 'test1.dat', -
dictionary_location => '/u01/app/oracle/oradata/orcl');
execute dbms_logmnr.add_logfile( -
LogFileName => '/u01/app/oracle/oradata/orcl/redo01.log', -
Options => dbms_logmnr.new);
execute dbms_logmnr.add_logfile( -
LogFileName => '/u01/app/oracle/oradata/orcl/redo02.log', -
Options => dbms_logmnr.addfile);
execute dbms_logmnr.add_logfile( -
LogFileName => '/u01/app/oracle/oradata/orcl/redo03.log', -
Options => dbms_logmnr.addfile);
execute dbms_logmnr.start_logmnr(-
Options => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG + -
DBMS_LOGMNR.COMMITTED_DATA_ONLY + -
DBMS_LOGMNR.PRINT_PRETTY_SQL );
/
######end_4-2#########################################
@@@
[oracle@station78 ~]$ ./logminor_redo_undo.sh
[oracle@station78 ~]$
@@@
@@@Thrid: check v$logmnr_contents
@@@
@@@check the redo.sql
####begin_4-3############################################
[oracle@station78 ~]$ cat redo.sql
SQL*Plus: Release 10.2.0.1.0 - Production on Wed May 9 19:28:33 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> Connected.
SQL> SQL>
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
SP2-0103: Nothing in SQL buffer to run.
SQL>
set transaction read write;
update "SYS"."OBJ$"
set
"OBJ#" = 1,
"DATAOBJ#" = 54266,
"TYPE#" = 0,
"CTIME" = TO_DATE('2005-10-22:21:44:33', 'yyyy-mm-dd:hh24:mi:ss'),
"MTIME" = TO_DATE('2012-05-09:19:28:07', 'yyyy-mm-dd:hh24:mi:ss'),
"STIME" = TO_DATE('2005-10-22:21:44:33', 'yyyy-mm-dd:hh24:mi:ss'),
"STATUS" = 0,
"FLAGS" = 0,
"OID$" = NULL,
"SPARE1" = 0,
"SPARE2" = 65535
where
"OBJ#" = 1 and
"DATAOBJ#" = 54256 and
"TYPE#" = 0 and
"CTIME" = TO_DATE('2005-10-22:21:44:33', 'yyyy-mm-dd:hh24:mi:ss') and
"MTIME" = TO_DATE('2012-05-08:22:28:18', 'yyyy-mm-dd:hh24:mi:ss') and
"STIME" = TO_DATE('2005-10-22:21:44:33', 'yyyy-mm-dd:hh24:mi:ss') and
"STATUS" = 0 and
"FLAGS" = 0 and
"OID$" IS NULL and
"SPARE1" = 0 and
"SPARE2" = 65535 and
ROWID = 'AAAAASAABAAAAB6AAa';
commit;
set transaction read write;
commit;
set transaction read write;
insert into "SYS"."SEG$"
values
"TS#" = 4,
"FILE#" = 4,
"BLOCK#" = 619,
"TYPE#" = 3,
"BLOCKS" = 8,
"EXTENTS" = 1,
"INIEXTS" = 8,
"MINEXTS" = 1,
"MAXEXTS" = 2147483645,
"EXTSIZE" = 128,
"EXTPCT" = 0,
"USER#" = 55,
"LISTS" = 0,
"GROUPS" = 0,
"BITMAPRANGES" = 0,
"CACHEHINT" = 0,
"SCANHINT" = 0,
"HWMINCR" = 54256,
"SPARE1" = 131329,
"SPARE2" IS NULL;
update "SYS"."TSQ$"
set
"GRANTOR#" = 0,
"BLOCKS" = 496,
"MAXBLOCKS" = 0,
"PRIV1" = 0,
"PRIV2" = 0,
"PRIV3" = 0
where
"USER#" = 55 and
"GRANTOR#" = 0 and
"BLOCKS" = 488 and
"MAXBLOCKS" = 0 and
"PRIV1" = 0 and
"PRIV2" = 0 and
"PRIV3" = 0 and
ROWID = 'AAAAAKAABAAAABcAAL';
commit;
set transaction read write;
commit;
set transaction read write;
commit;
set transaction read write;
insert into "SYS"."OBJ$"
values
"OBJ#" = 54256,
"DATAOBJ#" = 54256,
"OWNER#" = 55,
"NAME" = 'TEST_LOGMNR',
"NAMESPACE" = 1,
"SUBNAME" IS NULL,
"TYPE#" = 2,
"CTIME" = TO_DATE('2012-05-09:19:28:07', 'yyyy-mm-dd:hh24:mi:ss'),
"MTIME" = TO_DATE('2012-05-09:19:28:07', 'yyyy-mm-dd:hh24:mi:ss'),
"STIME" = TO_DATE('2012-05-09:19:28:07', 'yyyy-mm-dd:hh24:mi:ss'),
"STATUS" = 1,
"REMOTEOWNER" IS NULL,
"LINKNAME" IS NULL,
"FLAGS" = 0,
"OID$" IS NULL,
"SPARE1" = 6,
"SPARE2" = 1,
"SPARE3" IS NULL,
"SPARE4" IS NULL,
"SPARE5" IS NULL,
"SPARE6" IS NULL;
insert into "SYS"."TAB$"
values
"OBJ#" = 54256,
"DATAOBJ#" = 54256,
"TS#" = 4,
"FILE#" = 4,
"BLOCK#" = 619,
"BOBJ#" IS NULL,
"TAB#" IS NULL,
"COLS" = 1,
"CLUCOLS" IS NULL,
"PCTFREE$" = 10,
"PCTUSED$" = 40,
"INITRANS" = 1,
"MAXTRANS" = 255,
"FLAGS" = 1073741825,
"AUDIT$" = '--------------------------------------',
"ROWCNT" IS NULL,
"BLKCNT" IS NULL,
"EMPCNT" IS NULL,
"AVGSPC" IS NULL,
"CHNCNT" IS NULL,
"AVGRLN" IS NULL,
"AVGSPC_FLB" IS NULL,
"FLBCNT" IS NULL,
"ANALYZETIME" IS NULL,
"SAMPLESIZE" IS NULL,
"DEGREE" IS NULL,
"INSTANCES" IS NULL,
"INTCOLS" = 1,
"KERNELCOLS" = 1,
"PROPERTY" = 536870912,
"TRIGFLAG" = 0,
"SPARE1" = 736,
"SPARE2" IS NULL,
"SPARE3" IS NULL,
"SPARE4" IS NULL,
"SPARE5" IS NULL,
"SPARE6" = TO_DATE('2012-05-09:19:28:07', 'yyyy-mm-dd:hh24:mi:ss');
insert into "SYS"."COL$"
values
"OBJ#" = 54256,
"COL#" = 1,
"SEGCOL#" = 1,
"SEGCOLLENGTH" = 22,
"OFFSET" = 0,
"NAME" = 'A',
"TYPE#" = 2,
"LENGTH" = 22,
"FIXEDSTORAGE" = 0,
"PRECISION#" IS NULL,
"SCALE" IS NULL,
"NULL$" = 0,
"DEFLENGTH" IS NULL,
"SPARE6" IS NULL,
"INTCOL#" = 1,
"PROPERTY" = 0,
"CHARSETID" = 0,
"CHARSETFORM" = 0,
"SPARE1" = 0,
"SPARE2" = 0,
"SPARE3" = 0,
"SPARE4" IS NULL,
"SPARE5" IS NULL,
"DEFAULT$" IS NULL;
create table test_logmnr(a number);
update "SYS"."SEG$"
set
"TYPE#" = 5,
"BLOCKS" = 8,
"EXTENTS" = 1,
"INIEXTS" = 8,
"MINEXTS" = 1,
"MAXEXTS" = 2147483645,
"EXTSIZE" = 128,
"EXTPCT" = 0,
"USER#" = 55,
"LISTS" = 0,
"GROUPS" = 0,
"CACHEHINT" = 0,
"SCANHINT" = 0,
"HWMINCR" = 54256,
"SPARE1" = 131329
where
"TS#" = 4 and
"FILE#" = 4 and
"BLOCK#" = 619 and
"TYPE#" = 3 and
"BLOCKS" = 8 and
"EXTENTS" = 1 and
"INIEXTS" = 8 and
"MINEXTS" = 1 and
"MAXEXTS" = 2147483645 and
"EXTSIZE" = 128 and
"EXTPCT" = 0 and
"USER#" = 55 and
"LISTS" = 0 and
"GROUPS" = 0 and
"CACHEHINT" = 0 and
"SCANHINT" = 0 and
"HWMINCR" = 54256 and
"SPARE1" = 131329 and
ROWID = 'AAAAAIAABAAAOsPAAb';
commit;
set transaction read write;
insert into "HR"."TEST_LOGMNR"
values
"A" = 1;
insert into "HR"."TEST_LOGMNR"
values
"A" = 2;
insert into "HR"."TEST_LOGMNR"
values
"A" = 3;
insert into "HR"."TEST_LOGMNR"
values
"A" = 4;
commit;
27 rows selected.
SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
######end_4-3############################################
@@@check undo.sql
####begin_4-3############################################
[oracle@station78 ~]$ cat undo.sql
SQL*Plus: Release 10.2.0.1.0 - Production on Wed May 9 19:28:37 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> Connected.
SQL> SQL>
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
SP2-0103: Nothing in SQL buffer to run.
SQL>
update "SYS"."OBJ$"
set
"OBJ#" = 1,
"DATAOBJ#" = 54256,
"TYPE#" = 0,
"CTIME" = TO_DATE('2005-10-22:21:44:33', 'yyyy-mm-dd:hh24:mi:ss'),
"MTIME" = TO_DATE('2012-05-08:22:28:18', 'yyyy-mm-dd:hh24:mi:ss'),
"STIME" = TO_DATE('2005-10-22:21:44:33', 'yyyy-mm-dd:hh24:mi:ss'),
"STATUS" = 0,
"FLAGS" = 0,
"OID$" = NULL,
"SPARE1" = 0,
"SPARE2" = 65535
where
"OBJ#" = 1 and
"DATAOBJ#" = 54266 and
"TYPE#" = 0 and
"CTIME" = TO_DATE('2005-10-22:21:44:33', 'yyyy-mm-dd:hh24:mi:ss') and
"MTIME" = TO_DATE('2012-05-09:19:28:07', 'yyyy-mm-dd:hh24:mi:ss') and
"STIME" = TO_DATE('2005-10-22:21:44:33', 'yyyy-mm-dd:hh24:mi:ss') and
"STATUS" = 0 and
"FLAGS" = 0 and
"OID$" IS NULL and
"SPARE1" = 0 and
"SPARE2" = 65535 and
ROWID = 'AAAAASAABAAAAB6AAa';
delete from "SYS"."SEG$"
where
"TS#" = 4 and
"FILE#" = 4 and
"BLOCK#" = 619 and
"TYPE#" = 3 and
"BLOCKS" = 8 and
"EXTENTS" = 1 and
"INIEXTS" = 8 and
"MINEXTS" = 1 and
"MAXEXTS" = 2147483645 and
"EXTSIZE" = 128 and
"EXTPCT" = 0 and
"USER#" = 55 and
"LISTS" = 0 and
"GROUPS" = 0 and
"BITMAPRANGES" = 0 and
"CACHEHINT" = 0 and
"SCANHINT" = 0 and
"HWMINCR" = 54256 and
"SPARE1" = 131329 and
"SPARE2" IS NULL and
ROWID = 'AAAAAIAABAAAOsPAAb';
update "SYS"."TSQ$"
set
"GRANTOR#" = 0,
"BLOCKS" = 488,
"MAXBLOCKS" = 0,
"PRIV1" = 0,
"PRIV2" = 0,
"PRIV3" = 0
where
"USER#" = 55 and
"GRANTOR#" = 0 and
"BLOCKS" = 496 and
"MAXBLOCKS" = 0 and
"PRIV1" = 0 and
"PRIV2" = 0 and
"PRIV3" = 0 and
ROWID = 'AAAAAKAABAAAABcAAL';
delete from "SYS"."OBJ$"
where
"OBJ#" = 54256 and
"DATAOBJ#" = 54256 and
"OWNER#" = 55 and
"NAME" = 'TEST_LOGMNR' and
"NAMESPACE" = 1 and
"SUBNAME" IS NULL and
"TYPE#" = 2 and
"CTIME" = TO_DATE('2012-05-09:19:28:07', 'yyyy-mm-dd:hh24:mi:ss') and
"MTIME" = TO_DATE('2012-05-09:19:28:07', 'yyyy-mm-dd:hh24:mi:ss') and
"STIME" = TO_DATE('2012-05-09:19:28:07', 'yyyy-mm-dd:hh24:mi:ss') and
"STATUS" = 1 and
"REMOTEOWNER" IS NULL and
"LINKNAME" IS NULL and
"FLAGS" = 0 and
"OID$" IS NULL and
"SPARE1" = 6 and
"SPARE2" = 1 and
"SPARE3" IS NULL and
"SPARE4" IS NULL and
"SPARE5" IS NULL and
"SPARE6" IS NULL and
ROWID = 'AAAAASAABAAAMVuAAH';
delete from "SYS"."TAB$"
where
"OBJ#" = 54256 and
"DATAOBJ#" = 54256 and
"TS#" = 4 and
"FILE#" = 4 and
"BLOCK#" = 619 and
"BOBJ#" IS NULL and
"TAB#" IS NULL and
"COLS" = 1 and
"CLUCOLS" IS NULL and
"PCTFREE$" = 10 and
"PCTUSED$" = 40 and
"INITRANS" = 1 and
"MAXTRANS" = 255 and
"FLAGS" = 1073741825 and
"AUDIT$" = '--------------------------------------' and
"ROWCNT" IS NULL and
"BLKCNT" IS NULL and
"EMPCNT" IS NULL and
"AVGSPC" IS NULL and
"CHNCNT" IS NULL and
"AVGRLN" IS NULL and
"AVGSPC_FLB" IS NULL and
"FLBCNT" IS NULL and
"ANALYZETIME" IS NULL and
"SAMPLESIZE" IS NULL and
"DEGREE" IS NULL and
"INSTANCES" IS NULL and
"INTCOLS" = 1 and
"KERNELCOLS" = 1 and
"PROPERTY" = 536870912 and
"TRIGFLAG" = 0 and
"SPARE1" = 736 and
"SPARE2" IS NULL and
"SPARE3" IS NULL and
"SPARE4" IS NULL and
"SPARE5" IS NULL and
"SPARE6" = TO_DATE('2012-05-09:19:28:07', 'yyyy-mm-dd:hh24:mi:ss') and
ROWID = 'AAAAACAABAAAN0TAAB';
delete from "SYS"."COL$"
where
"OBJ#" = 54256 and
"COL#" = 1 and
"SEGCOL#" = 1 and
"SEGCOLLENGTH" = 22 and
"OFFSET" = 0 and
"NAME" = 'A' and
"TYPE#" = 2 and
"LENGTH" = 22 and
"FIXEDSTORAGE" = 0 and
"PRECISION#" IS NULL and
"SCALE" IS NULL and
"NULL$" = 0 and
"DEFLENGTH" IS NULL and
"SPARE6" IS NULL and
"INTCOL#" = 1 and
"PROPERTY" = 0 and
"CHARSETID" = 0 and
"CHARSETFORM" = 0 and
"SPARE1" = 0 and
"SPARE2" = 0 and
"SPARE3" = 0 and
"SPARE4" IS NULL and
"SPARE5" IS NULL and
"DEFAULT$" IS NULL and
ROWID = 'AAAAACAABAAAN0TAAB';
update "SYS"."SEG$"
set
"TYPE#" = 3,
"BLOCKS" = 8,
"EXTENTS" = 1,
"INIEXTS" = 8,
"MINEXTS" = 1,
"MAXEXTS" = 2147483645,
"EXTSIZE" = 128,
"EXTPCT" = 0,
"USER#" = 55,
"LISTS" = 0,
"GROUPS" = 0,
"CACHEHINT" = 0,
"SCANHINT" = 0,
"HWMINCR" = 54256,
"SPARE1" = 131329
where
"TS#" = 4 and
"FILE#" = 4 and
"BLOCK#" = 619 and
"TYPE#" = 5 and
"BLOCKS" = 8 and
"EXTENTS" = 1 and
"INIEXTS" = 8 and
"MINEXTS" = 1 and
"MAXEXTS" = 2147483645 and
"EXTSIZE" = 128 and
"EXTPCT" = 0 and
"USER#" = 55 and
"LISTS" = 0 and
"GROUPS" = 0 and
"CACHEHINT" = 0 and
"SCANHINT" = 0 and
"HWMINCR" = 54256 and
"SPARE1" = 131329 and
ROWID = 'AAAAAIAABAAAOsPAAb';
delete from "HR"."TEST_LOGMNR"
where
"A" = 1 and
ROWID = 'AAANPwAAEAAAAJtAAA';
delete from "HR"."TEST_LOGMNR"
where
"A" = 2 and
ROWID = 'AAANPwAAEAAAAJtAAB';
delete from "HR"."TEST_LOGMNR"
where
"A" = 3 and
ROWID = 'AAANPwAAEAAAAJtAAC';
delete from "HR"."TEST_LOGMNR"
where
"A" = 4 and
ROWID = 'AAANPwAAEAAAAJtAAD';
27 rows selected.
SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
######end_4-3############################################
本文出自 “Oracle+Linux=>Majesty” 博客,谢绝转载!