Section 1 : How to enable archive logging in oracle 11g
Method 1 : Using Alter system command
ALTER SYSTEM SET log_archive_start=TRUE SCOPE=spfile;
ALTER SYSTEM SET log_archive_dest=’/u01/oradata/MYSID/archive/’ SCOPE=spfile;
ALTER SYSTEM SET log_archive_format=’arch_%r_%t_%s.arc’ SCOPE=spfile;
SHUTDOWN IMMEDIATE;
STARTUP MOUNT;
ARCHIVE LOG START;
ALTER DATABASE ARCHIVELOG;
ALTER DATABASE OPEN;
archive log list
alter system switch logfile; –> This will create archive logfile
Method 2 : By modifying the parameter file.
create pfile=’/tmp/mypfile.ora’ from spfile;
vi mypfile.ora
Add following lines to the mypfile.ora
log_archive_start=TRUE
log_archive_format = ‘arch_%r_%t_%s.arc’
log_archive_dest = <localtion> #the location must be accessible to oracle.
shutdown immediate
startup nomount pfile =’/tmp/mypfile’ora’
cd $ORALCE_HOME and check there is any spfile<SID>.ora file exist or not
if yes then take the backup
create spfile = ‘oracle_home/database/spfile<sid>.ora’ from pfile =’/tmp/mypfile’ora’
shutdown immediate
startup
archive log list
Section 2 : Steps to implement Logminer
Step 1 : Enable Archive Logging as explained in Section 1.
Step 2 : Insert some values in the mytest table.
SQL> insert into mytest values(&id,’&name’);
Enter value for id: 1
Enter value for name: asd
old 1: insert into mytest values(&id,’&name’)
new 1: insert into mytest values(1,’asd’)
1 row created.
SQL> /
Enter value for id: 2
Enter value for name: qwer
old 1: insert into mytest values(&id,’&name’)
new 1: insert into mytest values(2,’qwer’)
1 row created.
SQL> /
Enter value for id: 3
Enter value for name: zxcv
old 1: insert into mytest values(&id,’&name’)
new 1: insert into mytest values(3,’zxcv’)
1 row created.
Step 3 :
SQL> commit;
Step 4 : Create the archive log file immediately.
SQL> alter system switch logfile;
===============================================================================
Step 5 : Create a user with role, which will be given all the privileges to use log miner.
SQL> create role logmnr_admin;
SQL> grant create session to logmnr_admin;
SQL> grant select on v_$logmnr_contents to logmnr_admin;
SQL> grant select on v_$logmnr_parameters to logmnr_admin;
SQL> grant select on v_$logmnr_logs to logmnr_admin;
SQL> grant select on v_$archived_log to logmnr_admin;
SQL> grant execute_catalog_role, select any dictionary, select any transaction, select any table, create tablespace, drop tablespace to logmnr_admin;
SQL> create user miner identified by miner;
SQL> grant logmnr_admin to miner;
SQL> alter user miner quota unlimited on users;
Step 6 : Enable Supplemental logging.
SQL> alter database add supplemental log data;
http://docs.oracle.com/cd/B19306_01/server.102/b14215/logminer.htm#i1021068
Step 7 : Ensure that supplemental logging has been enabled.
SQL> select supplemental_log_data_min from v$database;
The result of above query should be YES.
Step 8 : Specify a LogMiner dictionary. ( http://docs.oracle.com/cd/B19306_01/server.102/b14215/logminer.htm#i1015913)
In this step, their are three options :
a) Using the Online Catalog
b) Extracting LogMiner dictionary to Redo Log files.
c) Extracting LogMiner dictionary to a Flat file.
Steps for Scenario 8(a) : Online catalog can be directly specified in the subsequent steps when we start the log miner.
Step for Scenario 8 (c) :
i) Create a directory where dictionary file will be created.
mkdir /home/oracle/logmnr
ii) Set the utl_file_dir parameter. This is the location where dictionary file will be created.
SQL> alter system set utl_file_dir=’/home/oracle/logmnr’ scope=spfile;
iii) Restart the database.
iv) Execute DBMS_LOGMNR_D.BUILD(‘dictionary.ora’, ‘/home/oracle/logmnr’, options => dbms_logmnr_d.store_in_flat_file);
Note : /home/oracle/logmnr should be same as utl_file_dir
Step 9 : Find the archive log (created in step 4 of Section 2) that you want to use to mine.
SQL> SELECT name, TO_CHAR(first_time, ‘DD-MON-YYYY HH24:MI:SS’) first_time
FROM v$archived_log
WHERE name IS NOT NULL AND first_time BETWEEN TO_DATE(’20-MAR-2013 08:00:00′, ‘DD-MON-YYYY HH24:MI:SS’)
AND TO_DATE(’20-MAR-2013 10:59:00′, ‘DD-MON-YYYY HH24:MI:SS’)
ORDER BY sequence#;
Step 10 : Add log files to the logminer for mining.
In this step their are two ways of adding log files.
a) Manually adding each file.
b) Automatically.
Steps for Scenario 10(a) :
i) Execute dbms_logmnr.add_logfile(LogFileName=>’/u01/oradata/MYSID/archive/arch_803914076_1_22_.arc’, Options=>dbms_logmnr.NEW); –Adds first file.
Execute dbms_logmnr.add_logfile(LogFileName=>’/u01/oradata/MYSID/archive/arch_803914076_1_23.arc’, Options=>dbms_logmnr.ADDFILE); –Adds second file.
And so on….
Steps for Scenario 10(b) :
i) Files can be automatically added using the CONTINUOUS_MINE option of the start_logmnr procedure, which is explained in next step (Step 11).
Step 11 : Start LogMiner.
Follwing are the different ways of starting logminer based on dictionary used :
a) If Flat file is used for LogMiner dictionary ( Section 2 : Step 8 : Scenario (c))
i) Execute DBMS_LOGMNR.START_LOGMNR(dictfilename => ‘/home/oracle/logmnr/dictionary.ora’); — uses the added log file for mining.
b) If Online catalog is used ( Section 2 : Step 8 : Scenario (a))
i) Execute DBMS_LOGMNR.START_LOGMNR(OPTIONS => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG); — uses the added log file for mining.
c) Using CONTINUOUS_MINE
i) Alter session set NLS_DATE_FORMAT = ‘DD-MON-YYYY HH24:MI:SS’;
Execute DBMS_LOGMNR.START_LOGMNR(STARTTIME => ’19-MAR-2013 14:02:14′, ENDTIME => SYSDATE, OPTIONS => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG + DBMS_LOGMNR.CONTINUOUS_MINE ); –uses the log files between specified times and performs continuous mine.
Step 12 : Request the Redo data of interest.Query the V$LOGMNR_CONTENTS view. (You must have the SELECT ANY TRANSACTION privilege to query this view.)
SQL> SELECT username, operation,
DBMS_LOGMNR.MINE_VALUE(REDO_VALUE,’SCHEMA.TABLENAME.COLNAME’) REDO VALUE,
DBMS_LOGMNR.MINE_VALUE(UNDO_VALUE,’SCHEMA.TABLENAME.COLNAME’) UNDO VALUE,
sql_redo,
sql_undo,
TO_CHAR(timestamp, ‘DD-MON-YYYY HH24:MI:SS’) timestamp,
scn
FROM
v$logmnr_contents
WHERE
username = ‘SCOTT’
AND operation = ‘INSERT’
AND seg_owner = ‘SCOTT’;
Step 13 : Stop the miner
SQL> DBMS_LOGMNR.END_LOGMNR();
http://docs.oracle.com/cd/B19306_01/server.102/b14215/logminer.htm#i1015913