Oct 23, 2013

Find & repair Corrupt block in Oracle database

~ Find & repair Corrupt block in Oracle
~ Applies to any Oracle version
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- Find if any block (Table) is corrupted.

SQL> select * from V$DATABASE_BLOCK_CORRUPTION -- will show if any corruped block

Below query can give you information about corrupted block:

set head on; 
set pagesize 2000 
set linesize 250 
select * from v$database_block_corruption;
SELECT e.owner, e.segment_type, e.segment_name, e.partition_name, c.file# 
, greatest(e.block_id, c.block#) corr_start_block# 
, least(e.block_id+e.blocks-1, c.block#+c.blocks-1) corr_end_block# 
, least(e.block_id+e.blocks-1, c.block#+c.blocks-1) 
- greatest(e.block_id, c.block#) + 1 blocks_corrupted 
, null description 
FROM dba_extents e, v$database_block_corruption c 
WHERE e.file_id = c.file# 
AND e.block_id <= c.block# + c.blocks - 1 
AND e.block_id + e.blocks - 1 >= c.block# 
UNION 
SELECT s.owner, s.segment_type, s.segment_name, s.partition_name, c.file# 
, header_block corr_start_block# 
, header_block corr_end_block# 
, 1 blocks_corrupted 
, 'Segment Header' description 
FROM dba_segments s, v$database_block_corruption c 
WHERE s.header_file = c.file# 
AND s.header_block between c.block# and c.block# + c.blocks - 1 
UNION 
SELECT null owner, null segment_type, null segment_name, null partition_name, c.file# 
, greatest(f.block_id, c.block#) corr_start_block# 
, least(f.block_id+f.blocks-1, c.block#+c.blocks-1) corr_end_block# 
, least(f.block_id+f.blocks-1, c.block#+c.blocks-1) 
- greatest(f.block_id, c.block#) + 1 blocks_corrupted 
, 'Free Block' description 
FROM dba_free_space f, v$database_block_corruption c 
WHERE f.file_id = c.file# 
AND f.block_id <= c.block# + c.blocks - 1 
AND f.block_id + f.blocks - 1 >= c.block# 
order by file#, corr_start_block#; 


1) Collect file ids
sql> select distinct file_id from dba_extents;
2) Collect details
sql>
SELECT file_id,segment_name,segment_type,owner,tablespace_name,block_id,blocks
FROM   sys.dba_extents
WHERE  (file_id between 1 and 23) AND 658438 BETWEEN block_id AND block_id + blocks - 1;
3) Repair - If Table

a) Collect all data to temporary table and collect all DDL script and grants.
b) drop the table and re-create it with DDL script. (Disable refence key before drop, enable after create table)
c) Insert all records to the table

Note: This entire activity should not be taken in prod databases without Oracle support's recommendation.

Click here to get my work-around which is posted to this blog.

Hope this will help to resolve block corruption issue.

19 comments:

  1. Thank you for an additional great post. Exactly where else could anybody get that kind of facts in this kind of a ideal way of writing? I have a presentation next week, and I’m around the appear for this kind of data.
    Python training in marathahalli | Python training institute in pune

    ReplyDelete
  2. The site was so nice, I found out about a lot of great things. I like the way you make your blog posts. Keep up the good work and may you gain success in the long run.
    Java training in Marathahalli | Java training in Btm layout

    Java training in Marathahalli | Java training in Btm layout

    ReplyDelete
  3. Well done! Pleasant post! This truly helps me to discover the solutions for my inquiry. Trusting, that you will keep posting articles having heaps of valuable data. You're the best! 
    Data Science Training in Indira nagar
    Data Science training in marathahalli
    Data Science Interview questions and answers

    ReplyDelete
  4. Thanks a lot for sharing us about this update. Hope you will not get tired on making posts as informative as this. 

    devops online training

    aws online training

    data science with python online training

    data science online training

    rpa online training

    ReplyDelete
  5. Nice Post! Thank you for sharing knowledge, it was very good post to update my knowledge and improve my skills. keep blogging.
    Java Training in Electronic City

    ReplyDelete
  6. Your info is really amazing with impressive content..Excellent blog with informative concept. Really I feel happy to see this useful blog, Thanks for sharing such a nice blog..
    If you are looking for any Big data Hadoop Related information please visit our website hadoop classes in pune page!

    ReplyDelete
  7. This comment has been removed by a blog administrator.

    ReplyDelete
  8. Its great post.Very easy to understand,got lot of information.Thanks for posting,keep updating.IT managers suggest to take Hadoop Admin Training in Bangalore because its best suited for them who have basic linux experience.

    ReplyDelete
  9. Such a very wonderful post..
    Thanks for sharing with us,
    We are again come on your website,
    Thanks and good day,
    Please visit our site,
    buylogo

    ReplyDelete
  10. This comment has been removed by a blog administrator.

    ReplyDelete
  11. This comment has been removed by a blog administrator.

    ReplyDelete
  12. This comment has been removed by a blog administrator.

    ReplyDelete
  13. This comment has been removed by a blog administrator.

    ReplyDelete
  14. This comment has been removed by a blog administrator.

    ReplyDelete
  15. This comment has been removed by a blog administrator.

    ReplyDelete

Translate >>