Showing posts with label Oracle DB Administration. Show all posts
Showing posts with label Oracle DB Administration. Show all posts

Tuesday 8 April 2014

Steps to configure Oracle 10g Enterprise Manager Database Control

Steps to configure Oracle 10g Enterprise Manager Database Control


1.Ensure that you can connect to the Repository Database. Test it with SQL*Plus or TNSPING Utility.


#> tnsping TESTDB

TNS Ping Utility for Linux: Version 10.2.0.3.0 - Production on 23-FEB-2012 22:13:41

Copyright (c) 1997, 2006, Oracle.  All rights reserved.

Used parameter files:
/spl/intbase/DB/oracletns/sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.52)(PORT = 1521)) (CONNECT_DATA = (SID = TESTDB)))
OK (50 msec)
= TESTDB Shared DB server = oracle@testdb.sangam.com /orasw/app/oracle/product/10.2.0.3/bin

2. Change the %ORACLE_HOME%\network\admin\listener.ora file from an IP number to machine name.

3. Change the %ORACLE_HOME%\network\admin\tnsnames.ora file from an IP number to a machine name.

4. Change the C:\WINDOWS\System32\drivers\etc\hosts file by adding this line beneath the default localhost line (for the new Hostname value):

127.0.0.1       localhost
192.168.0.52  saidrasel saidrasel

5. Unlock the SYSMAN account because it ensures that emca can drop it and all dependencies. Then, drop the em configuration with the following commands.

C:\Data> set ORACLE_SID=orcl
C:\Data> emca -deconfig dbcontrol db -repos drop

6. You’ll receive the following prompts, enter the Oracle SID and Port number without double quotes but you must enter all passwords with double quotes (at least in Oracle Database 11g):

Oracle Database 11gR1

STARTED EMCA at Jul 13, 2008 8:26:42 AM
EM Configuration Assistant, Version 11.1.0.5.0 Production
Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Enter the following information:
Database SID: orcl
Listener port number: 1521
Password for SYS user:
Password for SYSMAN user:
Password for SYSMAN user:
Do you wish to continue? [yes(Y)/no(N)]: y

Oracle Database 11gR2

STARTED EMCA at Sep 3, 2012 7:40:07 PM
EM Configuration Assistant, Version 11.2.0.0.2 Production
Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Enter the following information:
Database SID: orcl
Listener port number: 1521
Password for SYS user:
Password for SYSMAN user:

Do you wish to continue? [yes(Y)/no(N)]: y


7. If you failed to unlock the SYSMAN account in step #5, you should drop the SYSMAN user manually. If you don’t drop the SYSMAN schema, you’ll raise an error when you try to recreate it:

CONFIG: ORA-20001: SYSMAN already EXISTS..
ORA-06512: at line 17

oracle.sysman.assistants.util.sqlEngine.SQLFatalErrorException: ORA-20001: SYSMAN already EXISTS..
ORA-06512: at line 17
The Java stack trace will look like this, more or less based on version and release:

at oracle.sysman.assistants.util.sqlEngine.SQLEngine.executeImpl(SQLEngine.java:1530)
at oracle.sysman.assistants.util.sqlEngine.SQLEngine.executeScript(SQLEngine.java:880)
at oracle.sysman.assistants.util.sqlEngine.SQLPlusEngine.executeScript(SQLPlusEngine.java
at oracle.sysman.assistants.util.sqlEngine.SQLPlusEngine.executeScript(SQLPlusEngine.java
at oracle.sysman.emcp.EMReposConfig.createRepository(EMReposConfig.java:492)
at oracle.sysman.emcp.EMReposConfig.invoke(EMReposConfig.java:218)
at oracle.sysman.emcp.EMReposConfig.invoke(EMReposConfig.java:147)
at oracle.sysman.emcp.EMConfig.perform(EMConfig.java:222)
at oracle.sysman.emcp.EMConfigAssistant.invokeEMCA(EMConfigAssistant.java:535)
at oracle.sysman.emcp.EMConfigAssistant.performConfiguration(EMConfigAssistant.java:1215)
at oracle.sysman.emcp.EMConfigAssistant.statusMain(EMConfigAssistant.java:519)
at oracle.sysman.emcp.EMConfigAssistant.main(EMConfigAssistant.java:468)
Drop the user and dependent on version a few other objects, like:

DROP USER sysman CASCADE;
DROP PUBLIC SYNONYM setemviewusercontext;
DROP ROLE mgmt_user;
DROP PUBLIC SYNONYM mgmt_target_blackouts;
DROP USER mgmt_view;

8. You can then create the em environment with the following syntax:

C:\Data> emca -config dbcontrol db -repos create

9. Again, you’ll receive the following prompts, enter the Oracle SID and Port number without double quotes but you must enter all passwords with double quotes (at least in Oracle Database 11g):

STARTED EMCA at Jul 13, 2008 8:28:48 AM
EM Configuration Assistant, Version 11.1.0.5.0 Production
Copyright (c) 2003, 2005, Oracle.  ALL rights reserved.

Enter the following information:
DATABASE SID: orcl
Listener port NUMBER: 1521
Password FOR SYS USER:
Password FOR DBSNMP USER:
Password FOR SYSMAN USER:
Password FOR SYSMAN USER: Email address FOR notifications (optional):
Outgoing Mail (SMTP) server FOR notifications (optional):
-----------------------------------------------------------------

You have specified the following settings

DATABASE ORACLE_HOME ................ C:\app\Administrator\product\11.1.0\db_1

LOCAL hostname ................ mclaughlin11g
Listener port NUMBER ................ 1521
DATABASE SID ................ orcl
Email address FOR notifications ...............
Outgoing Mail (SMTP) server FOR notifications ...............

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

Do you wish TO continue? [yes(Y)/no(N)]: y

Monday 24 March 2014

Oracle alert ORA-28 error in alert log

How to I fix the ORA-28 error?

Answer:  The oerr utility shows this for the ORA-28 aborting process error:

Reason: ORA 28:  Your session has been killed. A privileged user killed the session and it is no longer logged in to the database.

Action: The administrator may be attempting to perform an operation that 
requires users to be logged out.  When the database administrator announces that the database 
is available, log in and resume work.

Saturday 22 March 2014

Step by Step to change the Redo Log File size online in Oracle Database

Step by Step to change the Redo Log File size online in Oracle Database

Step1:

SQL> SELECT a.group#, a.member, b.bytes
  2  FROM v$logfile a, v$log b WHERE a.group# = b.group#;

Step2: Make the last redo log CURRENT

SQL> select group#, status from v$log;

    GROUP# STATUS
---------- ----------------
         1 CURRENT
         2 INACTIVE
         3 INACTIVE

SQL> alter system switch logfile;

SQL> alter system switch logfile;

SQL> select group#, status from v$log;

    GROUP# STATUS
---------- ----------------
         1 INACTIVE
         2 INACTIVE
         3 CURRENT

Step3: Drop first redo log

After making the last online redo log file the CURRENT one, drop the first online redo log:


SQL> alter database drop logfile group 1;

Database altered.  


Step4: Precaution

As a DBA, you should already be aware that if you are going to drop a logfile group, 
it cannot be the current logfile group. I have run into instances; however, where 
attempting to drop the logfile group resulted in the following error as a result of 
the logfile group having an active status:

SQL> ALTER DATABASE DROP LOGFILE GROUP 1;
ALTER DATABASE DROP LOGFILE GROUP 1
*
ERROR at line 1:
ORA-01624: log 1 needed for crash recovery of instance ORA920 (thread 1)
ORA-00312: online log 1 thread 1: ''
Easy problem to resolve. Simply perform a checkpoint on the database:

SQL> ALTER SYSTEM CHECKPOINT GLOBAL;

System altered.

SQL> ALTER DATABASE DROP LOGFILE GROUP 1;

Database altered.

Step5: Re-create dropped online redo log group

Re-create the dropped redo log group with different size (if desired):


SQL> alter database add logfile group 1 (
  2  '/data01/oradata/orcl/redo_g01a.log',  
  3  '/data02/oradata/orcl/redo_g01b.log',
  4  '/data03/oradata/orcl/redo_g01c.log') size 250m reuse;

Database altered.

Step6: Force another log switch

SQL> select group#, status from v$log;

    GROUP# STATUS
---------- ----------------
         1 UNUSED
         2 INACTIVE
         3 CURRENT

SQL> alter system switch logfile;

SQL> select group#, status from v$log;

    GROUP# STATUS
---------- ----------------
         1 CURRENT
         2 INACTIVE
         3 ACTIVE

Ref: http://www.idevelopment.info/data/Oracle/DBA_tips/Database_Administration/DBA_34.shtml

Wednesday 12 March 2014

Enable Automatic Shared Memory Management in Oracle

Enable Automatic Shared Memory Management in Oracle

The Oracle Automatic Shared Memory Management is a feature that automatically readjusts the 
sizes of the main pools (db_cache_size, shared_pool_size, large_pool_size, java_pool_size) 
based on existing workloads. Oracle Automatic Shared Memory Management is enabled by setting:

You must use an spfile for the init.ora values

sga_target parameter is set to a non-zero value

statistics_level parameter set to to TYPICAL (the default) or ALL

To switch to ASMM you need to set the initialization parameters SGA_TARGET to a non-zero 
value which must be less then or equal to value of parameter SGA_MAX_SIZE.

$ sqlplus / as sysdba

SQL> alter system set sga_max_size=35840m scope=spfile;

System altered.

SQL> alter system set sga_target=30720m scope=spfile;

System altered.

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup
ORACLE instance started.

Total System Global Area 3.7413E+10 bytes
Fixed Size                  2236168 bytes
Variable Size            8053063928 bytes
Database Buffers         2.9259E+10 bytes
Redo Buffers               98414592 bytes
Database mounted.
Database opened.

SQL> show parameter sga

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
lock_sga                             boolean     FALSE
pre_page_sga                         boolean     FALSE
sga_max_size                         big integer 35G
sga_target                           big integer 30G
SQL>


memory_target (starting in 11g):  If memory_target  is set, then AMM is enabled:  If memory_target is set to non zero value and :sga_target, sga_max_size and pga_aggregate_target are set to 0, then 60% of memory mentioned in memory_target is allocated to SGA and rest 40% is kept for PGA.sga_target and pga_aggregate_target are set to non-zero values, then these values will be considered minimum values.sga_target is set to non zero value and pga_aggregate_target is not set. still these values will be auto-tuned and pga_aggregate_target will be initialized with value of (memory_target-sga_target).pga_aggregate_target is set and sga_target is not set. still both parameters 
will be auto-tuned. The sga_target will be initialized to a value of (memory_target-pga_aggregate_target).


ORA-27102: out of memory Linux-x86_64 Error: 28: No space left on device

Problem

SQL> startup
ORA-27102: out of memory
Linux-x86_64 Error: 28: No space left on device
SQL>

Reason: shmall is too small, most likely is set to the default setting of 2097152 

Solution:

Check the following parameter value

[root@sbldb2 ~]# cat /proc/sys/kernel/shmall
2097152
[root@sbldb2 ~]#

[root@sbldb2 ~]# getconf PAGE_SIZE
4096
[root@sbldb2 ~]#
[root@sbldb2 ~]#  sysctl -p  
[root@sbldb2 ~]# cat /proc/sys/kernel/shmall

Change shmall value as follows

1073741824

Now try to start Database

[oracle@sbldb2 ~]$ sqlplus

SQL*Plus: Release 11.2.0.3.0 Production on Wed Mar 12 18:06:33 2014

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

Enter user-name: /as sysdba
Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area 3.7413E+10 bytes
Fixed Size                  2236168 bytes
Variable Size            8053063928 bytes
Database Buffers         2.9259E+10 bytes
Redo Buffers               98414592 bytes
Database mounted.
Database opened.
SQL>

Enable Automatic Memory Management (AMM) in Oracle Database 11g

Enable Automatic Memory Management (AMM) in Oracle Database 11g

AMM Parameters

memory_target (starting in 11g):  If memory_target  is set, then AMM is enabled:  If memory_target is set to non zero value and :sga_target, sga_max_size and pga_aggregate_target are set to 0, then 60% of memory mentioned in memory_target is allocated to SGA and rest 40% is kept for PGA.sga_target and pga_aggregate_target are set to non-zero values, then these values will be considered minimum values.sga_target is set to non zero value and pga_aggregate_target is not set. still these values will be auto-tuned and pga_aggregate_target will be initialized with value of (memory_target-sga_target).pga_aggregate_target is set and sga_target is not set. still both parameters will be auto-tuned. The sga_target will be initialized to a value of (memory_target-pga_aggregate_target).

Automatic memory management is configured using two new initialization parameters:

MEMORY_TARGET: The amount of shared memory available for Oracle to use when dynamically controlling the SGA and PGA. This parameter is dynamic, so the total amount of memory available to Oracle can be increased or decreased, provided it does not exceed the MEMORY_MAX_TARGET limit. The default value is "0".

MEMORY_MAX_TARGET: This defines the maximum size the MEMORY_TARGET can be increased to without an instance restart. If the MEMORY_MAX_TARGET is not specified, it defaults to MEMORY_TARGET setting.When using automatic memory management, the SGA_TARGET and PGA_AGGREGATE_TARGET act as minimum size settings for their respective memory areas. To allow Oracle to take full control of the memory management, these parameters should be set to zero.

If you are using UNIX/Linux, before you consider using AMM you should check the current size of your shared memory file system. On Linux you do this by issuing the following command.

# df -k /dev/shm
Filesystem           1K-blocks      Used Available Use% Mounted on
tmpfs                  1029884    350916    678968  35% /dev/shm
#

The shared memory file system should be big enough to accommodate the MEMORY_TARGET and 
MEMORY_MAX_TARGET values, or Oracle will throw the following error.

ORA-00845: MEMORY_TARGET not supported on this system To adjust the shared memory file system size issue the following commands, specifying the required size of shared memory.

# umount tmpfs
# mount -t tmpfs shmfs -o size=1200m /dev/shm

Make the setting permanent by amending the "tmpfs" setting of the "/etc/fstab" file to look like this.

tmpfs                   /dev/shm                tmpfs   size=1200m      0 0


Enabling automatic memory management on a system that didn't previously use it is a simple task. Assuming you want to use a similar amount of memory to your current settings you will need to use the following calculation.

MEMORY_TARGET = SGA_TARGET + GREATEST(PGA_AGGREGATE_TARGET, "maximum PGA allocated")

The following queries show you how to display the relevant information and how to combine it in a single statement to calculate the required value.

-- Individual values.
COLUMN name FORMAT A30
COLUMN value FORMAT A10

SELECT name, value
FROM   v$parameter
WHERE  name IN ('pga_aggregate_target', 'sga_target')
UNION
SELECT 'maximum PGA allocated' AS name, TO_CHAR(value) AS value
FROM   v$pgastat
WHERE  name = 'maximum PGA allocated';

-- Calculate MEMORY_TARGET

SELECT sga.value + GREATEST(pga.value, max_pga.value) AS memory_target
FROM (SELECT TO_NUMBER(value) AS value FROM v$parameter WHERE name = 'sga_target') sga,
     (SELECT TO_NUMBER(value) AS value FROM v$parameter WHERE name = 'pga_aggregate_target') pga,
     (SELECT value FROM v$pgastat WHERE name = 'maximum PGA allocated') max_pga;
Assuming our required setting was 5G, we might issue the following statements.

CONN / AS SYSDBA

-- Set the static parameter. Leave some room for possible future growth without restart.

ALTER SYSTEM SET MEMORY_MAX_TARGET=6G SCOPE=SPFILE;

-- Set the dynamic parameters. Assuming Oracle has full control.
ALTER SYSTEM SET MEMORY_TARGET=5G SCOPE=SPFILE;
ALTER SYSTEM SET PGA_AGGREGATE_TARGET=0 SCOPE=SPFILE;
ALTER SYSTEM SET SGA_TARGET=0 SCOPE=SPFILE;

-- Restart instance.
SHUTDOWN IMMEDIATE;
STARTUP;

Once the database is restarted the MEMORY_TARGET parameter can be amended as required without an instance restart.

ALTER SYSTEM SET MEMORY_TARGET=4G SCOPE=SPFILE;



Reference: http://www.oracle-base.com/articles/11g/automatic-memory-management-11gr1.php

Tuesday 4 March 2014

Configure Single Listener with Multiple Database Instance


Configure Single Listener with Multiple Database Instance.

Solution: We can configure Single Oracle Listener and it will associated multiple Database instance  


LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = ora03)(PORT = 1521))
)
)
)

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = CBS)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = CBS)
)
(SID_DESC =
(GLOBAL_DBNAME = IB)
(ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
(SID_NAME = IB)
)
)

