Monday, October 17, 2011

Manually corrupting the data block in Linux and recovering it using BLOCKRECOVER command of RMAN

Manually corrupting the data block in Linux and recovering it using BLOCKRECOVER command of RMAN
Sometimes, in order to test the RMAN’s  BLOCKRECOVER command, we need to corrupt the specific data block and recover it for testing purpose.
To do it in Linux, use dd command. In the following example, let’s create a table and corrupt it manually
 (Don’t try it on the production database  or you’ll be fired work from the job )


SQL> create table manu (id number ,name char(15));
Table created.

SQL> insert into manu values(1,'tanu');
1 row created.

SQL> commit;
Commit complete.

SQL> select * from manu;
        ID   NAME
———-------
         1   tanu


SQL> select header_blockfrom dba_segments where segment_name=’MANU’;
HEADER_BLOCK
————
          61201

[oracle@localhost ~]$ dd of=/u01/app/oradata/orcl/system01.dbf bs=8192 conv=notrunc seek=61202 << EOF
> testing corruption
> EOF
0+1 records in
0+1 records out


SQL> ALTER SYSTEM FLUSH BUFFER_CACHE;
System altered.


SQL> select * from manu;
select * from manu
                     *
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 1, block # 61202)
ORA-01110: data file 1: ‘/u01/app/oradata/orcl/system01.dbf’

SQL>

Now connect to the RMAN and recover the data block (not the whole datafile or database) using BLOCKRECOVER command as follows:
SQL> ! rman target /
RMAN>

RMAN>blockrecover datafile 1 block 61202;
Starting blockrecover at 15-OCT-11
<… underprocess … >
<… underprocess … >

Finished blockrecover at 15-OCT-11
RMAN> exit

Connect to SQL*Plus and query the table:SQL> select * from manu;
        ID NAME
———--------
         1     tanu




ALL THE BEST TO ALL...... :)