Tuesday, November 20, 2012

Oracle's RMAN Validation for Identifying corruption


Follow the below steps to identify corruption as well as corrupted objects in database.

Step 1: Identify the corrupt blocks:

RMAN> connect
RMAN> backup validate check logical database;

or

1-- RMAN> configure device type disk parallelism 4;  
    RMAN> backup validate check logical database;    
--------------------------------------------------------------------------------

The corrupted blocks are listed in the view v$database_block_corruption:

2-- SQL> select * from v$database_block_corruption;
--------------------------------------------------------------------------------

Step 2 : Identify the corrupt segments:

1-- drop table corrupted_objects;
------------------------------------------------------------------------------

2--
create table corrupted_objects
as
select owner, segment_name, partition_name, segment_type, 1 file#, 1 block#
from dba_extents
where 1=2;
------------------------------------------------------------------------------

3--
declare
cursor C1 is select file#, block#, blocks
from v$database_block_corruption;
begin
for r1 in C1 loop
  for r2 in 1..r1.blocks loop
   insert into corrupted_objects
   select owner, segment_name, partition_name,segment_type, r1.file#, r1.block#+r2-1
     from dba_extents
    where file_id=r1.file#
      and (r1.block#+r2-1) between block_id and block_id + blocks - 1;
   if sql%notfound then
   /* segment header block might be corrupt causing dba_extents not returning rows. */
    insert into corrupted_objects
     select owner, segment_name, partition_name, segment_type, r1.file#, r1.block#
       from dba_segments
      where header_file=r1.file# and header_block = (r1.block#+r2-1);
   end if;
   commit;
  end loop;
 end loop;
end;
/
----------------------------------------------------------------------------------

4-- Select all the objects populated in the table corrupted_objects:

SQL> select distinct owner, segment_name, partition_name, segment_type from corrupted_objects;

No comments:

Post a Comment