How to Find and repair Corrupt block in database

How to Find and repair Corrupt block in database

Step 1: Below query will show if there is any corrupted block

SELECTΒ *Β 
FROMΒ Β Β v$database_block_corruptionΒ β€”Β willΒ showΒ ifΒ anyΒ corrupedΒ blockΒ 

Step 2: Below query can give you Detail 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#;Β 

Step 4: Β Collect file ids

SELECTΒ DISTINCTΒ file_idΒ 
FROMΒ Β Β dba_extents;Β 

Step 5: Collect detailsΒ 

SELECTΒ file_id,Β 
Β Β Β Β Β Β Β segment_name,Β 
Β Β Β Β Β Β Β segment_type,Β 
Β Β Β Β Β Β Β owner,Β 
Β Β Β Β Β Β Β tablespace_name,Β 
Β Β Β Β Β Β Β block_id,Β 
Β Β Β Β Β Β Β blocksΒ 
FROMΒ Β Β sys.dba_extentsΒ 
WHEREΒ Β (Β file_idΒ BETWEENΒ 2Β ANDΒ 19Β )Β 
Β Β Β Β Β Β Β ANDΒ 468598Β BETWEENΒ block_idΒ ANDΒ block_idΒ +Β blocks – 1;

Step 6:Β  RepairΒ 

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.

About Syed Saad

With 16 years of experience as a certified and skilled Oracle Database Administrator, I possess the expertise to handle various levels of database maintenance tasks and proficiently perform Oracle updates. Throughout my career, I have honed my analytical abilities, enabling me to swiftly diagnose and resolve issues as they arise. I excel in planning and executing special projects within time-sensitive environments, showcasing exceptional organizational and time management skills. My extensive knowledge encompasses directing, coordinating, and exercising authoritative control over all aspects of planning, organization, and successful project completions. Additionally, I have a strong aptitude for resolving customer relations matters by prioritizing understanding and effective communication. I am adept at interacting with customers, vendors, and management, ensuring seamless communication and fostering positive relationships.

Check Also

AWR Snapshot Retention Period

AWR Snapshot Retention Period Configuration Β  This article explores the process of modifying the AWR …

Leave a Reply