Tuesday 25 February 2014

Number of concurrent multiple sessions allowed per user

Number of concurrent multiple sessions allowed per user


sessions_per_user

ALTER PROFILE developer LIMIT sessions_per_user 1;

Monday 24 February 2014

Find Oracle session from Unix/Linux Process ID

Find Oracle session from Unix/Linux Process ID

Step1: Find Linux Process ID using following command
ps -ef 

Step2: Find the Database session information using following query

select s.username,s.sid,s.serial#,p.spid,last_call_et,status
from V$SESSION s,V$PROCESS p
where  s.PADDR = p.ADDR
and     p.spid= 6354;

Step3: Find the SQL text using following query 

select * from v$session_longops t where trunc(t.START_TIME) ='25-FEB-2014' Order by t.START_TIME desc;

Select t.SQL_FULLTEXT from v$sql t where t.SQL_ID='dj3yuw6r7p569';

Wednesday 19 February 2014

Could not drop undo tablespace fails with error Ora-01548 .

Problem Description

Could not drop undo tablespace fails with error Ora-01548 .

SQL> DROP TABLESPACE UNDOTBS1 INCLUDING CONTENTS AND DATAFILES;
DROP TABLESPACE UNDOTBS1 INCLUDING CONTENTS AND DATAFILES
*
ERROR at line 1:
ORA-01548: active rollback segment '_SYSSMU1_1186132793$' found, terminate
dropping tablespace

Cause of The Problem
An attempt was made to drop a tablespace that contains active rollback segments.

Solution of The Problem

In order to get rid of this error you have to follow following steps.

Step1: Find all Undo Segments

select segment_name, tablespace_name, status from dba_rollback_segs where tablespace_name=’UNDOTBS1′

SEGMENT_NAME TABLESPACE_NAME STATUS
—————————— —————————— —————-
_SYSSMU10_820739558$ UNDOTBS1 OFFLINE
_SYSSMU9_2448906239$ UNDOTBS1 OFFLINE
_SYSSMU8_3066916762$ UNDOTBS1 OFFLINE
_SYSSMU7_892861194$ UNDOTBS1 OFFLINE
_SYSSMU6_1956589931$ UNDOTBS1 OFFLINE
_SYSSMU5_2919322705$ UNDOTBS1 OFFLINE
_SYSSMU4_3876247569$ UNDOTBS1 OFFLINE
_SYSSMU3_4245574747$ UNDOTBS1 OFFLINE

Step2: Create pfile if you started with database with spfile.

SQL>Create PFILE from SPFILE;

Step3: Edit pfile and set undo management to manual.
undo_management = manual

Step4: Put the entries of the undo segments in the pfile by using the following statement in the pfile:

_offline_rollback_segments=(_SYSSMU1$,_SYSSMU2$,_SYSSMU3$,.....)

Step5: Mount the database using new pfile.
Startup mount pfile='fullpath to pfile' 

Step6: Drop the datafiles,
sql>Alter Database datafile '&filename' offline drop;

Step7: Open the database.
sql>Alter Database Open;

Step8: Drop the undo segments,

sql>Drop Rollback Segment "_SYSSMU1$";
......
Step9: Drop Old undo tablespace.
sql>Drop Tablespace old_tablespace_name Including Contents;

Step10: Add the new undo tablespace.

Step11:  Shutdown Immediate;

Step12:  Change the pfile parameters back to Undo_management = AUTO and modify the parameter Undo_tablespace=new_undo_tablespace_name and remove the _offline_rollback_segments parameter.

Step13: Startup the Database.

Tuesday 7 January 2014

ORA-1652: unable to extend temp segment by 128 in tablespace

Error: ORA-1652: unable to extend temp segment by 128 in tablespace       TEMP


Cause: Failed to allocate an extent of the required number of blocks for a temporary segment in the tablespace indicated.

Solution:

1. Add a new datafile
alter tablespace   temp
add tempfile '/data01/oradata/stlbas/temp02.dbf' size 10g autoextend on;

alter tablespace   temp
add tempfile '/data02/oradata/stlbas/temp03.dbf' size 15g autoextend on;


2. Drop and create temp tablespace

Monday 9 December 2013

ora-02020: too many database links in use

Error: 

ora-02020: too many database links in use

Reason:

SQL> show parameter link

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
open_links                           integer     4
open_links_per_instance              integer     4
SQL>


Solution:

ALTER SESSION CLOSE DATABASE LINK linkname;
 
Note that this statement only closes the links that are active in your current session. 

Increase the open_links and open_links_instance parameter in the DB . Bounce Database





alter system set open_links =20 scope =spfile;


alter system set open_links_per_instance=20 scope=spfile;

Or

SQL>alter session close database link "link name";




Saturday 30 November 2013

Error ora-01034 ora-27101 linux-x86_64

Error Symptom

Enter user-name: bnsuser/bnsuser@stlbas
ERROR:
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux-x86_64 Error: 2: No such file or directory

Reason:

1. Check ORACLE_HOME is set correctly in listener file or not.
2. Check parameter file name with grep pmon (SID name) is same or not 
3. Check ORACLE_SID

[oracle@stlbasprod2 dbs]$ ps -ef | grep smon
oracle   11654     1  0 11:33 ?        00:00:00 ora_smon_STLBAS
oracle   11830  9978  0 11:45 pts/2    00:00:00 grep smon


