Вы находитесь на странице: 1из 28

Dealing with Database Corruption

Copyright 2008, Oracle. All rights reserved.

Objectives
After completing this lesson, you should be able to: Identify the causes of database corruption:
Hardware oftware

Detect database corruption by using:


ANALYZE DBVERIFY DB_BLOCK_CHECKING DBMS_REPAIR

!epair corruptions by using !"A#

7-2

Copyright 2008, Oracle. All rights reserved.

$hat Is %loc& Corruption'


$henever a bloc& is read or written, a consistency chec& is performed(
%loc& version D%A )data bloc& address* value in cache as compared to the D%A value in the bloc& buffer %loc&+chec&sum, if enabled

A corrupt bloc& is identified as being one of the following:


"edia corrupt ,ogically )or software* corrupt

7-3

Copyright 2008, Oracle. All rights reserved.

%loc& Corruption ymptoms: O!A+-./01


2he error ORA-01578: "ORACLE d ! "#$%& %$''()!*d +,-#* . /01 "#$%& . /02": Is generated when a corrupted data bloc& is found Always returns the relative file number and bloc& number Is returned to the session that issued the 3uery being performed when the corruption was discovered Appears in the #*'!3#$4 file

7-4

Copyright 2008, Oracle. All rights reserved.

How to Handle Corruption


