Skip to main content

Using Log Mining

Today I will show you how to use log mining.

Create new tablespace and move objects which belongs SYSAUX tablespace to new tablespace.

SQL> create tablespace test_tbs datafile '/home/oracle/oracle/product/10.2.0/oradata/mydb/test_tbs01.dbf' size 100M autoextend on maxsize unlimited;

Tablespace created.

SQL> EXEC DBMS_LOGMNR_D.SET_TABLESPACE('TEST_TBS');

PL/SQL procedure successfully completed.

SQL>

Now start Log Mining and load archive log file into it


Firstly, I created table under demo user and made some DML operations. Then using alter system switch logfile I enforce archive current log file.
  
SQL> create table demo.test(id number, str varchar2(10));

Table created.

SQL> insert into demo.test values(1,'a');

1 row created.

SQL> insert into demo.test values(2,'b');

1 row created.

SQL> commit;

Commit complete.

SQL> delete from demo.test where id=2;

1 row deleted.

SQL> commit;

Commit complete.

SQL> alter system switch logfile;

System altered.

SQL>

Check archivelog files --select the latest one
SQL> select name, status, archived, blocks from v$archived_log where status='A';

NAME                                                                                                        STATUS   ARCH     BLOCKS-----------------------------------------------------------------------------------------------------------------------------------------------------------
/home/oracle/oracle/product/10.2.0/oradata/mydb/ARCH/arch_1_76_770556397.arc A        YES      10146
/home/oracle/oracle/product/10.2.0/oradata/mydb/ARCH/arch_1_77_770556397.arc A        YES       35742
/home/oracle/oracle/product/10.2.0/oradata/mydb/ARCH/arch_1_78_770556397.arc A        YES       12014
/home/oracle/oracle/product/10.2.0/oradata/mydb/ARCH/arch_1_79_770556397.arc A        YES       11974
/home/oracle/oracle/product/10.2.0/oradata/mydb/ARCH/arch_1_80_770556397.arc A        YES       24974

SQL> exec DBMS_LOGMNR.ADD_LOGFILE('/home/oracle/oracle/product/10.2.0/oradata/mydb/ARCH/arch_1_80_770556397.arc',DBMS_LOGMNR.NEW);

PL/SQL procedure successfully completed.

SQL> 


Now perform log mining using DBMS_LOGMNR.START_LOGMNR


SQL> exec DBMS_LOGMNR.START_LOGMNR(OPTIONS=>DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG+DBMS_LOGMNR.COMMITTED_DATA_ONLY);

PL/SQL procedure successfully completed.

SQL> 



Now check below query

SQL> SELECT USERNAME, TO_CHAR(TIMESTAMP,'DD-MON-YYYYYHH24:MI:SS') TIMESTAMP, SESSION_INFO, SQL_REDO, SQL_UNDO FROM V$LOGMNR_CONTENTS
WHERE SEG_OWNER='DEMO'  AND TABLE_NAME='TEST';  

USERNAME                       TIMESTAMP
------------------------------ --------------------
SESSION_INFO
--------------------------------------------------------------------------------
SQL_REDO
--------------------------------------------------------------------------------
SQL_UNDO
--------------------------------------------------------------------------------
UNKNOWN                        04-DEC-2012214:16:58
UNKNOWN
create table demo.test(id number, str varchar2(10));



USERNAME                       TIMESTAMP
------------------------------ --------------------
SESSION_INFO
--------------------------------------------------------------------------------
SQL_REDO
--------------------------------------------------------------------------------
SQL_UNDO
--------------------------------------------------------------------------------
UNKNOWN                        04-DEC-2012214:18:06
UNKNOWN
insert into "DEMO"."TEST"("ID","STR") values ('1','a');
delete from "DEMO"."TEST" where "ID" = '1' and "STR" = 'a' and ROWID = 'AAAN6EAA
EAAAALUAAA';

USERNAME                       TIMESTAMP
------------------------------ --------------------
SESSION_INFO
--------------------------------------------------------------------------------
SQL_REDO
--------------------------------------------------------------------------------
SQL_UNDO
--------------------------------------------------------------------------------

UNKNOWN                        04-DEC-2012214:18:19
UNKNOWN
insert into "DEMO"."TEST"("ID","STR") values ('2','b');
delete from "DEMO"."TEST" where "ID" = '2' and "STR" = 'b' and ROWID = 'AAAN6EAA

