~ 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.
~ 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.
I know you feel more happy when you get things done and best of all those things are your most precious treasure.
ReplyDeleteangularjs-Training in velachery
angularjs-Training in annanagar
angularjs Training in chennai
angularjs Training in chennai
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.
ReplyDeletePython training in marathahalli | Python training institute in pune
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.
ReplyDeleteJava training in Marathahalli | Java training in Btm layout
Java training in Marathahalli | Java training in Btm layout
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!
ReplyDeleteData Science Training in Indira nagar
Data Science training in marathahalli
Data Science Interview questions and answers
Nice post
ReplyDeletejava training in Marathahalli
spring training in Marathahalli
java training institute in Marathahalli
spring and hibernate training in Marathahalli
Nice post..
ReplyDeleteDOT NET training in btm
dot net training institute in btm
dot net course in btm
best dot net training institute in btm
Thanks a lot for sharing us about this update. Hope you will not get tired on making posts as informative as this.
ReplyDeletedevops online training
aws online training
data science with python online training
data science online training
rpa online training
Nice Post! Thank you for sharing knowledge, it was very good post to update my knowledge and improve my skills. keep blogging.
ReplyDeleteJava Training in Electronic City
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..
ReplyDeleteIf you are looking for any Big data Hadoop Related information please visit our website hadoop classes in pune page!
This comment has been removed by a blog administrator.
ReplyDeleteIts 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.
ReplyDeleteSuch a very wonderful post..
ReplyDeleteThanks for sharing with us,
We are again come on your website,
Thanks and good day,
Please visit our site,
buylogo
This comment has been removed by a blog administrator.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteGreat Blog.. Thanks a lot
ReplyDeletecloud hosting in chennai
This comment has been removed by a blog administrator.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDelete