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

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...

Fix: ORA-13639: The current operation was interrupted because it timed out.

Sometimes SQL Tuning Advisor interrupts cause time limit took more than defined. You have to analyze it or increase value. Here you can see increasing of value. Example result of sql select                  execution_name, advisor_name,                  to_char(execution_start,'dd-mon-yy hh:mi:ss') execution_start,                  to_char(execution_end,'dd-mon-yy hh:mi:ss') execution_end, status,error_message from dba_advisor_executions where task_name = 'SYS_AUTO_SQL_TUNING_TASK' order by execution_start; Check value of TIME_LIMIT`s parameter : SQL> column parameter_value for A35 SQL> select parameter_name, parameter_value from dba_advisor_parameters where task_name = 'SYS_AUTO_SQL_TUNING_TASK' and parameter_name in ('TIME_LIMIT', 'DEFAULT_EXECUTION_TYP...

How to fix ORA-26040: Data block was loaded using the NOLOGGING option

Today I faced with new ORA error. After solving I want to share this experience with yours. So, today 5`th datafile of my database was corrupted (/u01/app/oracle/oradata/ulfet_db/example01.dbf). After recover via RMAN I saw strange error. RMAN> recover datafile 5 block 443; Starting recover at 24-MAR-13 using channel ORA_DISK_1 channel ORA_DISK_1: restoring block(s) channel ORA_DISK_1: specifying block(s) to restore from backup set restoring blocks of datafile 00005 channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/ULFET_DB/backupset/2013_03_24/o1_mf_nnndf_TAG20130324T223233_8nykp220_.bkp channel ORA_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/ULFET_DB/backupset/2013_03_24/o1_mf_nnndf_TAG20130324T223233_8nykp220_.bkp tag=TAG20130324T223233 channel ORA_DISK_1: restored block(s) from backup piece 1 channel ORA_DISK_1: block restore complete, elapsed time: 00:00:03 starting media recovery media recovery complete, elapsed ti...