[[oracle@stlbasprod2 dbs]$ ps -ef | grep pmon
oracle   11638     1  0 11:32 ?        00:00:00 ora_pmon_STLBAS
oracle   11837  9978  0 11:46 pts/2    00:00:00 grep pmon
[oracle@stlbasprod2 dbs]$

[oracle@stlbasprod2 dbs]$ echo $ORACLE_SID
STLBAS

Action:

1. Change the parameter file name initstlbas.ora to initSTLBAS.ora
2. stop and start the listener
3. shutdown the Database then startup
4. try to connect Database using normal user

Enter user-name: bnsuser/bnsuser@stlbas

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options

SQL> 

Wednesday 27 November 2013

create pfile in a specific location in Oracle

create pfile='/tmp/initstlbas.ora' from spfile;

cp /tmp/initstlbas.ora /u01/app/oracle/product/10.2.0/db_1/dbs/


SQL> startup nomount pfile='/u01/app/oracle/product/10.2.0/db_1/dbs/initstlbas.ora'
ORACLE instance started.

Total System Global Area 3.7581E+10 bytes
Fixed Size                  2090032 bytes
Variable Size            6794775504 bytes
Database Buffers         3.0769E+10 bytes
Redo Buffers               14684160 bytes
SQL>

Oracle startup using pfile


SQL> startup spfile='/u01/app/oracle/product/10.2.0/db_1/dbs/spfilestlbas.ora'
   SP2-0714: invalid combination of STARTUP options 


SQL> startup nomount pfile='/u01/app/oracle/product/10.2.0/db_1/dbs/initstlbas.ora'

ORACLE instance started.

Total System Global Area 3.7581E+10 bytes
Fixed Size                  2090032 bytes
Variable Size            6794775504 bytes
Database Buffers         3.0769E+10 bytes
Redo Buffers               14684160 bytes
SQL>

Oracle Service Create/shutdown in Windows

use oradim to create Oracle service

C:\> ORADIM -NEW -SID SID -INTPWD PASSWORD -MAXUSERS USERS
 -STARTMODE AUTO -PFILE ORACLE_HOME\DATABASE\INITSID.ORA


c:\> oradim -new -sid itbl

use oradim to shutdown Oracle service

c:\> oradim -shutdown -sid itbl

Sunday 24 November 2013

Drop & Create Temporary Tablespace in Oracle Database

Goal:

Following steps will help you to create a temporary tablespace in Oracle

1. Create Temporary Tablespace Temp

CREATE TEMPORARY TABLESPACE TEMP2 TEMPFILE   '/oracledb/oradata/stlbas/temp02.dbf' SIZE 2000M;

2. Move Default Database temp tablespace

ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp2;

3. Make sure No sessions are using your Old Temp tablespace

   a.  Find Session Number from V$SORT_USAGE:
       SELECT USERNAME, SESSION_NUM, SESSION_ADDR FROM V$SORT_USAGE;

   b.  Find Session ID from V$SESSION:

       If the resultset contains any tows then your next step will be to find the SID from the V$SESSION view. You can find session id by using SESSION_NUM or SESSION_ADDR from previous resultset.

       SELECT SID, SERIAL#, STATUS FROM V$SESSION WHERE SERIAL#=SESSION_NUM;
       OR
       SELECT SID, SERIAL#, STATUS FROM V$SESSION WHERE SADDR=SESSION_ADDR;

    c.  Kill Session:

    Now kill the session with IMMEDIATE.

    ALTER SYSTEM KILL 'SID,SERIAL#' IMMEDIATE;

4. Drop temp tablespace

DROP TABLESPACE temp INCLUDING CONTENTS AND DATAFILES;

5. Recreate Tablespace Temp

CREATE TEMPORARY TABLESPACE TEMP TEMPFILE  '/oracledb/oradata/stlbas/temp01.dbf' SIZE 10240M;

6 Move Tablespace Temp, back to new temp tablespace

ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp;

7. Drop temporary for tablespace temp

DROP TABLESPACE temp2 INCLUDING CONTENTS AND DATAFILES;

Find the index need to rebuild in Oracle

Goal:

Following script will help to find out the index candidate for rebuild in Oracle.

select
   p.object_name c1,
   p.operation c2,
   p.options c3,
   count(1) c4
from
   dba_hist_sql_plan p,
   dba_hist_sqlstat s
where
   p.object_owner ='STLBAS'
and
   p.operation like '%INDEX%'
and
   p.sql_id = s.sql_id
group by
   p.object_name,
   p.operation,
   p.options
order by
   1,2,3;


select 'ALTER INDEX  ' ||owner||'.'||index_name||'  REBUILD ONLINE;'
from
   dba_hist_sql_plan p,
   dba_hist_sqlstat s
where
   p.object_owner ='STLBAS'
and
   p.operation like '%INDEX%'
and
   p.sql_id = s.sql_id
group by
   p.object_name,
   p.operation,
   p.options
order by
   1,2,3;


select 'ALTER INDEX  ' ||object_name||'  REBUILD ONLINE;'
from
   dba_hist_sql_plan p,
   dba_hist_sqlstat s
where
   p.object_owner ='STLBAS'
and
   p.operation like '%INDEX%'
and
   p.sql_id = s.sql_id
group by
   p.object_name,
   p.operation,
   p.options
order by
   1;


select 'ALTER INDEX  ' ||owner||'.'||index_name||'  REBUILD ONLINE;' 
from dba_indexes 
where owner='STLBAS'
and table_name in('STTRNDTL','STFETRAN')

Wednesday 23 October 2013

LogMiner in Oracle

Contents


  • Introduction
  • Requirements
  • Copying V$LOGMNR_CONTENTS
  • Scenario 1: Extract LogMiner Dictionary to a Flat File
  • Scenario 2: Extract LogMiner Dictionary to the Redo Log Files
  • Scenario 3: Reading the LogMiner Dictionary From the Current Online Catalog
  • Scenario 4: Source Database (10g) — Remote Mining Database (11g)
  • Scenario 5: Using the CONTINUOUS_MINE Option
  • About the Author

Introduction

LogMiner is a built-in database tool introduced in Oracle8i that provides a relational interface for users to query redo records found in online and archived redo log files. LogMiner is most often used for auditing purposes, data analysis, or recovering data from a user error.
This tutorial provides an example-based approach on how to use LogMiner in a number of different scenarios. The examples will be based on Oracle Database 11g Release 2 (11.2.0.3.0) running on the Linux platform.
Consult the following article for an overview of the LogMiner tool and an explanation of its components.

  • Understanding LogMiner
The examples presented in this tutorial will explain the different methods to construct and maintain the LogMiner dictionary. For example, extracting the LogMiner dictionary to a flat file, extracting the LogMiner dictionary to the redo log files, and reading the LogMiner dictionary from the current online catalog.
LogMiner automatically builds its own internal dictionary from the LogMiner dictionary that you specify when you start LogMiner (either an online catalog, a dictionary in the redo log files, or a flat file). This internal dictionary provides a snapshot of the database objects and their definitions. If your LogMiner dictionary is in the redo log files or is a flat file, you can use the DDL_DICT_TRACKING option to the PL/SQL DBMS_LOGMNR.START_LOGMNR procedure to direct LogMiner to track data definition language (DDL) statements. DDL tracking enables LogMiner to successfully track structural changes made to a database object, such as adding or dropping columns from a table. It is important to understand that the LogMiner internal dictionary is not the same as the LogMiner dictionary contained in a flat file, in redo log files, or in the online catalog. LogMiner does update its internal dictionary, but it does not update the dictionary that is contained in a flat file, in redo log files, or in the online catalog.

LogMiner Interfaces

The LogMiner utility can be accessed through SQL statements (command-line) or through the Oracle LogMiner Viewer graphical user interface which is part of Oracle Enterprise Manager. The examples presented in this guide will all use the command-line interface.

Requirements

The following are requirements for the source and mining database, the data dictionary, and the redo log files that LogMiner will mine in the examples presented in this guide.

LogMiner Source and Mining Database


  • Source and Mining Database

    • Both the source database and the mining database must be running on the same hardware platform.
    • The mining database can be the same as, or completely separate from, the source database.
    • The mining database must run the same version or a later version of the Oracle Database software as the source database.
    • The mining database must use the same character set (or a super set of the character set) used by the source database.
  • LogMiner Dictionary

    • The dictionary must be produced by the same source database that generates the redo log files that LogMiner will analyze.
  • All Redo Log Files

    • Must be produced by the same source database.
    • Must be associated with the same database RESETLOGS SCN.
    • Must be from a release 8.0 or later Oracle Database. However, several of the LogMiner features introduced as of release 9.0.1 work only with redo log files produced on an Oracle9i or later database.
LogMiner does not allow you to mix redo log files from different databases or to use a dictionary from a different database than the one that generated the redo log files to be analyzed.

Archivelog Mode

Archivelog mode must be enabled in order to generate usable redo log files.

SQL> select log_mode from v$database;

LOG_MODE
------------
NOARCHIVELOG


SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.


SQL> startup mount
ORACLE instance started.

Total System Global Area 1653518336 bytes
Fixed Size                  2228904 bytes
Variable Size            1291849048 bytes
Database Buffers          352321536 bytes
Redo Buffers                7118848 bytes
Database mounted.


SQL> alter database archivelog;

Database altered.


SQL> alter database open;

Database altered.


SQL> select log_mode from v$database;

LOG_MODE
------------
ARCHIVELOG

Security

A new role named LOGMNR_ADMIN will be created and assigned the appropriate privileges for LogMiner analysis. This role will be assigned to a new user named MINER that will be used to perform the LogMiner examples presented in this guide.

SQL> create role logmnr_admin;

Role created.


SQL> grant create session to logmnr_admin;

Grant succeeded.


SQL> grant select on v_$logmnr_contents to logmnr_admin;

Grant succeeded.


SQL> grant select on v_$logmnr_dictionary to logmnr_admin;

Grant succeeded.


SQL> grant select on v_$logmnr_parameters to logmnr_admin;

Grant succeeded.


SQL> grant select on v_$logmnr_logs to logmnr_admin;

Grant succeeded.


SQL> grant select on v_$archived_log to logmnr_admin;

Grant succeeded.


SQL> grant  execute_catalog_role
          , select any dictionary
          , select any transaction
          , select any table
          , create tablespace
          , drop tablespace
to logmnr_admin;

Grant succeeded.


SQL> create user miner identified by miner;

User created.


SQL> grant logmnr_admin to miner;

Grant succeeded.


SQL> alter user miner quota unlimited on users;

User altered.

Supplemental Logging

LogMiner is a redo-based application and as such, requires at least minimal supplemental logging be enabled on the source database. Oracle does not enable any supplemental logging by default.
After verifying supplemental logging is enabled, force a log switch in order for the new supplemental log configuration to begin archiving the additional column data to the redo logs.

SQL> alter database add supplemental log data;

Database altered.


SQL> select supplemental_log_data_min from v$database;

SUPPLEMENTAL_LOG_DATA_MIN
--------------------------
YES


SQL> alter system switch logfile;

System altered.

LogMiner Tablespace

This optional step allows you to re-create all LogMiner tables in an alternative tablespace other than the default SYSAUX tablespace.

CREATE TABLESPACE logmnrts DATAFILE SIZE 25M
AUTOEXTEND ON NEXT 25M MAXSIZE UNLIMITED;

Tablespace created.


BEGIN
    DBMS_LOGMNR_D.SET_TABLESPACE (
        new_tablespace => 'logmnrts'
    );
END;
/

PL/SQL procedure successfully completed.
Remember that supplemental logging must be enabled on the source database before generating redo log files that will be analyzed by LogMiner.

Copying V$LOGMNR_CONTENTS

After preparing and starting a LogMiner session, the redo entries mined from the redo log files by LogMiner are made available through the private view V$LOGMNR_CONTENTS. The SQL interface can be used to query SQL statements (and their UNDO) executed on the database during any point in time you have redo log files for. When a SELECT statement is executed against the V$LOGMNR_CONTENTS view, the redo log files are read sequentially. Translated records from the redo log files are returned as rows in the V$LOGMNR_CONTENTS view. This continues until either the filter criteria specified at startup (EndTime or endScn) are met or the end of the redo log file(s) is reached. The records available through the V$LOGMNR_CONTENTS view are only accessible to the current session which started the LogMiner session and only until the DBMS_LOGMNR.END_LOGMNR is called.
The examples in this guide are provided to demonstrate a number of practical scenarios but are kept small in order to explain concepts. However, in many cases, the number of redo entries to analyze can be significant. Trying to perform a LogMiner analysis of many redo entries through the V$LOGMNR_CONTENTS view can be expensive given the nature of how the redo log files need to be read.
A good practice is to copy the LogMiner contents from V$LOGMNR_CONTENTS to a user table. Accessing a user table will be faster and can also be indexed for better query performance. In addition, the LogMiner contents will be persisted when the LogMiner session ends.
...

BEGIN
    DBMS_LOGMNR.START_LOGMNR (
        options => DBMS_LOGMNR.DICT_FROM_REDO_LOGS
    );
END;
/

PL/SQL procedure successfully completed.


CREATE TABLE miner.logmnr_contents_20121018 AS
    SELECT * FROM v$logmnr_contents;

Table created.


CREATE INDEX miner.logmnr_contents_20121018_idx1
    ON miner.logmnr_contents_20121018(username, operation, seg_owner);

Index created.


BEGIN
    DBMS_LOGMNR.END_LOGMNR();
END;
/

PL/SQL procedure successfully completed.

Scenario 1: Extract LogMiner Dictionary to a Flat File

Prior to Oracle9i, extracting the LogMiner dictionary to a flat file was the only method available to create the dictionary. This method is maintained for backward compatibility with previous releases. In addition, this method does not guarantee transactional consistency.

Requirements

Review the requirements section at the beginning of this guide to prepare the source and mining database, the data dictionary, and the redo log files that LogMiner will mine in this example. To extract the dictionary to a flat file, set the dictionary_filename parameter to the name of the file when calling DBMS_LOGMNR_D.BUILD, the dictionary_location set to a directory on the database machine specified in UTL_FILE_DIR, and optionally set the options parameter to the constant DBMS_LOGMNR_D.STORE_IN_FLAT_FILE. Using these options, the BUILD procedure will query the data dictionary tables of the current database and create a text-based file containing the contents of the tables.
The directory specified in dictionary_location must exist as a value in the UTL_FILE_DIR initialization parameter. After setting this parameter, the instance will need to be restarted in order to take effect.
Only extract the dictionary to a flat file after all DDL statements have been run and prior to the creation of any redo log files that will be analyzed. Do not run DBMS_LOGMNR_D.BUILD while DDL operations are occurring in the database, else the snapshot of the dictionary will not be consistent.

Action Items to Perform

The scenario described in this section performs the following actions:

  • The same database will be used for the source and mining database.
  • The following SQL statement was run in the database by the user SCOTT and written to the redo log file on around 06-OCT-2012 00:21:00.

    insert into
    hr.departments(department_id, department_name, manager_id, location_id)
    values(hr.departments_seq.nextval, 'Engineering', null, 1700);
  • Verify the utl_file_dir initialization parameter contains the destination directory where the LogMiner dictionary will be extracted to.
  • Extract LogMiner dictionary to a flat file.
  • Determine the redo log files to be analyzed by LogMiner.
  • Add two archived redo log files to the list of log files for LogMiner to analyze.
  • Start a LogMiner session with no options.
  • Query V$LOGMNR_CONTENTS for the SQL_REDO and SQL_UNDO for the above DDL INSERT statement.
  • Properly end a LogMiner session using the DBMS_LOGMNR.END_LOGMNR procedure which performs all cleanup operations. This procedure is automatically called when you log out of a database or when you call DBMS_LOGMNR.ADD_LOGFILE and specify the NEW option.

Example LogMiner Session


CONNECT miner/miner
Connected.


ALTER SESSION SET nls_date_format = 'DD-MON-YYYY HH24:MI:SS';

Session altered.


SELECT name, value
FROM v$parameter
WHERE name = 'utl_file_dir';

NAME            VALUE
--------------- -------------------------
utl_file_dir    /u04/app/oracle/logmnr


BEGIN
    DBMS_LOGMNR_D.BUILD (
        dictionary_filename => 'dictionary.ora',
        dictionary_location => '/u04/app/oracle/logmnr',
        options => DBMS_LOGMNR_D.STORE_IN_FLAT_FILE
    );
END;
/

PL/SQL procedure successfully completed.


ls -l /u04/app/oracle/logmnr/dictionary.ora
-rw-r--r-- 1 oracle asmadmin 39125525 Oct  6 00:25 /u04/app/oracle/logmnr/dictionary.ora


COLUMN name             FORMAT A66 HEAD "Log File Name"
COLUMN first_time       FORMAT A23 HEAD "First Time"

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('06-OCT-2012 00:15:00', 'DD-MON-YYYY HH24:MI:SS') AND
      TO_DATE('06-OCT-2012 00:45:00', 'DD-MON-YYYY HH24:MI:SS')
ORDER BY
    sequence#;


Log File Name                                                      First Time 
------------------------------------------------------------------ -----------------------
+FRA/racdb/archivelog/2012_10_06/thread_1_seq_3138.1105.795917893  06-OCT-2012 00:16:38     
+FRA/racdb/archivelog/2012_10_06/thread_1_seq_3139.1036.795918129  06-OCT-2012 00:26:41   
+FRA/racdb/archivelog/2012_10_06/thread_1_seq_3140.1123.795919913  06-OCT-2012 00:36:39 


BEGIN
    DBMS_LOGMNR.ADD_LOGFILE (
        LogFileName => '+FRA/racdb/archivelog/2012_10_06/thread_1_seq_3138.1105.795917893',
        options => DBMS_LOGMNR.NEW
    );
END;
/

PL/SQL procedure successfully completed.


BEGIN
    DBMS_LOGMNR.ADD_LOGFILE (
        LogFileName => '+FRA/racdb/archivelog/2012_10_06/thread_1_seq_3139.1036.795918129',
        options => DBMS_LOGMNR.ADDFILE
    );
END;
/

PL/SQL procedure successfully completed.


BEGIN
    DBMS_LOGMNR.START_LOGMNR (
        DictFileName => '/u04/app/oracle/logmnr/dictionary.ora'
    );
END;
/

PL/SQL procedure successfully completed.


COLUMN timestamp  FORMAT A20
COLUMN filename   FORMAT A38

SELECT
    timestamp
  , filename
  , dictionary_scn
  , NVL(info, 'VALID') as DICTIONARY_STATUS
FROM
    v$logmnr_dictionary;

TIMESTAMP            FILENAME                               DICTIONARY_SCN DICTIONARY_STATUS
-------------------- -------------------------------------- -------------- ------------------
06-OCT-2012 00:24:57 /u04/app/oracle/logmnr/dictionary.ora        96112409 VALID


COLUMN username   FORMAT A8
COLUMN operation  FORMAT A9
COLUMN sql_redo   FORMAT A25 WORD_WRAPPED
COLUMN sql_undo   FORMAT A25 WORD_WRAPPED
COLUMN timestamp  FORMAT A20

SELECT 
    username
  , operation
  , 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 = 'HR';

Username OPERATION SQL_REDO                  SQL_UNDO                  TIMESTAMP                   SCN
-------- --------- ------------------------- ------------------------- -------------------- ----------
SCOTT    INSERT    insert into               delete from               06-OCT-2012 00:21:38   96112299
                   "HR"."DEPARTMENTS"("DEPAR "HR"."DEPARTMENTS" where
                   TMENT_ID","DEPARTMENT_NAM "DEPARTMENT_ID" = '320'
                   E","MANAGER_ID","LOCATION and "DEPARTMENT_NAME" =
                   _ID") values              'Engineering' and
                   ('320','Engineering',NULL "MANAGER_ID" IS NULL and
                   ,'1700');                 "LOCATION_ID" = '1700'
                                             and ROWID =
                                             'AAAQ08AAEAAAACvAAb';


See the section Copying V$LOGMNR_CONTENTS for tips on how to retain the LogMiner contents and enhance performance when accessing the V$LOGMNR_CONTENTS private view.
BEGIN DBMS_LOGMNR.END_LOGMNR(); END; / PL/SQL procedure successfully completed.

Scenario 2: Extract LogMiner Dictionary to the Redo Log Files

Oracle recommends extracting the LogMiner Dictionary to the redo log files when you do not expect to have access to the source database from which the redo log files were created, or if you anticipate that changes will be made to the column definitions in the tables of interest.

Requirements

Review the requirements section at the beginning of this guide to prepare the source and mining database, the data dictionary, and the redo log files that LogMiner will mine in this example. When reading the dictionary from the redo log files, call the DBMS_LOGMNR_D.BUILD procedure and specify the options parameter with the value set to the constant DBMS_LOGMNR.DICT_FROM_REDO_LOGS. The redo log file(s) including the LogMiner dictionary from the DBMS_LOGMNR_D.BUILD procedure need to have been explicitly loaded for the current LogMiner session through the DBMS_LOGMNR.ADD_LOGFILE procedure. LogMiner will expect to find the LogMiner dictionary in the redo log files specified for the current LogMiner session.
The size of the LogMiner dictionary may cause it to be contained in multiple redo log files.
Extracting the dictionary to the redo log files requires the following:
  • Oracle9i database or later
  • The COMPATIBLE initialization parameter must be set to 9.2.0 or higher
  • Archivelog mode enabled in order to generate usable redo log files
  • Supplemental logging (at least the minimum level) should be enabled in order to take advantage of all LogMiner features

Action Items to Perform

The scenario described in this section performs the following actions:

  • The same database will be used for the source and mining database.
  • The following SQL statement was run in the database by the user SCOTT and written to the redo log file on around 09-OCT-2012 10:05:00.

    insert into
    hr.departments(department_id, department_name, manager_id, location_id)
    values(hr.departments_seq.nextval, 'Engineering', null, 1700);
  • Extract LogMiner dictionary to the Redo Log Files.
  • Identify the archived redo log files containing the LogMiner dictionary and any other log files to be analyzed by LogMiner.
  • Add archived redo log files to the list of log files for LogMiner to analyze. All log files from the time of the target SQL statement until the LogMiner dictionary must be added.
  • Query the V$LOGMNR_LOGS view to determine which redo log files have been manually or automatically added to the list of redo log files for LogMiner to analyze.
  • Start a LogMiner session and enable the following options:

    • DICT_FROM_REDO_LOGS — If set, LogMiner expects to find a LogMiner dictionary in the redo log files that were specified.
    • DDL_DICT_TRACKING instructs LogMiner to update its internal dictionary if a DDL event occurs. (This option cannot be used in conjunction with the DICT_FROM_ONLINE_CATALOG option and cannot be used when the LogMiner dictionary being used is one that was extracted to a flat file prior to Oracle9i.)
    • PRINT_PRETTY_SQL — format the reconstructed SQL statements making them easier to read.
  • Query V$LOGMNR_CONTENTS for the SQL_REDO and SQL_UNDO for the above DDL INSERT statement.
  • Properly end a LogMiner session using the DBMS_LOGMNR.END_LOGMNR procedure which performs all cleanup operations. This procedure is automatically called when you log out of a database or when you call DBMS_LOGMNR.ADD_LOGFILE and specify the NEW option.

Example LogMiner Session


CONNECT miner/miner
Connected.


ALTER SESSION SET nls_date_format = 'DD-MON-YYYY HH24:MI:SS';

Session altered.


BEGIN
    DBMS_LOGMNR_D.BUILD (
        options => DBMS_LOGMNR_D.STORE_IN_REDO_LOGS
    );
END;
/

PL/SQL procedure successfully completed.


COLUMN name             FORMAT A66 HEAD "Log File Name"
COLUMN first_time       FORMAT A23 HEAD "First Time"
COLUMN dictionary_begin FORMAT A5  HEAD "Dict|Begin"
COLUMN dictionary_end   FORMAT A5  HEAD "Dict|End"

SELECT
    name
  , TO_CHAR(first_time, 'DD-MON-YYYY HH24:MI:SS') first_time
  , dictionary_begin
  , dictionary_end
FROM
    v$archived_log
WHERE
      name IS NOT NULL
  AND first_time BETWEEN
      TO_DATE('09-OCT-2012 10:00:00', 'DD-MON-YYYY HH24:MI:SS') AND
      TO_DATE('09-OCT-2012 11:00:00', 'DD-MON-YYYY HH24:MI:SS')
ORDER BY
    sequence#;

                                                                                           Dict  Dict 
Log File Name                                                      First Time              Begin End  
------------------------------------------------------------------ ----------------------- ----- -----
+FRA/racdb/archivelog/2012_10_09/thread_1_seq_3198.1127.796212243  09-OCT-2012 10:01:07    NO    NO   
+FRA/racdb/archivelog/2012_10_09/thread_1_seq_3199.957.796212841   09-OCT-2012 10:04:03    NO    NO   
+FRA/racdb/archivelog/2012_10_09/thread_1_seq_3200.1044.796213443  09-OCT-2012 10:14:00    NO    NO   
+FRA/racdb/archivelog/2012_10_09/thread_1_seq_3201.1083.796214041  09-OCT-2012 10:24:02    NO    NO   
+FRA/racdb/archivelog/2012_10_09/thread_1_seq_3202.1013.796214585  09-OCT-2012 10:34:00    NO    NO   
+FRA/racdb/archivelog/2012_10_09/thread_1_seq_3203.1038.796214587  09-OCT-2012 10:43:05    NO    NO   
+FRA/racdb/archivelog/2012_10_09/thread_1_seq_3204.982.796214591   09-OCT-2012 10:43:07    YES   NO   
+FRA/racdb/archivelog/2012_10_09/thread_1_seq_3205.1103.796214597  09-OCT-2012 10:43:10    NO    YES
+FRA/racdb/archivelog/2012_10_09/thread_1_seq_3206.983.796215193   09-OCT-2012 10:43:17    NO    NO


BEGIN
    DBMS_LOGMNR.ADD_LOGFILE (
        LogFileName => '+FRA/racdb/archivelog/2012_10_09/thread_1_seq_3199.957.796212841',
        options => DBMS_LOGMNR.NEW
    );
END;
/

PL/SQL procedure successfully completed.


BEGIN
    DBMS_LOGMNR.ADD_LOGFILE (
        LogFileName => '+FRA/racdb/archivelog/2012_10_09/thread_1_seq_3200.1044.796213443',
        options => DBMS_LOGMNR.ADDFILE
    );
END;
/

PL/SQL procedure successfully completed.


BEGIN
    DBMS_LOGMNR.ADD_LOGFILE (
        LogFileName => '+FRA/racdb/archivelog/2012_10_09/thread_1_seq_3201.1083.796214041',
        options => DBMS_LOGMNR.ADDFILE
    );
END;
/

PL/SQL procedure successfully completed.


BEGIN
    DBMS_LOGMNR.ADD_LOGFILE (
        LogFileName => '+FRA/racdb/archivelog/2012_10_09/thread_1_seq_3202.1013.796214585',
        options => DBMS_LOGMNR.ADDFILE
    );
END;
/

PL/SQL procedure successfully completed.


BEGIN
    DBMS_LOGMNR.ADD_LOGFILE (
        LogFileName => '+FRA/racdb/archivelog/2012_10_09/thread_1_seq_3203.1038.796214587',
        options => DBMS_LOGMNR.ADDFILE
    );
END;
/

PL/SQL procedure successfully completed.


BEGIN
    DBMS_LOGMNR.ADD_LOGFILE (
        LogFileName => '+FRA/racdb/archivelog/2012_10_09/thread_1_seq_3204.982.796214591',
        options => DBMS_LOGMNR.ADDFILE
    );
END;
/

PL/SQL procedure successfully completed.


BEGIN
    DBMS_LOGMNR.ADD_LOGFILE (
        LogFileName => '+FRA/racdb/archivelog/2012_10_09/thread_1_seq_3205.1103.796214597',
        options => DBMS_LOGMNR.ADDFILE
    );
END;
/

PL/SQL procedure successfully completed.


COLUMN filename         FORMAT A66 HEAD "Log File Name"
COLUMN type             FORMAT A8  HEAD "Type"
COLUMN status           FORMAT A33 HEAD "Status"
COLUMN dictionary_begin FORMAT A5  HEAD "Dict|Begin"
COLUMN dictionary_end   FORMAT A5  HEAD "Dict|End"

SELECT
    filename
  , type
  , ( CASE status
        WHEN 0 THEN 'Redo log file will be processed.'
        WHEN 1 THEN 'First log file to be processed.'
        WHEN 2 THEN 'Redo log file will not be processed (pruned).'
        WHEN 4 THEN 'Redo log file is missing from LogMiner list.'
      END) as status
  , dictionary_begin
  , dictionary_end
FROM
    v$logmnr_logs
ORDER BY
    log_id;

                                                                                                              Dict  Dict 
Log File Name                                                      Type     Status                            Begin End  
------------------------------------------------------------------ -------- --------------------------------- ----- -----
+FRA/racdb/archivelog/2012_10_09/thread_1_seq_3199.957.796212841   ARCHIVE  Redo log file will be processed.  NO    NO   
+FRA/racdb/archivelog/2012_10_09/thread_1_seq_3200.1044.796213443  ARCHIVE  Redo log file will be processed.  NO    NO   
+FRA/racdb/archivelog/2012_10_09/thread_1_seq_3201.1083.796214041  ARCHIVE  Redo log file will be processed.  NO    NO   
+FRA/racdb/archivelog/2012_10_09/thread_1_seq_3202.1013.796214585  ARCHIVE  Redo log file will be processed.  NO    NO   
+FRA/racdb/archivelog/2012_10_09/thread_1_seq_3203.1038.796214587  ARCHIVE  Redo log file will be processed.  NO    NO   
+FRA/racdb/archivelog/2012_10_09/thread_1_seq_3204.982.796214591   ARCHIVE  Redo log file will be processed.  YES   NO   
+FRA/racdb/archivelog/2012_10_09/thread_1_seq_3205.1103.796214597  ARCHIVE  Redo log file will be processed.  NO    YES


BEGIN
    DBMS_LOGMNR.START_LOGMNR (
        options => DBMS_LOGMNR.DICT_FROM_REDO_LOGS +
                   DBMS_LOGMNR.DDL_DICT_TRACKING +
                   DBMS_LOGMNR.PRINT_PRETTY_SQL
    );
END;
/

PL/SQL procedure successfully completed.


COLUMN username   FORMAT A8
COLUMN operation  FORMAT A9
COLUMN sql_redo   FORMAT A25 WORD_WRAPPED
COLUMN sql_undo   FORMAT A25 WORD_WRAPPED
COLUMN timestamp  FORMAT A20

SELECT 
    username
  , operation
  , 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 = 'HR';

USERNAME OPERATION SQL_REDO                  SQL_UNDO                  TIMESTAMP                   SCN
-------- --------- ------------------------- ------------------------- -------------------- ----------
SCOTT    INSERT    insert into               delete from               09-OCT-2012 10:05:12   97631060
                   "HR"."DEPARTMENTS"        "HR"."DEPARTMENTS"
                   values                    where
                   "DEPARTMENT_ID" = 350,    "DEPARTMENT_ID" = 350 and
                   "DEPARTMENT_NAME" =       "DEPARTMENT_NAME" =
                   'Engineering',            'Engineering' and
                   "MANAGER_ID" IS NULL,     "MANAGER_ID" IS NULL and
                   "LOCATION_ID" = 1700;     "LOCATION_ID" = 1700 and
                                             ROWID =
                                             'AAAQ08AAEAAAACuAAB';

See the section Copying V$LOGMNR_CONTENTS for tips on how to retain the LogMiner contents and enhance performance when accessing the V$LOGMNR_CONTENTS private view.
BEGIN DBMS_LOGMNR.END_LOGMNR(); END; / PL/SQL procedure successfully completed.

Scenario 3: Reading the LogMiner Dictionary From the Current Online Catalog

Oracle recommends reading the LogMiner Dictionary from the current online catalog when you will have access to the source database from which the redo log files were created and when no changes to the column definitions in the tables of interest are anticipated.
The online catalog contains the latest information about the database and may be the fastest way to start your analysis. Because DDL operations that change important tables should be somewhat rare in a production system, the online catalog generally contains the information you need for your analysis.

Requirements

Review the requirements section at the beginning of this guide to prepare the source and mining database, the data dictionary, and the redo log files that LogMiner will mine in this example. If reading the dictionary from the current online catalog, specify the options parameter with the value set to the constant DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG of the DBMS_LOGMNR.START_LOGMNR procedure. In this case, it is not necessary to have previously extracted the LogMiner dictionary to a flat file or in the redo log files being analyzed for the current LogMiner sessions through the DBMS_LOGMNR_D.BUILD procedure.
In addition to using the online catalog to analyze online redo log files, you can use it to analyze archived redo log files, if you are on the same system that generated the archived redo log files.
The online catalog can only reconstruct SQL statements that are executed on the latest version of a table. As soon as a table is altered, the online catalog is updated and no longer reflects the previous version of the table. This means that LogMiner will not be able to reconstruct any SQL statements that were executed on the previous version of the table. Instead, LogMiner generates non-executable SQL (including hexadecimal-to-raw formatting of binary values) in the SQL_REDO column of the V$LOGMNR_CONTENTS view similar to the following example:

insert into HR.EMPLOYEES("COL 1","COL 2","COL 3","COL 4")
values (HEXTORAW('c2035b'),HEXTORAW('456e67696e656572696e67'),NULL,HEXTORAW('c212'));
Expect to see a value of 2 in the STATUS column of the V$LOGMNR_CONTENTS view if the table definition in the database does not match the table definition in the redo log file.
The online catalog option requires that the database be open.
The online catalog option is not valid with the DDL_DICT_TRACKING option of DBMS_LOGMNR.START_LOGMNR.

Action Items to Perform

The scenario described in this section performs the following actions:

  • The same database will be used for the source and mining database.
  • The following SQL statement was run in the database by the user SCOTT and written to the redo log file on around 16-OCT-2012 10:22:13.

    insert into
    hr.departments(department_id, department_name, manager_id, location_id)
    values(hr.departments_seq.nextval, 'Engineering', null, 1700);
  • Read the LogMiner dictionary from the current online catalog.
  • Determine and add the redo log files to be analyzed by LogMiner.
  • Start a LogMiner session and enable the following options:

    • DICT_FROM_ONLINE_CATALOG — direct LogMiner to use the dictionary currently in use for the database.
    • PRINT_PRETTY_SQL — format the reconstructed SQL statements making them easier to read.
    • NO_SQL_DELIMITER — suppresses the semicolon from the reconstructed statements. This is helpful for applications that open a cursor and then execute the reconstructed statements.
    • COMMITTED_DATA_ONLY — If set, DML statements corresponding to committed transactions are returned. DML statements corresponding to a committed transaction are grouped together. Transactions are returned in their commit order. Transactions that are rolled back or in-progress are filtered out, as are internal redo records (those related to index operations, management, and so on). If this option is not set, all rows for all transactions (committed, rolled back, and in-progress) are returned in the order in which they are found in the redo logs (in order of SCN values).
  • Query the V$LOGMNR_LOGS view to determine which redo log files have been manually or automatically added to the list of redo log files for LogMiner to analyze.
  • Query V$LOGMNR_CONTENTS for the SQL_REDO and SQL_UNDO for the above DDL INSERT statement.
  • Properly end a LogMiner session using the DBMS_LOGMNR.END_LOGMNR procedure which performs all cleanup operations. This procedure is automatically called when you log out of a database or when you call DBMS_LOGMNR.ADD_LOGFILE and specify the NEW option.

Example LogMiner Session


CONNECT miner/miner
Connected.


ALTER SESSION SET nls_date_format = 'DD-MON-YYYY HH24:MI:SS';

Session altered.


COLUMN name             FORMAT A66 HEAD "Log File Name"
COLUMN first_time       FORMAT A23 HEAD "First Time"
COLUMN dictionary_begin FORMAT A5  HEAD "Dict|Begin"
COLUMN dictionary_end   FORMAT A5  HEAD "Dict|End"

SELECT
    name
  , TO_CHAR(first_time, 'DD-MON-YYYY HH24:MI:SS') first_time
  , dictionary_begin
  , dictionary_end
FROM
    v$archived_log
WHERE
      name IS NOT NULL
  AND first_time BETWEEN
      TO_DATE('16-OCT-2012 10:00:00', 'DD-MON-YYYY HH24:MI:SS') AND
      TO_DATE('16-OCT-2012 11:00:00', 'DD-MON-YYYY HH24:MI:SS')
ORDER BY
    sequence#;

                                                                                           Dict  Dict 
Log File Name                                                      First Time              Begin End  
------------------------------------------------------------------ ----------------------- ----- -----
+FRA/racdb/archivelog/2012_10_16/thread_1_seq_4261.985.796817011   16-OCT-2012 10:02:20    NO    NO
+FRA/racdb/archivelog/2012_10_16/thread_1_seq_4262.975.796817609   16-OCT-2012 10:03:30    NO    NO
+FRA/racdb/archivelog/2012_10_16/thread_1_seq_4263.1109.796818207  16-OCT-2012 10:13:28    NO    NO
+FRA/racdb/archivelog/2012_10_16/thread_1_seq_4264.969.796818655   16-OCT-2012 10:23:27    NO    NO
+FRA/racdb/archivelog/2012_10_16/thread_1_seq_4265.1126.796818969  16-OCT-2012 10:30:54    NO    NO
+FRA/racdb/archivelog/2012_10_16/thread_1_seq_4266.1082.796819407  16-OCT-2012 10:36:09    NO    NO
+FRA/racdb/archivelog/2012_10_16/thread_1_seq_4267.1081.796819855  16-OCT-2012 10:43:26    NO    NO
+FRA/racdb/archivelog/2012_10_16/thread_1_seq_4268.1076.796820451  16-OCT-2012 10:50:53    NO    NO


BEGIN
    DBMS_LOGMNR.ADD_LOGFILE (
        LogFileName => '+FRA/racdb/archivelog/2012_10_16/thread_1_seq_4263.1109.796818207',
        options => DBMS_LOGMNR.NEW
    );
END;
/

PL/SQL procedure successfully completed.


BEGIN
    DBMS_LOGMNR.ADD_LOGFILE (
        LogFileName => '+FRA/racdb/archivelog/2012_10_16/thread_1_seq_4264.969.796818655',
        options => DBMS_LOGMNR.ADDFILE
    );
END;
/

PL/SQL procedure successfully completed.


COLUMN filename         FORMAT A66 HEAD "Log File Name"
COLUMN type             FORMAT A8  HEAD "Type"
COLUMN status           FORMAT A33 HEAD "Status"
COLUMN dictionary_begin FORMAT A5  HEAD "Dict|Begin"
COLUMN dictionary_end   FORMAT A5  HEAD "Dict|End"

SELECT
    filename
  , type
  , ( CASE status
        WHEN 0 THEN 'Redo log file will be processed.'
        WHEN 1 THEN 'First log file to be processed.'
        WHEN 2 THEN 'Redo log file will not be processed (pruned).'
        WHEN 4 THEN 'Redo log file is missing from LogMiner list.'
      END) as status
  , dictionary_begin
  , dictionary_end
FROM
    v$logmnr_logs
ORDER BY
    log_id;

                                                                                                              Dict  Dict 
Log File Name                                                      Type     Status                            Begin End  
------------------------------------------------------------------ -------- --------------------------------- ----- -----
+FRA/racdb/archivelog/2012_10_16/thread_1_seq_4263.1109.796818207  ARCHIVE  Redo log file will be processed.  NO    NO   
+FRA/racdb/archivelog/2012_10_16/thread_1_seq_4264.969.796818655   ARCHIVE  Redo log file will be processed.  NO    NO


BEGIN
    DBMS_LOGMNR.START_LOGMNR (
        options => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG +
                   DBMS_LOGMNR.PRINT_PRETTY_SQL +
                   DBMS_LOGMNR.NO_SQL_DELIMITER +
                   DBMS_LOGMNR.COMMITTED_DATA_ONLY
    );
END;
/

PL/SQL procedure successfully completed.


COLUMN username   FORMAT A8
COLUMN operation  FORMAT A9
COLUMN sql_redo   FORMAT A25 WORD_WRAPPED
COLUMN sql_undo   FORMAT A25 WORD_WRAPPED
COLUMN timestamp  FORMAT A20

SELECT 
    username
  , operation
  , 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 = 'HR';

USERNAME OPERATION SQL_REDO                  SQL_UNDO                  TIMESTAMP                   SCN
-------- --------- ------------------------- ------------------------- -------------------- ----------
SCOTT    INSERT    insert into               delete from               16-OCT-2012 10:22:19  102833460
                   "HR"."DEPARTMENTS"        "HR"."DEPARTMENTS"
                   values                    where
                   "DEPARTMENT_ID" = 360,    "DEPARTMENT_ID" = 360 and
                   "DEPARTMENT_NAME" =       "DEPARTMENT_NAME" =
                   'Engineering',            'Engineering' and
                   "MANAGER_ID" IS NULL,     "MANAGER_ID" IS NULL and
                   "LOCATION_ID" = 1700      "LOCATION_ID" = 1700 and
                                             ROWID =
                                             'AAAQ08AAEAAAACsAAB'

See the section Copying V$LOGMNR_CONTENTS for tips on how to retain the LogMiner contents and enhance performance when accessing the V$LOGMNR_CONTENTS private view.
BEGIN DBMS_LOGMNR.END_LOGMNR(); END; / PL/SQL procedure successfully completed.

Scenario 4: Source Database (10g) — Remote Mining Database (11g)

This particular example demonstrates a scenario where the DBA may be managing a heavy utilized Oracle 10g OLTP database that is unable to mine its archived redo logs because of a lack of resources. Because it is not required that the mining operating occur on the source database, the DBA decides to locate another database with available resources that will allow LogMiner to analyze the logs. In this example, the mining database will be an Oracle 11g database running on a different server than the source.
This example will use the following configuration:

  • Source Database

    SOURCE_DB=ORA10G
    SOURCE_MACHINE=packmule.idevelopment.info
    SOURCE_DB_CONNECT_STRING=sys/manager@//packmule:1521/ora10g.idevelopment.info as sysdba
    SOURCE_DB_VERSION=10.2.0.4
  • Mining Database

    MINING_DB=ORA11G
    MINING_MACHINE=testnode1.idevelopment.info
    MINING_ARC_DIR=/u03/app/oracle/oraarch/ORA10G
    MINING_DB_CONNECT_STRING=miner/miner@//testnode1:1521/ora11g.idevelopment.info
    MINING_DB_VERSION=11.2.0.3

Action Items to Perform

The scenario described in this section performs the following actions:

  • The following SQL statement was run in the database by the user SCOTT and written to the redo log file on around 18-OCT-2012 18:05:15.

    insert into
    hr.departments(department_id, department_name, manager_id, location_id)
    values(hr.departments_seq.nextval, 'Engineering', null, 1700);
  • Connect to the source database.
  • Extract LogMiner dictionary to the Redo Log Files.
  • Identify the archived redo log files containing the LogMiner dictionary and any other log files to be analyzed by LogMiner. All log files from the time of the target SQL statement until the LogMiner dictionary must be part of the LogMiner session.
  • Send all identified archived redo log files from the source database server to the mining database server.
  • Connect to the mining database.
  • From the mining database, add the archived redo log files sent from the source database to the list of log files for LogMiner to analyze. All log files from the time of the target SQL statement until the LogMiner dictionary must be added.
  • Query the V$LOGMNR_LOGS view to determine which redo log files have been manually or automatically added to the list of redo log files for LogMiner to analyze.
  • Start a LogMiner session on the mining database and enable the following options:

    • DICT_FROM_REDO_LOGS — If set, LogMiner expects to find a LogMiner dictionary in the redo log files that were specified.
    • PRINT_PRETTY_SQL — format the reconstructed SQL statements making them easier to read.
  • Query V$LOGMNR_CONTENTS for the SQL_REDO and SQL_UNDO for the above DDL INSERT statement.
  • Properly end a LogMiner session using the DBMS_LOGMNR.END_LOGMNR procedure which performs all cleanup operations. This procedure is automatically called when you log out of a database or when you call DBMS_LOGMNR.ADD_LOGFILE and specify the NEW option.

Example LogMiner Session


CONNECT sys/manager@//packmule:1521/ora10g.idevelopment.info as sysdba
Connected.


ALTER SESSION SET nls_date_format = 'DD-MON-YYYY HH24:MI:SS';

Session altered.


BEGIN
    DBMS_LOGMNR_D.BUILD (
        options => DBMS_LOGMNR_D.STORE_IN_REDO_LOGS
    );
END;
/

PL/SQL procedure successfully completed.


COLUMN name             FORMAT A81 HEAD "Log File Name"
COLUMN first_time       FORMAT A23 HEAD "First Time"
COLUMN dictionary_begin FORMAT A5  HEAD "Dict|Begin"
COLUMN dictionary_end   FORMAT A5  HEAD "Dict|End"

SELECT
    name
  , TO_CHAR(first_time, 'DD-MON-YYYY HH24:MI:SS') first_time
  , dictionary_begin
  , dictionary_end
FROM
    v$archived_log
WHERE
      name IS NOT NULL
  AND first_time BETWEEN
      TO_DATE('18-OCT-2012 17:45:00', 'DD-MON-YYYY HH24:MI:SS') AND
      TO_DATE('18-OCT-2012 19:00:00', 'DD-MON-YYYY HH24:MI:SS')
ORDER BY
    sequence#;

                                                                                                          Dict  Dict 
Log File Name                                                                     First Time              Begin End  
--------------------------------------------------------------------------------- ----------------------- ----- -----
/u03/flash_recovery_area/ORA10G/archivelog/2012_10_18/o1_mf_1_3047_880yr881_.arc  18-OCT-2012 17:46:23    NO    NO
/u03/flash_recovery_area/ORA10G/archivelog/2012_10_18/o1_mf_1_3048_880yzv08_.arc  18-OCT-2012 17:56:24    NO    NO
/u03/flash_recovery_area/ORA10G/archivelog/2012_10_18/o1_mf_1_3049_880zlk2d_.arc  18-OCT-2012 18:00:26    NO    NO
/u03/flash_recovery_area/ORA10G/archivelog/2012_10_18/o1_mf_1_3050_881059l7_.arc  18-OCT-2012 18:10:25    NO    NO
/u03/flash_recovery_area/ORA10G/archivelog/2012_10_18/o1_mf_1_3051_8810qz36_.arc  18-OCT-2012 18:20:25    NO    NO
/u03/flash_recovery_area/ORA10G/archivelog/2012_10_18/o1_mf_1_3052_8810shg8_.arc  18-OCT-2012 18:30:23    NO    NO
/u03/flash_recovery_area/ORA10G/archivelog/2012_10_18/o1_mf_1_3053_8810sr4p_.arc  18-OCT-2012 18:31:11    YES   YES
/u03/flash_recovery_area/ORA10G/archivelog/2012_10_18/o1_mf_1_3054_8811dmfj_.arc  18-OCT-2012 18:31:20    NO    NO


SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining Scoring Engine
and Real Application Testing options


[oracle@packmule ~]$ cd /u03/flash_recovery_area/ORA10G/archivelog/2012_10_18
[oracle@packmule 2012_10_18]$ scp o1_mf_1_3049_880zlk2d_.arc o1_mf_1_305[0123]_*.arc testnode1:/u03/app/oracle/oraarch/ORA10G/
oracle@testnode1's password: xxxxxxxxxx
o1_mf_1_3049_880zlk2d_.arc                      100%  691KB 691.0KB/s   00:00
o1_mf_1_3050_881059l7_.arc                      100%  131KB 131.0KB/s   00:00
o1_mf_1_3051_8810qz36_.arc                      100%   82KB  82.0KB/s   00:00
o1_mf_1_3052_8810shg8_.arc                      100% 5120     5.0KB/s   00:00
o1_mf_1_3053_8810sr4p_.arc                      100% 9223KB   9.0MB/s   00:00


[oracle@packmule 2012_10_18]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.4.0 - Production on Thu Oct 18 18:53:37 2012

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.

SQL> CONNECT miner/miner@//testnode1:1521/ora11g.idevelopment.info
Connected.


BEGIN
    DBMS_LOGMNR.ADD_LOGFILE (
        LogFileName => '/u03/app/oracle/oraarch/ORA10G/o1_mf_1_3049_880zlk2d_.arc',
        options => DBMS_LOGMNR.NEW
    );
END;
/

PL/SQL procedure successfully completed.


BEGIN
    DBMS_LOGMNR.ADD_LOGFILE (
        LogFileName => '/u03/app/oracle/oraarch/ORA10G/o1_mf_1_3050_881059l7_.arc',
        options => DBMS_LOGMNR.ADDFILE
    );
END;
/

PL/SQL procedure successfully completed.


BEGIN
    DBMS_LOGMNR.ADD_LOGFILE (
        LogFileName => '/u03/app/oracle/oraarch/ORA10G/o1_mf_1_3051_8810qz36_.arc',
        options => DBMS_LOGMNR.ADDFILE
    );
END;
/

PL/SQL procedure successfully completed.


BEGIN
    DBMS_LOGMNR.ADD_LOGFILE (
        LogFileName => '/u03/app/oracle/oraarch/ORA10G/o1_mf_1_3052_8810shg8_.arc',
        options => DBMS_LOGMNR.ADDFILE
    );
END;
/

PL/SQL procedure successfully completed.


BEGIN
    DBMS_LOGMNR.ADD_LOGFILE (
        LogFileName => '/u03/app/oracle/oraarch/ORA10G/o1_mf_1_3053_8810sr4p_.arc',
        options => DBMS_LOGMNR.ADDFILE
    );
END;
/

PL/SQL procedure successfully completed.


COLUMN filename         FORMAT A66 HEAD "Log File Name"
COLUMN type             FORMAT A8  HEAD "Type"
COLUMN status           FORMAT A33 HEAD "Status"
COLUMN dictionary_begin FORMAT A5  HEAD "Dict|Begin"
COLUMN dictionary_end   FORMAT A5  HEAD "Dict|End"

SELECT
    filename
  , type
  , ( CASE status
        WHEN 0 THEN 'Redo log file will be processed.'
        WHEN 1 THEN 'First log file to be processed.'
        WHEN 2 THEN 'Redo log file will not be processed (pruned).'
        WHEN 4 THEN 'Redo log file is missing from LogMiner list.'
      END) as status
  , dictionary_begin
  , dictionary_end
FROM
    v$logmnr_logs
ORDER BY
    log_id;

                                                                                                              Dict  Dict 
Log File Name                                                      Type     Status                            Begin End  
------------------------------------------------------------------ -------- --------------------------------- ----- -----
/u03/app/oracle/oraarch/ORA10G/o1_mf_1_3049_880zlk2d_.arc          ARCHIVE  Redo log file will be processed.  NO    NO
/u03/app/oracle/oraarch/ORA10G/o1_mf_1_3050_881059l7_.arc          ARCHIVE  Redo log file will be processed.  NO    NO
/u03/app/oracle/oraarch/ORA10G/o1_mf_1_3051_8810qz36_.arc          ARCHIVE  Redo log file will be processed.  NO    NO
/u03/app/oracle/oraarch/ORA10G/o1_mf_1_3052_8810shg8_.arc          ARCHIVE  Redo log file will be processed.  NO    NO
/u03/app/oracle/oraarch/ORA10G/o1_mf_1_3053_8810sr4p_.arc          ARCHIVE  Redo log file will be processed.  YES   YES


BEGIN
    DBMS_LOGMNR.START_LOGMNR (
        options => DBMS_LOGMNR.DICT_FROM_REDO_LOGS +
                   DBMS_LOGMNR.PRINT_PRETTY_SQL
    );
END;
/

PL/SQL procedure successfully completed.


COLUMN username   FORMAT A8
COLUMN operation  FORMAT A9
COLUMN sql_redo   FORMAT A25 WORD_WRAPPED
COLUMN sql_undo   FORMAT A25 WORD_WRAPPED
COLUMN timestamp  FORMAT A20

SELECT 
    username
  , operation
  , 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 = 'HR';

USERNAME OPERATION SQL_REDO                  SQL_UNDO                  TIMESTAMP                   SCN
-------- --------- ------------------------- ------------------------- -------------------- ----------
SCOTT    INSERT    insert into               delete from               18-OCT-2012 18:05:06   63352304
                   "HR"."DEPARTMENTS"        "HR"."DEPARTMENTS"
                   values                    where
                   "DEPARTMENT_ID" = 310,    "DEPARTMENT_ID" = 310 and
                   "DEPARTMENT_NAME" =       "DEPARTMENT_NAME" =
                   'Engineering',            'Engineering' and
                   "MANAGER_ID" IS NULL,     "MANAGER_ID" IS NULL and
                   "LOCATION_ID" = 1700;     "LOCATION_ID" = 1700 and
                                             ROWID =
                                             'AAApwWAANAAAAKcAAb';

See the section Copying V$LOGMNR_CONTENTS for tips on how to retain the LogMiner contents and enhance performance when accessing the V$LOGMNR_CONTENTS private view.
BEGIN DBMS_LOGMNR.END_LOGMNR(); END; / PL/SQL procedure successfully completed.

Scenario 5: Using the CONTINUOUS_MINE Option

LogMiner needs to mine data in the redo log files in order to analyze changes made to the database. Up until to this point, any redo log files that were required to be analyzed by LogMiner needed to be explicitly added to the list using the DBMS_LOGMNR.ADD_LOGFILE procedure.
# First redo log file
BEGIN
    DBMS_LOGMNR.ADD_LOGFILE (
        LogFileName => '+FRA/racdb/archivelog/2012_10_22/thread_1_seq_5143.2392.797337181',
        options => DBMS_LOGMNR.NEW
    );
END;
/
After adding the first redo log file to the list, subsequent redo log files can be manually added so long as they are from the same database and associated with the same database RESETLOGS SCN for LogMiner to analyze.
# Subsequent redo log file(s)
BEGIN
    DBMS_LOGMNR.ADD_LOGFILE (
        LogFileName => '+FRA/racdb/archivelog/2012_10_22/thread_1_seq_5144.2394.797337779',
        options => DBMS_LOGMNR.ADDFILE
    );
END;
/
The V$LOGMNR_LOGS view could then be queried which contains one row for each redo log file in the current LogMiner session. When using the manual method of adding redo log files, LogMiner need not be connected to the source database.

The CONTINUOUS_MINE Option

Oracle introduced an alternative approach in Oracle 9i (9.2) that directs LogMiner to automatically find and create a list of redo log files (archived and online) for LogMiner to analyze after the LogMiner session has started. This is done using the CONTINUOUS_MINE option to the DBMS_LOGMNR.START_LOGMNR procedure. You can specify a date or SCN range to the DBMS_LOGMNR.START_LOGMNR procedure to find the data of interest or specify the first redo log file to start mining. LogMiner will use the database control file to find and add redo log files that satisfy the specified time or SCN range to the LogMiner redo log file list. When using the CONTINUOUS_MINE option, it is no longer necessary to map the time frame to an explicit set of redo log files.
The LogMiner session must be connected to the same database (the source database) that generated the redo log files when using the CONTINUOUS_MINE option. It also requires that the database be mounted and that archiving be enabled.
  Beginning with Oracle Database 10g Release 1 (10.1), the CONTINUOUS_MINE options is supported for use in an Oracle Real Application Clusters (Oracle RAC) environment.
Note that although the following example call specifies the dictionary from the online catalog, any LogMiner dictionary can be used:
ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS';

BEGIN
  DBMS_LOGMNR.START_LOGMNR (
    STARTTIME => '22-OCT-2012 10:30:00',
    ENDTIME   => '22-OCT-2012 10:45:00',
    OPTIONS   => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG +
                 DBMS_LOGMNR.CONTINUOUS_MINE
  );
END;
/
In the above example, the ALTER SESSION SET NLS_DATE_FORMAT statement was run first to avoid the need to specify the date format to the DBMS_LOGMNR.START_LOGMNR procedure call.
You can also direct LogMiner to automatically build a list of redo log files to analyze by specifying just one redo log file using DBMS_LOGMNR.ADD_LOGFILE, and then specifying the CONTINUOUS_MINE option when you start LogMiner. If only one redo log file is specified in the list for the LogMiner session, then LogMiner will assume the name of the next archived redo log file(s) based on the same directory location and subsequent log sequence numbers.
BEGIN
    DBMS_LOGMNR.ADD_LOGFILE (
        LogFileName => '+FRA/racdb/archivelog/2012_10_22/thread_1_seq_5159.2424.797346781',
        options => DBMS_LOGMNR.NEW
    );
END;
/

BEGIN
  DBMS_LOGMNR.START_LOGMNR (
    OPTIONS   => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG +
                 DBMS_LOGMNR.CONTINUOUS_MINE
  );
END;
/
The previously described method is more typical, however.
Keep the following in mind when using the CONTINUOUS_MINE option:

  • You need only specify the first log file to start mining, or simply provide a starting date or SCN to indicate to LogMiner where to begin mining logs.
  • The database control file will hold information about a limited number of archived redo log files, although the number of entries can be quite large. Query the V$ARCHIVED_LOGS view to determine which redo log file entries can be found by LogMiner.
    Even if an entry is listed in the database control file (and the V$ARCHIVED_LOGS view), the archived redo log file may not be accessible by LogMiner for various reasons. For example, the archived redo log file may have been deleted or moved from its location (for example, honoring a retention policy where a backup operation was performed to tape), or the directory where it resides may not be not available.
  • If you specify the CONTINUOUS_MINE option and an ending time or SCN that will occur in the future (or you do not specify an end time or SCN), a query of the V$LOGMNR_CONTENTS view will not finish until the database has generated redo log files beyond the specified time or SCN. In this scenario, LogMiner will automatically add archived redo log files to the LogMiner redo log file list as they are generated. In addition, in this scenario only, LogMiner may automatically remove redo log files from the list to keep it at 50 processed redo files. This is to save PGA memory as LogMiner automatically adds redo log files to the list. If LogMiner did not perform automated removal, memory could eventually be exhausted.
  • LogMiner can mine online redo logs. However, if the CONTINUOUS_MINE option is not specified, it is possible that the database is writing to the online redo log file at the same time that LogMiner is reading the online redo log file. If a log switch occurs while LogMiner is reading an online redo log file, the database will overwrite what LogMiner is attempting to read. The data that LogMiner returns if the file it is trying to read gets overwritten by the database is unpredictable.

Example 1 — Mining the Redo Log Files in a Given Date Range

This example demonstrates how to specify a date range of interest and mine the redo log files that satisfy that range. LogMiner will only report committed transactions (using the COMMITTED_DATA_ONLY option) whose effects may not have yet been made permanent in the datafiles.

  1. Connect as the MINER database user and set the date/time format for the SQL session.

    CONNECT miner/miner
    Connected.
    
    ALTER SESSION SET nls_date_format = 'DD-MON-YYYY HH24:MI:SS';
    
    Session altered.
  2. Start a new LogMiner session with a date (or SCN) range and specify the CONTINUOUS_MINE option.

    BEGIN
      DBMS_LOGMNR.START_LOGMNR (
        STARTTIME => '25-OCT-2012 15:00:00',
        ENDTIME   => '25-OCT-2012 15:30:00',
        OPTIONS   => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG +
                     DBMS_LOGMNR.COMMITTED_DATA_ONLY +
                     DBMS_LOGMNR.PRINT_PRETTY_SQL +
                     DBMS_LOGMNR.CONTINUOUS_MINE
      );
    END;
    /
    
    PL/SQL procedure successfully completed.
  3. Determine which archived redo log files have been automatically added to the list of log files LogMiner will analyze.

    COLUMN filename         FORMAT A66 HEAD "Log File Name"
    COLUMN low_time         FORMAT A21 HEAD "Low Time"
    COLUMN high_time        FORMAT A21 HEAD "High Time"
    COLUMN dictionary_begin FORMAT A5  HEAD "Dict|Begin"
    COLUMN dictionary_end   FORMAT A5  HEAD "Dict|End"
    
    SELECT
        filename
      , low_time
      , high_time
      , dictionary_begin
      , dictionary_end
    FROM
        v$logmnr_logs
    ORDER BY
        log_id;
    
                                                                                                                   Dict  Dict
    Log File Name                                                      Low Time              High Time             Begin End
    ------------------------------------------------------------------ --------------------- --------------------- ----- -----
    +FRA/racdb/archivelog/2012_10_25/thread_2_seq_4732.1517.797612407  25-OCT-2012 14:53:17  25-OCT-2012 15:00:06  NO    NO
    +FRA/racdb/archivelog/2012_10_25/thread_2_seq_4733.1513.797613711  25-OCT-2012 15:00:06  25-OCT-2012 15:21:50  NO    NO
    +FRA/racdb/archivelog/2012_10_25/thread_1_seq_5580.1518.797612405  25-OCT-2012 14:58:42  25-OCT-2012 15:00:04  NO    NO
    +FRA/racdb/archivelog/2012_10_25/thread_1_seq_5581.1516.797612443  25-OCT-2012 15:00:04  25-OCT-2012 15:00:43  NO    NO
    +FRA/racdb/archivelog/2012_10_25/thread_1_seq_5582.1515.797612721  25-OCT-2012 15:00:43  25-OCT-2012 15:05:21  NO    NO
    +FRA/racdb/archivelog/2012_10_25/thread_1_seq_5583.1514.797613709  25-OCT-2012 15:05:21  25-OCT-2012 15:21:48  NO    NO
    Note that the redo log files that LogMiner adds to the list may not contain the entire date or SCN range. When specifying the CONTINUOUS_MINE option, LogMiner only adds archived redo log files when the DBMS_LOGMNR.START_LOGMNR procedure is called. LogMiner will automatically add any remaining redo data within the date or SCN range from the online redo log files as needed during the query against V$LOGMNR_CONTENTS.
    Use the following query to determine whether the last log file added by LogMiner is the latest archived redo log file produced from the database.

    COLUMN name             FORMAT A66 HEAD "Log File Name"
    COLUMN first_time       FORMAT A21 HEAD "First Time"
    COLUMN completion_time  FORMAT A21 HEAD "Completion Time"
    
    SELECT
        name
      , first_time
      , completion_time
    FROM
        v$archived_log 
    WHERE
        sequence# = (select max(sequence#) from v$archived_log);
    
    Log File Name                                                      First Time            Completion Time
    ------------------------------------------------------------------ --------------------- ---------------------
    +FRA/racdb/archivelog/2012_10_25/thread_1_seq_5583.1514.797613709  25-OCT-2012 15:05:21  25-OCT-2012 15:21:48
    A similar query can be performed against V$LOGMNR_CONTENTS to determine the date range for the LogMiner session.

    COLUMN low_time         FORMAT A21 HEAD "Low Time"
    COLUMN high_time        FORMAT A21 HEAD "High Time"
    
    SELECT
        MIN(timestamp) as log_time
      , MAX(timestamp) as high_time
    FROM
        v$logmnr_contents;
    
    LOG_TIME             High Time
    -------------------- ---------------------
    25-OCT-2012 15:00:04 25-OCT-2012 15:29:18
  4. Query V$LOGMNR_CONTENTS for any data of interest. Include all COMMIT statements but disregard any Oracle auditing records (INSERT INTO "SYSTEM"."AUD$").

    COLUMN username   FORMAT A8
    COLUMN operation  FORMAT A9
    COLUMN sql_redo   FORMAT A25 WORD_WRAPPED
    COLUMN sql_undo   FORMAT A25 WORD_WRAPPED
    COLUMN timestamp  FORMAT A20
    
    SELECT 
        username
      , operation
      , sql_redo
      , sql_undo
      , TO_CHAR(timestamp, 'DD-MON-YYYY HH24:MI:SS') timestamp
      , scn
    FROM
        v$logmnr_contents
    WHERE
          username = 'SCOTT'
      AND operation IN ('INSERT', 'COMMIT')
      AND ( seg_owner NOT IN ('SYSTEM')  -- Disregard Oracle Auditing
            OR
            seg_owner IS NULL -- Still include COMMITs
          )
    ORDER BY
        timestamp;
    
    USERNAME OPERATION SQL_REDO                  SQL_UNDO                  TIMESTAMP                   SCN
    -------- --------- ------------------------- ------------------------- -------------------- ----------
    SCOTT    COMMIT    commit;                                             25-OCT-2012 15:00:04  109026619
    SCOTT    COMMIT    commit;                                             25-OCT-2012 15:00:43  109028429
    SCOTT    COMMIT    commit;                                             25-OCT-2012 15:02:12  109028564
    SCOTT    INSERT    insert into               delete from               25-OCT-2012 15:02:12  109028564
                       "HR"."DEPARTMENTS"        "HR"."DEPARTMENTS"
                       values                    where
                       "DEPARTMENT_ID" = 430,    "DEPARTMENT_ID" = 430 and
                       "DEPARTMENT_NAME" =       "DEPARTMENT_NAME" =
                       'Computer Scientists',    'Computer Scientists' and
                       "MANAGER_ID" IS NULL,     "MANAGER_ID" IS NULL and
                       "LOCATION_ID" = 1700;     "LOCATION_ID" = 1700 and
                                                 ROWID =
                                                 'AAAQ08AAEAAAACtAAB';
    
    SCOTT    COMMIT    commit;                                             25-OCT-2012 15:02:16  109028577
    SCOTT    COMMIT    commit;                                             25-OCT-2012 15:05:21  109029883
    SCOTT    COMMIT    commit;                                             25-OCT-2012 15:08:19  109030629
    SCOTT    INSERT    insert into               delete from               25-OCT-2012 15:08:20  109030630
                       "HR"."DEPARTMENTS"        "HR"."DEPARTMENTS"
                       values                    where
                       "DEPARTMENT_ID" = 440,    "DEPARTMENT_ID" = 440 and
                       "DEPARTMENT_NAME" = 'IT', "DEPARTMENT_NAME" = 'IT'
                       "MANAGER_ID" IS NULL,     and
                       "LOCATION_ID" = 1800;     "MANAGER_ID" IS NULL and
                                                 "LOCATION_ID" = 1800 and
                                                 ROWID =
                                                 'AAAQ08AAEAAAACtAAC';
    
    SCOTT    COMMIT    commit;                                             25-OCT-2012 15:08:22  109030644
    SCOTT    COMMIT    commit;                                             25-OCT-2012 15:21:48  109032856
    SCOTT    COMMIT    commit;                                             25-OCT-2012 15:22:11  109032894
    SCOTT    INSERT    insert into               delete from               25-OCT-2012 15:22:11  109032894
                       "HR"."DEPARTMENTS"        "HR"."DEPARTMENTS"
                       values                    where
                       "DEPARTMENT_ID" = 450,    "DEPARTMENT_ID" = 450 and
                       "DEPARTMENT_NAME" =       "DEPARTMENT_NAME" =
                       'Mathematics',            'Mathematics' and
                       "MANAGER_ID" IS NULL,     "MANAGER_ID" IS NULL and
                       "LOCATION_ID" = 1700;     "LOCATION_ID" = 1700 and
                                                 ROWID =
                                                 'AAAQ08AAEAAAACtAAA';
    
    SCOTT    COMMIT    commit;                                             25-OCT-2012 15:22:13  109032901
  5. End the LogMiner session.

    BEGIN
        DBMS_LOGMNR.END_LOGMNR();
    END;
    /
    
    PL/SQL procedure successfully completed.

Example 2 — Using Continuous Mining to Include Future Values in a Query

This example demonstrates how to specify a query on V$LOGMNR_CONTENTS not finish until some future time occurs or SCN is reached by using the CONTINUOUS_MINE option. This is done by setting either the end time (ENDTIME) or end SCN (ENDSCN) parameter when calling the DBMS_LOGMNR.START_LOGMNR procedure to a time in the future or to an SCN value that has not yet been reached.
This example assumes you want to monitor all changes made to the table HR.DEPARTMENTS from now until 3 hours in the future and that you are using the dictionary in the online catalog.

  1. Connect as the MINER database user and set the date/time format for the SQL session.

    CONNECT miner/miner
    Connected.
    
    ALTER SESSION SET nls_date_format = 'DD-MON-YYYY HH24:MI:SS';
    
    Session altered.
  2. Start a new LogMiner session with an end date 3 hours from now and specify the CONTINUOUS_MINE option.

    BEGIN
      DBMS_LOGMNR.START_LOGMNR (
        STARTTIME => SYSDATE,
        ENDTIME   => SYSDATE + 3/24,
        OPTIONS   => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG +
                     DBMS_LOGMNR.PRINT_PRETTY_SQL +
                     DBMS_LOGMNR.CONTINUOUS_MINE
      );
    END;
    /
    
    PL/SQL procedure successfully completed.
  3. Query V$LOGMNR_CONTENTS for any data of interest. The SELECT operation will not complete until it encounters the first redo log file record that is generated after the time range of interest (3 hours from now). You can end the SELECT operation prematurely by entering Ctrl-C.
    Note that this example specifies the SET ARRAYSIZE statement so that rows are displayed as they are entered in the redo log file. If you do not specify the SET ARRAYSIZE statement, rows are not returned until the SQL internal buffer is full.

    SET ARRAYSIZE 1
    
    COLUMN username   FORMAT A8
    COLUMN operation  FORMAT A9
    COLUMN sql_redo   FORMAT A25 WORD_WRAPPED
    COLUMN timestamp  FORMAT A20
    
    SELECT 
        username
      , operation
      , sql_redo
      , TO_CHAR(timestamp, 'DD-MON-YYYY HH24:MI:SS') timestamp
      , scn
    FROM
        v$logmnr_contents
    WHERE
        (seg_owner = 'HR' AND table_name = 'DEPARTMENTS')
        OR
        (operation = 'COMMIT' AND username NOT IN ('SYS', 'UNKNOWN'));
    
    USERNAME OPERATION SQL_REDO                  TIMESTAMP                   SCN
    -------- --------- ------------------------- -------------------- ----------
    SCOTT    COMMIT    commit;                   26-OCT-2012 12:22:58  109364105
    SCOTT    INSERT    insert into               26-OCT-2012 12:22:58  109364105
                       "HR"."DEPARTMENTS"
                       values
                       "DEPARTMENT_ID" = 500,
                       "DEPARTMENT_NAME" =
                       'Computer Scientists',
                       "MANAGER_ID" IS NULL,
                       "LOCATION_ID" = 1700;
    
    SCOTT    COMMIT    commit;                   26-OCT-2012 12:23:08  109364124
    SCOTT    COMMIT    commit;                   26-OCT-2012 12:24:43  109364340
    SCOTT    INSERT    insert into               26-OCT-2012 12:24:43  109364340
                       "HR"."DEPARTMENTS"
                       values
                       "DEPARTMENT_ID" = 510,
                       "DEPARTMENT_NAME" = 'IT',
                       "MANAGER_ID" IS NULL,
                       "LOCATION_ID" = 1800;
    
    SCOTT    COMMIT    commit;                   26-OCT-2012 12:24:43  109364344
    SCOTT    COMMIT    commit;                   26-OCT-2012 12:27:35  109364831
    SCOTT    INSERT    insert into               26-OCT-2012 12:27:35  109364832
                       "HR"."DEPARTMENTS"
                       values
                       "DEPARTMENT_ID" = 520,
                       "DEPARTMENT_NAME" =
                       'Mathematics',
                       "MANAGER_ID" IS NULL,
                       "LOCATION_ID" = 1700;
    
    SCOTT    COMMIT    commit;                   26-OCT-2012 12:27:35  109364835
    SCOTT    UPDATE    update "HR"."DEPARTMENTS" 26-OCT-2012 12:30:13  109365178
                       set
                       "DEPARTMENT_NAME" = 'IT -
                       Admin'
                       where
                       "DEPARTMENT_ID" = 510 and
                       "DEPARTMENT_NAME" = 'IT'
                       and
                       ROWID =
                       'AAAQ08AAEAAAACrAAC';
    
    SCOTT    COMMIT    commit;                   26-OCT-2012 12:30:20  109365348
    SCOTT    DELETE    delete from               26-OCT-2012 12:31:21  109365525
                       "HR"."DEPARTMENTS"
                       where
                       "DEPARTMENT_ID" = 500 and
                       "DEPARTMENT_NAME" =
                       'Computer Scientists' and
                       "MANAGER_ID" IS NULL and
                       "LOCATION_ID" = 1700 and
                       ROWID =
                       'AAAQ08AAEAAAACrAAB';
    
    SCOTT    DELETE    delete from               26-OCT-2012 12:31:21  109365526
                       "HR"."DEPARTMENTS"
                       where
                       "DEPARTMENT_ID" = 510 and
                       "DEPARTMENT_NAME" = 'IT -
                       Admin' and
                       "MANAGER_ID" IS NULL and
                       "LOCATION_ID" = 1800 and
                       ROWID =
                       'AAAQ08AAEAAAACrAAC';
    
    SCOTT    DELETE    delete from               26-OCT-2012 12:31:21  109365526
                       "HR"."DEPARTMENTS"
                       where
                       "DEPARTMENT_ID" = 520 and
                       "DEPARTMENT_NAME" =
                       'Mathematics' and
                       "MANAGER_ID" IS NULL and
                       "LOCATION_ID" = 1700 and
                       ROWID =
                       'AAAQ08AAEAAAACrAAA';
    
    SCOTT    COMMIT    commit;                   26-OCT-2012 12:31:30  109365570
    
    <Ctrl-C>
    
    ERROR:
    ORA-01013: user requested cancel of current operation
  4. End the LogMiner session.

    BEGIN
        DBMS_LOGMNR.END_LOGMNR();
    END;
    /
    
    PL/SQL procedure successfully completed.
    
    
    Ref: http://www.idevelopment.info/data/Oracle/DBA_tips/LogMiner/