Professional Documents
Culture Documents
Amit Oracle DBA Blog: Manually corrupting the data block in Linux and recovering it using BLOCKRECOVER command of RMAN
In order to test the RMANs 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, lets create a table and corrupt it
manually
1. For the purpose of this practice, will create a separate tablespace and a new schema user.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
b. Create an user say test and assign quota to the test_corrupt tablespace
SQL> create user test identified by test123 default tablespace test_corrupt
quota unlimited on test_corrupt;
User created.
1/10
06/01/2015
Amit Oracle DBA Blog: Manually corrupting the data block in Linux and recovering it using BLOCKRECOVER command of RMAN
3. Insert some dummy records into the table by writing a simple for loop block as shown:
SQL> begin
for i in 1..10000
loop
insert into emp values(i);
end loop;
end;
/
PL/SQL procedure successfully completed.
4. Take the RMAN backup, either full database or tablespace level backup before corrupting the block.
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
2/10
06/01/2015
Amit Oracle DBA Blog: Manually corrupting the data block in Linux and recovering it using BLOCKRECOVER command of RMAN
100
SYSTEM
***
/data/oracle/app/oracle/oradata/TESTDB/system.dbf
100
SYSTEM
***
/data/oracle/app/oracle/oradata/TESTDB/user04.dbf
100
SYSAUX
***
/data/oracle/app/oracle/oradata/TESTDB/sysaux.dbf
500
UNDOTBS
***
/data/oracle/app/oracle/oradata/TESTDB/undo.dbf
1024
TEST
***
/data/oracle/app/oracle/oradata/TESTDB/test1_tmp.dbf
10
TEST_CORRUPT
***
/data/oracle/app/oracle/oradata/TESTDB/test_corrupt.dbf
1000
TEMP
1000
/data/oracle/app/oracle/oradata/TESTDB/temp1.dbf
3/10
06/01/2015
Amit Oracle DBA Blog: Manually corrupting the data block in Linux and recovering it using BLOCKRECOVER command of RMAN
RMAN>
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
So the header of segment (table) is block 130, so if the block 131,132,133, get some noise it will eventually end up as
a datafile with corrupted blocks
[oracle@NVMBD1BZY150D00 ~]$ dd
of=/data/oracle/app/oracle/oradata/TESTDB/test_corrupt.dbf bs=8192 conv=notrunc
data:text/html;charset=utf-8,%3Ch3%20class%3D%22post-title%20entry-title%22%20itemprop%3D%22name%22%20style%3D%22margin%3A%200px%3B
4/10
06/01/2015
Amit Oracle DBA Blog: Manually corrupting the data block in Linux and recovering it using BLOCKRECOVER command of RMAN
6. To query the data, connect to the test user and query the table emp
SQL> ALTER SYSTEM FLUSH BUFFER_CACHE;
System altered.
The query returns complains of block corruption in file 6, and the block numbered 131 is being reported as
corrupt.
This is the methods to be followed in order to corrupt the Oracle data blocks.
Lets us see, how to identify the corrupted blocks and recover them.
7. Let us see what are the blocks are corrupted in test_corrupt01.dbf datafile by running dbv (DBVERIFY) utility.
data:text/html;charset=utf-8,%3Ch3%20class%3D%22post-title%20entry-title%22%20itemprop%3D%22name%22%20style%3D%22margin%3A%200px%3B
5/10
06/01/2015
Amit Oracle DBA Blog: Manually corrupting the data block in Linux and recovering it using BLOCKRECOVER command of RMAN
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
: 1280
(Data) : 0
(Index): 0
(Seg) : 0
data:text/html;charset=utf-8,%3Ch3%20class%3D%22post-title%20entry-title%22%20itemprop%3D%22name%22%20style%3D%22margin%3A%200px%3B
6/10
06/01/2015
Amit Oracle DBA Blog: Manually corrupting the data block in Linux and recovering it using BLOCKRECOVER command of RMAN
: 1129
:1
:0
:0
: 678748 (0.678748)
This utility scans all the blocks in a given datafile and outputs the corrupt blocks. In this case, there was only
one block marked as corrupt. Make a note of all the corrupted blocks as we need to recover them to previous
state.
8. Start RMAN session and recover all the corrupted blocks.
The beauty of RMAN is that it recovers only corrupted blocks and we need to recover only those corrupt
blocks instead of entire datafile.
[oracle@NVMBD1BZY150D00 ~]$ rman target /
Recovery Manager: Release 11.2.0.3.0 - Production on Fri Dec 19 18:22:41 2014
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Report the Schema to know the status of target database, gathers the information from control file
RMAN> report schema;
7/10
06/01/2015
Amit Oracle DBA Blog: Manually corrupting the data block in Linux and recovering it using BLOCKRECOVER command of RMAN
100
SYSTEM
***
/data/oracle/app/oracle/oradata/TESTDB/system.dbf
100
SYSTEM
***
/data/oracle/app/oracle/oradata/TESTDB/user04.dbf
100
SYSAUX
***
/data/oracle/app/oracle/oradata/TESTDB/sysaux.dbf
500
UNDOTBS
***
/data/oracle/app/oracle/oradata/TESTDB/undo.dbf
1024
TEST
***
/data/oracle/app/oracle/oradata/TESTDB/test1_tmp.dbf
10
TEST_CORRUPT
***
/data/oracle/app/oracle/oradata/TESTDB/test_corrupt.dbf
1000
TEMP
1000
/data/oracle/app/oracle/oradata/TESTDB/temp1.dbf
data:text/html;charset=utf-8,%3Ch3%20class%3D%22post-title%20entry-title%22%20itemprop%3D%22name%22%20style%3D%22margin%3A%200px%3B
8/10
06/01/2015
Amit Oracle DBA Blog: Manually corrupting the data block in Linux and recovering it using BLOCKRECOVER command of RMAN
RMAN>
Recovery Manager complete.
Connected.
SQL> select * from emp order by eno;
ENO
1
2
3
9997
9998
9999
10000
10000 rows selected.
data:text/html;charset=utf-8,%3Ch3%20class%3D%22post-title%20entry-title%22%20itemprop%3D%22name%22%20style%3D%22margin%3A%200px%3B
9/10
06/01/2015
Amit Oracle DBA Blog: Manually corrupting the data block in Linux and recovering it using BLOCKRECOVER command of RMAN
This will executes successfully and the records will be restored back to the table.
data:text/html;charset=utf-8,%3Ch3%20class%3D%22post-title%20entry-title%22%20itemprop%3D%22name%22%20style%3D%22margin%3A%200px%3B
10/10