USERNAME                       TIMESTAMP
------------------------------ --------------------
SESSION_INFO
--------------------------------------------------------------------------------
SQL_REDO
--------------------------------------------------------------------------------
SQL_UNDO
--------------------------------------------------------------------------------
EAAAALUAAB';

UNKNOWN                        04-DEC-2012214:18:41
UNKNOWN
delete from "DEMO"."TEST" where "ID" = '2' and "STR" = 'b' and ROWID = 'AAAN6EAA

USERNAME                       TIMESTAMP
------------------------------ --------------------
SESSION_INFO
--------------------------------------------------------------------------------
SQL_REDO
--------------------------------------------------------------------------------
SQL_UNDO
--------------------------------------------------------------------------------
EAAAALUAAB';
insert into "DEMO"."TEST"("ID","STR") values ('2','b');


SQL> spool off;
SQL> 



Open spooled file via any text editor.

ex : gedit output_logminer.txt


You can filter your query too

SQL> SELECT USERNAME, TO_CHAR(TIMESTAMP,'DD-MON-YYYYYHH24:MI:SS') TIMESTAMP, SESSION_INFO, SQL_REDO, SQL_UNDO FROM V$LOGMNR_CONTENTS
WHERE SEG_OWNER='DEMO'  AND TABLE_NAME='TEST' AND OPERATION='DELETE';

USERNAME    TIMESTAMP SESSION_INFO SQL_REDO SQL_UNDO
----------------------------------------------------------------------------------------------------------------------------------------------------------------
UNKNOWN                        04-DEC-2012214:18:41
UNKNOWN
delete from "DEMO"."TEST" where "ID" = '2' and "STR" = 'b' and ROWID = 'AAAN6EAA
EAAAALUAAB';
insert into "DEMO"."TEST"("ID","STR") values ('2','b');

USERNAME                       TIMESTAMP
------------------------------ --------------------
SESSION_INFO
--------------------------------------------------------------------------------
SQL_REDO
--------------------------------------------------------------------------------
SQL_UNDO
--------------------------------------------------------------------------------


SQL>

Comments

Popular posts from this blog

Rman encryption and other techniques

Today I will demonstrate Recovery Manager features, especially encryption and some other techniques. First of all let me note about RMAN backup encryption. Staring from Oracle 10g RMAN now creates encrypted backups that cannot be restored by unauthorized people. There are 3 modes of backup encryption: * Transparent encryption * Password encryption * Dual-mode encryption using either transparent or password encryption All RMAN backups are not encrypted but you can encrypt any RMAN backup in the form of a backup set. In this tutorial I will show you how to configure Password encryption. Let`s finish talking and start to demonstrate. check parameters with "SHOW ALL" command, by default encryption is OFF RMAN> show all; RMAN configuration parameters are: CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default CONFIGURE BACKUP OPTIMIZATION OFF; # default CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default CONFIGURE CONTROLFILE AUTOBACKUP ON; CONFIGURE CONTR...

ORA-03206: maximum file size of (5242880) blocks in AUTOEXTEND clause is out of range

Today when I want to change max size of datafile I got strange error. ALTER DATABASE DATAFILE '/u01/app/oracle/oradata/MYDB/users01.dbf' AUTOEXTEND ON NEXT 1280K MAXSIZE 32GB ORA-03206: maximum file size of (5242880) blocks in AUTOEXTEND clause is out of range Here is reason: The maximum file size for an autoextendable file has exceeded the maximum number of blocks allowed. After research internet I found that instead of using 32GB we can use 32767M. (same values but in MB). Or you may use 31GB too. ALTER DATABASE DATAFILE '/u01/app/oracle/oradata/MYDB/users01.dbf' AUTOEXTEND ON NEXT 1280K MAXSIZE 32767M;

Fix ORA-01139: RESETLOGS option only valid after an incomplete database recovery

While shutting down my TEST database process was hanged. Then I had to use shutdown abort. But when I wanted to start database it did not open. SQL> select name from v$database; NAME --------- TEST SQL> shut abort; ORACLE instance shut down. SQL> startup mount ORACLE instance started. Total System Global Area 6597406720 bytes Fixed Size 2265664 bytes Variable Size 3204451776 bytes Database Buffers 3372220416 bytes Redo Buffers 18468864 bytes Database mounted. SQL> alter database open; alter database open * ERROR at line 1: ORA-03113: end-of-file on communication channel Process ID: 6552 Session ID: 191 Serial number: 3  What`s wrong?  SQL> alter database open resetlogs; ERROR:    ORA-03114: not connected to ORACLE    SQL> exit Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Pr...