Top Banner
7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption
25

7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

Dec 25, 2015

Download

Documents

Leona Simmons
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

7Copyright © 2006, Oracle. All rights reserved.

Dealing with Database Corruption

Page 2: 7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

7-2 Copyright © 2006, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to:

• Identify the causes of database corruption:– Hardware– Software

• Detect database corruption by using:– ANALYZE– DBVERIFY– DB_BLOCK_CHECKING– DBMS_REPAIR

• Repair corruptions by using RMAN

Page 3: 7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

7-3 Copyright © 2006, Oracle. All rights reserved.

What Is Block Corruption?

• Whenever a block is read or written, a consistency check is performed.– Block version– DBA (data block address) value in cache as

compared to the DBA value in the block buffer– Block-checksum, if enabled

• A corrupt block is identified as being one of the following:– Media corrupt– Logically (or software) corrupt

Page 4: 7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

7-4 Copyright © 2006, Oracle. All rights reserved.

Block Corruption Symptoms: ORA-01578

The error ORA-01578: "ORACLE data block corrupted (file # %s, block # %s)":

• Is generated when a corrupted data block is found

• Always returns the absolute file number and block number

• Is returned to the session that issued the query being performed when the corruption was discovered

• Appears in the alert.log file

Page 5: 7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

7-5 Copyright © 2006, Oracle. All rights reserved.

How to Handle Corruption

• Check the alert log and operating system log file.

• Use available diagnostic tools to find out the type of corruption.

• Determine whether the error persists by running checks multiple times.

• Recover data from the corrupted object if necessary.

Page 6: 7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

7-6 Copyright © 2006, Oracle. All rights reserved.

How to Handle Corruption

• Resolve any hardware issues:– Memory boards– Disk controllers– Disks

• Recover or restore data from the corrupt object if necessary.

Page 7: 7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

7-7 Copyright © 2006, Oracle. All rights reserved.

Corruption-Related Features

Feature CorruptionDetected

RepairsCorruption

DBVERIFY Physical FALSE

ANALYZE Logical FALSE

DB_BLOCK_CHECKING Logical FALSE

DB_BLOCK_CHECKSUM Physical FALSE

exp Physical FALSE

Flashback Logical TRUE

DBMS_REPAIR Logical TRUE

Block media recovery None TRUE

Page 8: 7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

7-8 Copyright © 2006, Oracle. All rights reserved.

DBVERIFY Utility

• Works only on data files; redo log files cannot be checked

• Checks block consistency

• Can be used while the database is open

• Name of the utility program: dbv

$ dbv file=/u01/oradata/users01.dbf \ blocksize=8192

Page 9: 7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

7-9 Copyright © 2006, Oracle. All rights reserved.

Interpreting DBVERIFY Output

• A “page” is a block.

• If the head and tail do not match, DBVERIFY rereads the block. If they match, an influx block is reported; otherwise, a corruption is signaled.

Total Pages Examined : 12800Total Pages Processed (Data) : 4408Total Pages Failing (Data) : 0Total Pages Processed (Index): 1264 . . .Total Pages Marked Corrupt : 4Total Pages Influx : 0Highest block SCN : 654836 (0.654836)

Page 10: 7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

7-11 Copyright © 2006, Oracle. All rights reserved.

ANALYZE Command

• Performs a logical block check

• Does not mark blocks as soft corrupt; only reports them

• Validates index and table entries

SQL> ANALYZE TABLE table_name VALIDATE 2 STRUCTURE CASCADE;

SQL> ANALYZE INDEX index_name VALIDATE 2 STRUCTURE;

Page 11: 7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

7-12 Copyright © 2006, Oracle. All rights reserved.

Verifying Block Integrity in Real Time: DB_BLOCK_CHECKING

The DB_BLOCK_CHECKING initialization parameter:

• Controls the degree of self-consistency checks performed on each block as it is processed

• Can prevent memory and data corruption

• Can be set by using the ALTER SESSION or ALTER SYSTEM DEFERRED command

Page 12: 7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

7-13 Copyright © 2006, Oracle. All rights reserved.

Verifying Block Integrity in Real Time: DB_BLOCK_CHECKSUM

The DB_BLOCK_CHECKSUM initialization parameter:

• Determines whether a checksum is maintained and verified on each block

• Can prevent corruption caused by underlying I/O systems

a14f

Page 13: 7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

7-14 Copyright © 2006, Oracle. All rights reserved.

Using EXP to Detect Corruption

Conventional export can be used to detect corruption.

$ exp hr/hr tables=departments About to export specified tables via Conventional Path .... . exporting table DEPARTMENTSEXP-00056: ORACLE error 1578 encounteredORA-01578: ORACLE data block corrupted (file # 5, block # 51)ORA-01110: data file 5: '/u01/app/oracle/oradata/orcl/example01.dbf'

Page 14: 7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

7-15 Copyright © 2006, Oracle. All rights reserved.

Using Flashback for Logical Corruption

DBA

USER

Undo SQL or

Flashback Table

Corruptdata found

Flashback Versions

Query

Flashback Transaction

Query

Page 15: 7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

7-16 Copyright © 2006, Oracle. All rights reserved.

DBMS_REPAIR Package

Available procedures

• CHECK_OBJECT• FIX_CORRUPT_BLOCKS• DUMP_ORPHAN_KEYS• REBUILD_FREELISTS• SEGMENT_FIX_STATUS• SKIP_CORRUPT_BLOCKS • ADMIN_TABLES

Page 16: 7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

7-17 Copyright © 2006, Oracle. All rights reserved.

Using DBMS_REPAIR

1. Detect and report corruptions.

2. Evaluate the costs and benefits of DBMS_REPAIR.

SET SERVEROUTPUT ONDECLARE num_corrupt INT;BEGIN num_corrupt := 0; DBMS_REPAIR.CHECK_OBJECT ( schema_name => ‘HR', object_name => 'DEPARTMENTS', repair_table_name => 'REPAIR_TABLE', corrupt_count => num_corrupt);END;

Page 17: 7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

7-19 Copyright © 2006, Oracle. All rights reserved.

Using DBMS_REPAIR

3. Make objects usable.

SET SERVEROUTPUT ONDECLARE num_fix INT;BEGIN num_fix := 0; DBMS_REPAIR.FIX_CORRUPT_BLOCKS ( schema_name => 'HR', object_name => 'DEPARTMENTS', object_type => DBMS_REPAIR.TABLE_OBJECT, repair_table_name => 'REPAIR_TABLE', fix_count => num_fix);END;

Page 18: 7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

7-20 Copyright © 2006, Oracle. All rights reserved.

Using DBMS_REPAIR

4. Repair corruptions and rebuild lost data.

SET SERVEROUTPUT ONDECLARE num_orphans INT;BEGIN num_orphans := 0; DBMS_REPAIR.DUMP_ORPHAN_KEYS ( schema_name => 'SCOTT', object_name => 'PK_DEPT', object_type => DBMS_REPAIR.INDEX_OBJECT, repair_table_name => 'REPAIR_TABLE', orphan_table_name => 'ORPHAN_KEY_TABLE', key_count => num_orphans); DBMS_OUTPUT.PUT_LINE('orphan key count: ' || TO_CHAR(num_orphans));END;

Page 19: 7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

7-21 Copyright © 2006, Oracle. All rights reserved.

Block Media Recovery (BMR)

Block media recovery:

• Lowers the mean time to recover (MTTR)

• Increases availability during media recovery– The data file remains online during recovery.– Only blocks being recovered are inaccessible.

• Is invoked through RMAN via the BLOCKRECOVER command.– Restores individual blocks from available backups– Coordinates with the server to have them recovered

Page 20: 7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

7-22 Copyright © 2006, Oracle. All rights reserved.

BLOCKRECOVER Command

The RMAN BLOCKRECOVER command:

• Identifies the backups containing the blocks to recover

• Reads the backups and accumulates requested blocks into in-memory buffers

• Manages the block media recovery session by reading the archive logs from backup if necessary

• Cannot be used for incomplete recovery

RMAN> BLOCKRECOVER DATAFILE 6 BLOCK 3;

Page 21: 7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

7-23 Copyright © 2006, Oracle. All rights reserved.

Examples of Using BLOCKRECOVER

• Recovering a group of corrupt blocks

• Limiting block media recovery by type of restore

• Limiting block media recovery by backup tag

• Limiting block media recovery by time, SCN, or log sequence

Page 22: 7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

7-25 Copyright © 2006, Oracle. All rights reserved.

The RMAN BMR Interface

Dynamic views show the current state of corruption.

• The V$DATABASE_BLOCK_CORRUPTION view shows the list of currently corrupted database blocks.

• The V$BACKUP_CORRUPTION view shows the list of corrupted blocks in data file backups.

• The V$COPY_CORRUPTION view shows the list of corrupted blocks in image file copies.

RMAN> BLOCKRECOVER CORRUPTION LIST 2> RESTORE UNTIL TIME 'sysdate – 10';

Page 23: 7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

7-26 Copyright © 2006, Oracle. All rights reserved.

Alternative Actions to Take

• Table: The data in the corrupted block is lost.– Drop the table and re-create it, and import data from

an export dump.– Use SQL or PL/SQL to pull data out of the table into

a newly created table.

• Index: Drop and re-create the index.

Page 24: 7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

7-27 Copyright © 2006, Oracle. All rights reserved.

Summary

In this lesson, you should have learned how to:

• Identify the causes of database corruption:– Hardware– Software

• Detect database corruption by using:– ANALYZE– dbverify– DB_BLOCK_CHECKING– DBMS_REPAIR

• Repair corruptions by using RMAN

Page 25: 7 Copyright © 2006, Oracle. All rights reserved. Dealing with Database Corruption.

7-28 Copyright © 2006, Oracle. All rights reserved.

Practice Overview:Perform Block Media Recovery

This practice covers the following topics:

• Discovering corruption

• Identifying the location of the corruption

• Recovering from the corruption by using block media recovery