Tuesday, 7 May 2013

"truncate table" and oracle redo logs


Is it "truncate" statement written to the oracle redo logs? Yes, but just as any other DDL command, just as "truncate table <table_name>.

Let's look at an example below, where I've used the logmnr oracle utility to search through the redo logs:

First we create a table t and then truncate it:


SQL> create table t as select * from obj;

Table created.


SQL> truncate table t;

Table truncated.

Now we're going to switch the logfile and then initialize the Logmnr:

SQL> alter system switch logfile;

System altered.

SQL> execute DBMS_LOGMNR.ADD_LOGFILE('/pete_pbmlol/redoB1/redo_pbmlol_B1.dbf',options => dbms_logmnr.new);

PL/SQL procedure successfully completed.

SQL> execute DBMS_LOGMNR.START_LOGMNR(options => -
                                dbms_logmnr.dict_from_online_catalog);
>
PL/SQL procedure successfully completed.

We create a table based on the logmnr results, for convenience:

SQL> create table mycontents nologging parallel(degree 8)
  2  tablespace tools
  3   as select * from v$logmnr_contents;

Table created.

The moment of truth, we query sql_redo with regards to our table:


SQL> select sql_redo from mycontents where TABLE_NAME='T';

SQL_REDO
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
create table t as select * from obj;
truncate table t;
Unsupported


 And there is no undo statement, as expected :-)


SQL> select sql_undo  from mycontents where TABLE_NAME='T';

SQL_UNDO
--------------------------------------------------------------------------------


Unsupported

No comments:

Post a Comment