How to use Oracle Logminer to analysis Logfile
We know that any changes to database is recored in online redo logfiles.
If your database archival mode on then online redo log files are archived which contains the database changes.
With these logfile we can analysis any changes in database.
In simple we can say an undo entry provides the values of data stored
before a change and the redo entry provides the values of data stored after a change.
Because undo segments are database changes, they also generate redo entries.
So we can get them from online redo logs and then to archived logs.
So from online redo logs and from archived redo logs we can get database redo and undo information.
But online and archived logs have an unpublished format and are not human-readable.
With the DBMS_LOGMNR package we can analysis redo log files and can get
back undo and redo information in a human readable format.
Another scenario of use of logminer is to investigate database past in time.
With Flashback Query we can get prior values of the record in the table at
some point in the past but is limited to UNDO_RETENTION parameter
(which is often as short as 30 minutes for an OLTP database.).
So in order to analysis past activity on the database logminer is a good choice.
In this step I will show you the step by step procedure how we can use logminer.
1)Ensure that you have on at a minimal level supplemental logging
To work with logminer you must have database supplemental logging
on of the source database at a minimum level.By default,
Oracle Database does not provide any supplemental logging,
which means that by default LogMiner is not usable. To make it use you need to on it.
You can check your supplemental logging on of off by following commands,
SQL> select SUPPLEMENTAL_LOG_DATA_MIN from v$database;
In order to on it at a minimal level,
SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
2)Install the DBMS_LOGMNR package.
The next step is to install DBMS_LOGMNR package.
If you have already installed then ignore this steps.
You can install this package by running $ORACLE_HOME/rdbms/admin/dbmslm.sql script.
If you create your database with dbca then this script run automatically.
So you can ignore this step.
However if you create database manually with CREATE DATABASE … command
then you must run the script before using logminer. That is ,
3)Grant the EXECUTE_CATALOG_ROLE role.
The user who will do the mining task give him EXECUTE_CATALOG_ROLE. Here user is ARJU.
SQL>GRANT EXECUTE_CATALOG_ROLE TO ARJU;
4)Create the synonym. ARJU creates a public synonym:
CREATE PUBLIC SYNONYM DBMS_LOGMNR FOR SYS.DBMS_LOGMNR;
All above four steps are needed just for once.
5)Specify the scope of the mining.
Now you decide on which file you will do the analysis.
You may have interest over archived redo log files or online redo log files based on your scenario.
In this post suppose you have recent problem in your database
and so you might show interest of your online redo log files.
You can see current online redo logs by,
SQL> SELECT distinct member LOGFILENAME FROM V$LOGFILE;
Sometimes, you want to mine the redo log file that was most recently archived.
SQL> SELECT NAME FROM V$ARCHIVED_LOG
WHERE FIRST_TIME = (SELECT MAX(FIRST_TIME) FROM V$ARCHIVED_LOG);
With the DBMS_LOGMNR.ADD_LOGFILE specify those files that you want to mine.
Here I have given the online redo log files redo01.log and redo03.log.
6)Start the LogMiner session and specify a dictionary.
To start the LogMiner session:
Using the OPTIONS parameter,
it is specified that Oracle Database read the dictionary information
to convert the object names from the online catalog while starting LogMiner.
7)Check contents from V$LOGMNR_CONTENTS view.
To get information and when DML or DDL happened in the V$LOGMNR_CONTENTS about table TEST3 we can issue
SQL> select username, to_char(timestamp,'mm/dd/yy hh24:mi:ss') timestamp,
seg_type_name, seg_name, table_space, session# SID, serial# , operation
where table_name = 'TEST3';
USERNAM TIMESTAMP SEG_TY SEG_NAME TABLE_SPAC SID SERIAL# OPERATION
——- —————– —— ———- ———- ———- ———- ——————————–
08/03/08 02:57:35 TABLE TEST3 153 3272 DDL
08/03/08 02:57:41 TABLE TEST3 SYSTEM 153 3272 INSERT
08/03/08 02:57:55 TABLE TEST3 SYSTEM 153 3272 UPDATE
08/03/08 03:01:35 TABLE TEST3 SYSTEM 153 3272 UPDATE
We can get SQL_UNDO and SQL_REDO information by,
SQL> select sql_undo, sql_redo
where table_name = 'TEST3' and OPERATION='UPDATE';
update "SYS"."TEST3" set "A" = '3' where "A" = '9' update "SYS"."TEST3" set "A" = '9' where "A" = '3'
and ROWID = 'AAAOKVAABAAAP8qAAA'; and ROWID = 'AAAOKVAABAAAP8qAAA';
update "SYS"."TEST3" set "A" = '9' where "A" = '10 update "SYS"."TEST3" set "A" = '10' where "A" = '9
' and ROWID = 'AAAOKVAABAAAP8qAAA'; ' and ROWID = 'AAAOKVAABAAAP8qAAA';
8)End the LogMiner session.
Use the DBMS_LOGMNR.END_LOGMNR procedure.
PL/SQL procedure successfully completed.