Friday, August 16, 2013

Database -- Damage/Corrupt Oracle Block using dd command

To  implement our recovery test scenarios, we need to have real corruptions sometimes.
Following method can be used to corrupt an Oracle Block..
In this method we will use dd command in Linux/Unix to corrupt a datafile 's block.

First, we copy the datafile up to the block no(block we want to corrupt) into a temp file.
Secondly, we create another temp file by copying one unrelated block into it.
Then , we copy the datafile contents by starting from the block that we want to corrupt +1 into another tempfile.
Finally we concetanate this tree files into a single file , and overwrite the actual datafile with this single file..

Some information about dd;

if = input file
of = output file
bs = block size
count = copy only BLOCKS input blocks
skip  = skip BLOCKS ibs-sized blocks at start of input
block size (bs) option will override both ibs and obs.

For example to corruput block no 15 on a database with blocksize 8192 bytes;

shutdown the Oracle Database

copy /actual_path_of_the_datafile/datafilename.dbf /tmp/

cd /tmp

dd if=datafilename.dbf of=f1 bs=8192 count=15
dd if=datafilename.dbf of=f2 bs=8192 count=1
dd if=datafilename.dbf of=f3 bs=8192 skip=16

cat f1 > /tmp/datafilename.dbf
cat f2 >> /tmp/datafilename.dbf
cat f3 >> /tmp/datafilename.dbf

cp datafilename.dbf /actual_path_of_the_datafile/datafilename.dbf

start the Oracle Database and issue the relevant queries, that will use the corrupted block..
Following errors will be encountered;

ORA-01578: ORACLE data block corrupted (file # 4, block # 15)
ORA-01110: data file 4: '/actual_path_of_the_datafile/datafilename.dbf'

So, we have a corrupt block now.. At this point, we can test our recovery scenarios-- like Rman 's blockrecover..


No comments :

Post a Comment

If you will ask a question, please don't comment here..

For your questions, please create an issue into my forum.

Forum Link: http://ermanarslan.blogspot.com.tr/p/forum.html

Register and create an issue in the related category.
I will support you from there.