Chec& the alert log and operating system log file( 4se available diagnostic tools to find out the type of corruption( Determine whether the error persists by running chec&s multiple times( !ecover data from the corrupted object if necessary(

7-

Copyright 2008, Oracle. All rights reserved.

How to Handle Corruption


!esolve any hardware issues:
"emory boards Dis& controllers Dis&s

!ecover or restore data from the corrupt object if necessary(

7-!

Copyright 2008, Oracle. All rights reserved.

Corruption+!elated 5eatures

"eat#re %'()&*"+ ANALYZE DB_BLOCK_CHECKING DB_BLOCK_CHECKSUM exp "lash/ac0 DBMS_REPAIR 'loc0 3edia recovery

Corr#ptio$ %etected ,hysical -ogical -ogical ,hysical ,hysical -ogical -ogical 4o$e

&epairs Corr#ptio$ "A-.) "A-.) "A-.) "A-.) "A-.) 1&2) 1&2) 1&2)

7-7

Copyright 2008, Oracle. All rights reserved.

D%67!I58 4tility
$or&s only on data files9 redo log files cannot be chec&ed Chec&s bloc& consistency Can be used while the database is open #ame of the utility program: d"5

6 d"5 ,-#*78(018$' d ! 8(0*'0013d", 9 "#$%&0-:*781;<

7-8

Copyright 2008, Oracle. All rights reserved.

Interpreting D%67!I58 Output


A :page; is a bloc&( If the head and tail do not match, D%67!I58 rereads the bloc&( If they match, an influ< bloc& is reported9 otherwise, a corruption is signaled(
4*0 4*0 4*0 4*0 E> ?-@*d : P'$%*00*d +D ! 2 : F -#-@4 +D ! 2 : P'$%*00*d +I@d*>2: 1<800 AA08 0 1<BA

=$! # P =$! # P =$! # P =$! # P 3 3 3 =$! # P =$! # P H-4C*0!


7-5

4*0 M '&*d C$''()! 4*0 I@,#(> "#$%& SCN

: A : 0 : B5A8DB +03B5A8DB2

Copyright 2008, Oracle. All rights reserved.

4otes O$ly .lide

7 - 60

Copyright 2008, Oracle. All rights reserved.

ANALYZE Command
=erforms a logical bloc& chec& Does not mar& bloc&s as soft corrupt9 only reports them 6alidates inde< and table entries

SELF ANALYZE =ABLE table_name VALIDA=E < S=RGC=GRE CASCADEH SELF ANALYZE INDEI index_name VALIDA=E < S=RGC=GREH

7 - 66

Copyright 2008, Oracle. All rights reserved.

6erifying %loc& Integrity in !eal 2ime: DB_BLOCK_CHECKING


2he DB_BLOCK_CHECKING initiali>ation parameter: Controls the degree of self+consistency chec&s performed on each bloc& as it is processed Can prevent memory and data corruption Can be set by using the AL=ER SESSION or AL=ER SYS=EM command

7 - 62

Copyright 2008, Oracle. All rights reserved.

6erifying %loc& Integrity in !eal 2ime: DB_BLOCK_CHECKSGM


2he DB_BLOCK_CHECKSGM initiali>ation parameter: Determines whether a chec&sum is maintained and verified on each bloc& Can prevent corruption caused by underlying I?O systems

1A,

7 - 63

Copyright 2008, Oracle. All rights reserved.

4sing EIP to Detect Corruption


Conventional e<port can be used to detect corruption(
6 *>) C'8C' ! "#*07d*) '!?*@!0 A"$(! !$ *>)$'! 0)*%-,-*d ! "#*0 5- C$@5*@!-$@ # P !C 333 3 3 *>)$'!-@4 ! "#* DEPAR=MEN=S EIP-0005B: ORACLE *''$' 1578 *@%$(@!*'*d ORA-01578: ORACLE d ! "#$%& %$''()!*d +,-#* . 51 "#$%& . 512 ORA-01110: d ! ,-#* 5: J8(018 ))8$' %#*8$' d ! 8$'%#8*> ?)#*013d",J

7 - 64

Copyright 2008, Oracle. All rights reserved.

4sing 5lashbac& for ,ogical Corruption


5lashbac& 6ersions @uery

D%A

5lashbac& 2ransaction @uery

Corrupt data found

4 7!

4ndo @, or 5lashbac& 2able

7-6

Copyright 2008, Oracle. All rights reserved.

DBMS_REPAIR =ac&age
Available procedures CHECK_OBKEC= FII_CORRGP=_BLOCKS DGMP_ORPHAN_KEYS REBGILD_FREELIS=S SEGMEN=_FII_S=A=GS SKIP_CORRGP=_BLOCKS ADMIN_=ABLES

7 - 6!

Copyright 2008, Oracle. All rights reserved.

4sing DBMS_REPAIR
.( Detect and report corruptions(
SE= SERVEROG=PG= ON DECLARE @(?_%$''()! IN=H BEGIN @(?_%$''()! :7 0H DBMS_REPAIR3CHECK_OBKEC= + 0%C*? _@ ?* 7F LHRJ1 $"M*%!_@ ?* 7F JDEPAR=MEN=SJ1 '*) -'_! "#*_@ ?* 7F JREPAIR_=ABLEJ1 %$''()!_%$(@! 7F @(?_%$''()!2H ENDH

A( 7valuate the costs and benefits of DBMS_REPAIR3

7 - 67

Copyright 2008, Oracle. All rights reserved.

4otes O$ly .lide

7 - 68

Copyright 2008, Oracle. All rights reserved.

4sing DBMS_REPAIR
B( "a&e objects usable(
SE= SERVEROG=PG= ON DECLARE @(?_,-> IN=H BEGIN @(?_,-> :7 0H DBMS_REPAIR3FII_CORRGP=_BLOCKS + 0%C*? _@ ?* 7F JHRJ1 $"M*%!_@ ?* 7F JDEPAR=MEN=SJ1 $"M*%!_!N)* 7F DBMS_REPAIR3=ABLE_OBKEC=1 '*) -'_! "#*_@ ?* 7F JREPAIR_=ABLEJ1 ,->_%$(@! 7F @(?_,->2H ENDH

7 - 65

Copyright 2008, Oracle. All rights reserved.

4sing DBMS_REPAIR
C( !epair corruptions and rebuild lost data(
SE= SERVEROG=PG= ON DECLARE @(?_$')C @0 IN=H BEGIN @(?_$')C @0 :7 0H DBMS_REPAIR3DGMP_ORPHAN_KEYS + 0%C*? _@ ?* 7F JSCO==J1 $"M*%!_@ ?* 7F JPK_DEP=J1 $"M*%!_!N)* 7F DBMS_REPAIR3INDEI_OBKEC=1 '*) -'_! "#*_@ ?* 7F JREPAIR_=ABLEJ1 $')C @_! "#*_@ ?* 7F JORPHAN_KEY_=ABLEJ1 &*N_%$(@! 7F @(?_$')C @02H DBMS_OG=PG=3PG=_LINE+J$')C @ &*N %$(@!: J OO =O_CHAR+@(?_$')C @022H ENDH
7 - 20 Copyright 2008, Oracle. All rights reserved.

%loc& "edia !ecovery )%"!*


%loc& media recovery: ,owers the mean time to recover )"22!* Increases availability during media recovery
2he data file remains online during recovery( Only bloc&s being recovered are inaccessible(

Is invo&ed through !"A# via the BLOCKRECOVER command(


!estores individual bloc&s from available bac&ups Coordinates with the server to have them recovered

7 - 26

Copyright 2008, Oracle. All rights reserved.

BLOCKRECOVER Command
2he !"A# BLOCKRECOVER command: Identifies the bac&ups containing the bloc&s to recover !eads the bac&ups and accumulates re3uested bloc&s into in+memory buffers "anages the bloc& media recovery session by reading the archive logs from bac&up if necessary Cannot be used for incomplete recovery
RMANF BLOCKRECOVER DA=AFILE B BLOCK DH

7 - 22

Copyright 2008, Oracle. All rights reserved.

7<amples of 4sing BLOCKRECOVER


!ecovering a group of corrupt bloc&s ,imiting bloc& media recovery by type of restore ,imiting bloc& media recovery by bac&up tag ,imiting bloc& media recovery by time, C#, or log se3uence

7 - 23

Copyright 2008, Oracle. All rights reserved.

4otes O$ly .lide

7 - 24

Copyright 2008, Oracle. All rights reserved.

2he !"A# %"! Interface


Dynamic views show the current state of corruption( 2he V6DA=ABASE_BLOCK_CORRGP=ION view shows the list of currently corrupted database bloc&s(
RMANF BLOCKRECOVER CORRGP=ION LIS= <F RES=ORE GN=IL =IME J0N0d !* P 10JH

2he V6BACKGP_CORRGP=ION view shows the list of corrupted bloc&s in data file bac&ups( 2he V6COPY_CORRGP=ION view shows the list of corrupted bloc&s in image file copies(

7-2

Copyright 2008, Oracle. All rights reserved.

Alternative Actions to 2a&e


2able: 2he data in the corrupted bloc& is lost(
Drop the table and re+create it, and import data from an e<port dump( 4se @, or =,? @, to pull data out of the table into a newly created table(

Inde<: Drop and re+create the inde<(

7 - 2!

Copyright 2008, Oracle. All rights reserved.

ummary
In this lesson, you should have learned how to: Identify the causes of database corruption:
Hardware oftware

Detect database corruption by using:


ANALYZE d"5*'-,N DB_BLOCK_CHECKING DBMS_REPAIR

!epair corruptions by using !"A#

7 - 27

Copyright 2008, Oracle. All rights reserved.

=ractice Overview: =erform %loc& "edia !ecovery


2his practice covers the following topics: Discovering corruption Identifying the location of the corruption !ecovering from the corruption by using bloc& media recovery

7 - 28

Copyright 2008, Oracle. All rights reserved.

Вам также может понравиться