Oracle corrupt block(坏块) 详解

上一篇 / 下一篇  2011-08-18 12:55:43 / 个人分类:Oracle 调优

一. 坏块说明

1.1 相关链接

2FEc D3Llpr0 在看坏块之前,先看几个相关的链接,在后面的说明中,会用到链接中的一些内容。

XM~_4F~s3r A0

Z$?{S-QxF/eL0

:b O+J%c'CJ7f |'D0CNOUG博客首页 Ju,M ?C

ORA-600 各个参数含义说明

J(E ]ScT,R0

Y p'{g1C^Uw0http://blog.csdn.net/tianlesoftware/article/details/6645809

5^&B6e Kz4G/q0

h)~0Le+S?I0

G?(H*u J0

vu.N k_$GV@k#Vj1V0Oracle 不同故障的恢复方案CNOUG博客首页\ {&NIy w9uiWf

&A E3S o7J0http://blog.csdn.net/tianlesoftware/article/details/6106178CNOUG博客首页uP4J~ hk.V

fcV:ZT$_ c2b:QC0

m H?XWe0CNOUG博客首页Dwx E bSs

Current online Redo 和 Undo 损坏的处理方法

3[`@${ {? _0CNOUG博客首页s9T+z#u:M5T(s4h

http://blog.csdn.net/tianlesoftware/article/details/6261475CNOUG博客首页:]1w9m n@[

2[9dFs$|(fRm0 CNOUG博客首页e*g G+B,rZ!poKG

Dz+|X*f,HwK0Oracle DBV 工具 说明

-F2S1h I*OB3a0

:p0|3c S&D7hh C#H9Jm4S0http://blog.csdn.net/tianlesoftware/article/details/5015164CNOUG博客首页;G.OMw/\C

CNOUG博客首页m ? i[(dm

e(\ b y:L-G$B0

4lv_"x-UmjP4V0Oracle BBED 工具 说明

,K-m:V&[O6f's3Av0CNOUG博客首页)q[)wu:| A

http://blog.csdn.net/tianlesoftware/article/details/5006580

:v{q C'}0CNOUG博客首页 UQ A5m;U3B

%Q M]Fy0

d!p-|p2~ dyU0Oracle bbed 五个 实用示例

br2G:?z5yB]9g kr0

c Sa/G4S+_0http://blog.csdn.net/tianlesoftware/article/details/6684505

}$|O.t,d/@t)F%E0

b&dkU&Z5o N{,|-m |0

#h?F3G| ?0

oRoR Z#{d0Oracle datafile block 格式 说明CNOUG博客首页lxEd@W;uQ

`!oJ(\\"s,[0http://blog.csdn.net/tianlesoftware/article/details/6654786

.hZ5IBG%y]:|,{0

|$r#^6{!RM5J0 CNOUG博客首页,H;yC P2y `w

CNOUG博客首页k9CB2G^t U*gP-J}

MOS 上的相关文档:

B3[1v\$P,h F,z0

3~G;W[2G ?}b a9[2C2H0 RMAN: Block-Level Media Recovery - Concept & Example [ID 144911.1]

n8I;e7L9P l1y8B0CNOUG博客首页jOaY'y%|8f5hT

FAQ:Physical Corruption [ID 403747.1]

i)g^uDsXU4M0

9[Y5V%R:]_*dx_0 MasterNote for Handling Oracle Database Corruption Issues [ID 1088018.1]CNOUG博客首页 `i,n3Hp$N9[ jVN+X8G

z5~LeG_4|.O3e4g0 HandlingOracle Block Corruptions in Oracle7/8/8i/9i/10g/11g [ID 28814.1]CNOUG博客首页PfqCTWGN

CNOUG博客首页-^%t4NRF?m Jg)ue

ExtractingData from a Corrupt Table using ROWID Range Scans in Oracle8 and higher [ID61685.1]CNOUG博客首页jw:R,f$^

V#p0i W$[ mvR {0
)Y!Y!ApV|d0

vPB8}U0

sfZrkoz y_0官网的链接:CNOUG博客首页7s9aARz} h5A

hM!k,X I0 ValidatingDatabase Files and Backups

8W6G4A4v(_ ~"LewB0

#y QrM*TV |{$R:c|0 http://download.oracle.com/docs/cd/E11882_01/backup.112/e10642/rcmvalid.htm#CHDCEHFDCNOUG博客首页1p$O4Edy~

CNOUG博客首页2\@4uY{J'_"l

CNOUG博客首页TAN:Zt z[

CNOUG博客首页Q![&@hW

Performing Block Media RecoveryCNOUG博客首页0Irk|S"i6D$En/S

http://download.oracle.com/docs/cd/E11882_01/backup.112/e10642/rcmblock.htm#CHDCBIIBCNOUG博客首页gx0Cu}'}|TP

h+|jG&Th x0 CNOUG博客首页_!wF@S2o$h5v

D0e.v2Q:mX9A,WH0老熊的一篇文章:

VOh~q&mM#M!^0

R,P1_EW&\X4T"u0 Oracle怎样标记坏块及一次数据恢复CNOUG博客首页8F2aif9x*aw!g

CNOUG博客首页M1us{ AV!q

http://www.laoxiong.net/how_to_mark_corruption_block_and_recovery.html

3v2t:b)X2pFy(r0

c*`*H.F5V[0

W.nF@p0

1.2 block corruption 分类

6T!X0d{'j$a*^4fkD&E0For purposes of the paper we will categorize corruption under three general areasand give best practices for prevention, detection and repair for each:

U/W/~(b0c&~sB0CNOUG博客首页C;J }/Wsy6h

Memory corruptionCNOUG博客首页)Uf7gf;x3y m

CNOUG博客首页"K3U2_.A R$S A$t&Q(j

Logical corruption(soft corruption)

Y(\,i Q.|5US*|u^0CNOUG博客首页GiU!s&K(?

Media corruption(Physicalcorruption)

0N6^vnk(^+t0bn h0

i:j+X(UF Cd7[)K0
|%V SZDa`)_&o U0

"e$~K!g6_+F M0CNOUG博客首页)m.Kae"tV s:VSe.v%a

Physicalor structural corruption can be defined as damage to internal data structureswhich do not allow Oracle software to find user data within the database. Logical corruption involves Oracle beingable to find the data, but the data values are incorrect as far as the end useris concerned.CNOUG博客首页D%}*X+v%v'Mi&].y5n

CNOUG博客首页~o7t Rm;k]!X%^X]

Physica lcorruption due to hardware or software can occur in two general places -- inmemory (including various IO buffers and the Oracle buffer cache) or on disk.Operator error such as overwriting a file can also be defined as a physicalcorruption. Logical corruption on theother hand is usually due to end-user error or non-robust(?) applicationdesign. A small physical corruption such as a single bit flip may be mistakenfor a logical error. CNOUG博客首页AKa:N&Xq|#`~

CNOUG博客首页q9^#ledQ


)v!H,Pb,|%y B UM0

rT2DMRj0

1.3 查看blockcorruption

xO t~0P5F~ z0 可以通过v$database_block_corruption 查看database 的corruption。 官网对该视图的定义如下:CNOUG博客首页^3| PsPi:p

gd~mho$~;c e0 V$DATABASE_BLOCK_CORRUPTION displaysinformation about database blocks that were corrupted after the last backup.CNOUG博客首页nXQ.AyC&bC&b

CNOUG博客首页K3p#u y:w(tc

cA,|*cS;U.c0CNOUG博客首页i,z aY(?%z'^I

SYS@dave2(db2)>desc v$database_block_corruption

'Q4jS.PG y%rzW%S0CNOUG博客首页5p3Rj+c'rOX0JO

Name Null? TypeCNOUG博客首页;TFo@ q

CNOUG博客首页BaW)O-oOX4^

------------------------------------------------- ----------------------------

k!G']H2?P vg0CNOUG博客首页(t~tI}fYp[

FILE# NUMBERCNOUG博客首页j*](G8gq} G[

CNOUG博客首页 kjmW&K,O4Dz

BLOCK# NUMBERCNOUG博客首页+uU&g}8q2`_2J

CNOUG博客首页%c_C$T? j*l8lT

BLOCKS NUMBERCNOUG博客首页x2Z }r[HoO

ty} ba#S6b0 CORRUPTION_CHANGE# NUMBER

q1r o6cB A;v+t#m4V5} C0CNOUG博客首页*yl:k\0F_@4n

CORRUPTION_TYPE VARCHAR2(9)

~7FeILp4P1E'J(q0CNOUG博客首页Uwf k!A2l[X

CNOUG博客首页C$a ?k,]E

CNOUG博客首页:_P"?,iU7Lxx(D

SYS@dave2(db2)> select * fromv$database_block_corruption;

G4? C6L-_C'B0

r*^.O~1\`&k0no rows selected

.} r*Oq%rH0

5u$C`J:Vf2tn&S0 CNOUG博客首页 ~6jo JFo_~

CNOUG博客首页3l;dV}w&j{4n

这里没有坏块,为了演示这个效果,我用BBED 制造一个坏块,然后在用bbed 恢复过来。

3eId LsLeA.W6a$K0

6^(qS'l#afM8m0

"W^ M zSX"~ ca0

(Z/BM*s0l0先确定block:CNOUG博客首页~*Yw yb!{;g

&a R r3E[0SYS@dave2(db2)> select * from dvd;

J-nQ8ub-C9xM3dI%QAQ0

JO z@F0

&i,];m0a8xt.DA k0

ccy7\w+t O7h0JOB

*ze}$tW$db%k }0

Ot)D'V3I1^0--------------------------------------------------------------------------------

Z]*?Y8{}JS1zR0CNOUG博客首页R-HCbg(j5T ei1~

DMM is DBA!CNOUG博客首页 A\8N v%T B?K4G

CNOUG博客首页,uQk-W/td0l

dmme like Oracle!

X,hJ+g.m.d0

Cwq+^&dkS+A0 CNOUG博客首页hJt^*@5?P)R e^

CNOUG博客首页"D%v7?/`~H.B]$v S.L

SYS@dave2(db2)>selectCNOUG博客首页pWax&[s L

3X h0Z/pX+j,y3r0 2 rowid,CNOUG博客首页4Bk8I G(\!e \0\$i

} ?(M$Y(bJu0 3 dbms_rowid.rowid_relative_fno(rowid)rel_fno,

x,F7M5H[&? |?0u0CNOUG博客首页;@U*Dny DBP

4 dbms_rowid.rowid_block_number(rowid)blockno,

b\lWR;yUj0CNOUG博客首页h lvRf)zt]

5 dbms_rowid.rowid_row_number(rowid) rownoCNOUG博客首页(Y0x6yI"I6qJ3L[5s

'N:v.l3UG PT5rB|0 6 from dvd;

5W;AJ ke0

R V'S MT8x!_0

qd?U9ao Qb y ow0CNOUG博客首页rBm1qi!V

ROWID REL_FNO BLOCKNO ROWNO

^H.T0E-r vRl8Q/Bd0

e \gVj:J0alNmA0------------------ ---------- --------------------

r!{{ B)GOlc0CNOUG博客首页,t~(Y-S^_ rA6A\

AAAN9hAAGAAAAAcAAA 6 28 0

u.oE'w8|X8tL*o0

$GpDX3^#_I9c4`0AAAN9hAAGAAAAAcAAB 6 28 1CNOUG博客首页 j&^!KWK ^w8nJ%j5T

7Q9V.|7QQ*_ B0

3w4X0F0{4w3wM7c4q0

Ise!ob0用bbed 修改block 28:

P/Y4?ImB}9O0D0CNOUG博客首页,Cz:c%Ov

[oracle@db2 ~]$ bbed parfile=/u01/bbed.par

p7K[G v2I^0CNOUG博客首页8JGO{n

Password:

U f5c*LF9c.r0CNOUG博客首页5C*C'h3hn&euY

0usX{ K4[J0

b4R%bcqW7D(BM&M0BBED: Release 2.0.0.0.0 - LimitedProduction on Mon Aug 15 22:15:10 2011

8zdM0\;|@5r0

8_ x!@ d u2hm4u0Copyright (c) 1982, 2005, Oracle. All rights reserved.

.dV7P,[ @h&B,h0CNOUG博客首页 p _!LJp`6J

*************!!! For Oracle Internal Use only !!! ***************

R/nu'A_w0CNOUG博客首页a/V!TAig

BBED> set dba 6,28

z)u8xuRy&c E p0CNOUG博客首页sl)s+c3d$H

DBA 0x0180001c(25165852 6,28)

KTqaa/@"h r7BZ*m0CNOUG博客首页8V |1Gt$^KoM4L` sE

BBED> map CNOUG博客首页.W7W&tcn `

/l,Qc;L7I#r,n$^0 File: /u01/app/oracle/oradata/dave2/dave01.dbf(6)

(h%dyIR3j.CS k0CNOUG博客首页:_f1ZK Q.d[(w

Block: 28 Dba:0x0180001cCNOUG博客首页j/c"^[P8C

'in?;p ~!Z7j j Q0------------------------------------------------------------CNOUG博客首页|(Bs\Lyx2x6Kxf

8FA8P8e|/M0 KTBData Block (Table/Cluster)

;\5_"kgHKv/j i0CNOUG博客首页I y1oS Q+e

struct kcbh, 20 bytes @0

Sp9ReD(y;[;A/p9j0

1lSWJRN.`!z8L0 struct ktbbh, 96 bytes @20

ff D(`n'z1A0

a`t,G5FQ"vvV]S.U0 struct kdbh, 14 bytes @124

zX c+r7b0CNOUG博客首页 q8x!Z.\q+tv A:K U

struct kdbt[1], 4 bytes @138

)q.w(c(y"L(I0

.b2{&KpOn'F\ iS0 sb2kdbr[2] @142

~ ed/`l.BlP0CNOUG博客首页1^ G3^+\ a,E/s k?

ub1freespace[8005] @146

;R][-~,HFH X#j0]0

d daO8[Rs*BH0 ub1rowdata[37] @8151 CNOUG博客首页M'H9LPPY M`h

lL\,F IQ~0 ub4tailchk @8188 CNOUG博客首页7}2|k,^[uXB

CNOUG博客首页'Me'ty9]

CNOUG博客首页7^ ~)S;E1m f/Z!c"X

CNOUG博客首页c8{D2n dO5V

BBED> d /voffset 0 count 128

X)cIu-i$fV1y~'Q0CNOUG博客首页V3Nj [vQi

File: /u01/app/oracle/oradata/dave2/dave01.dbf(6)

hs9p9?:q,f_/d0CNOUG博客首页H#Zh{p#~l5N

Block: 28 Offsets: 0 to 127 Dba:0x0180001cCNOUG博客首页 u_4C e9h6vQ\!l

CNOUG博客首页8@io6`5EK*[

-------------------------------------------------------

g|5N Wn|~0

4S*EyDJ3Y~ F0 06a20000 1c008001 f4a90780 00000104 l.¢......ô©......CNOUG博客首页D.@;Jr6M2C4QR

CNOUG博客首页3]:^$MmHS

f5b40000 01000000 61df0000 f4a90780 lõ´......aß..ô©..CNOUG博客首页2|%t0X h%X$hL2q

CNOUG博客首页/B?Z-TvWB ?:z_

00000000 03003200 19008001 03001000 l......2.........

v~ h"R:UI0

VV-n`*pHx0 3b0a0000 00000000 00000000 00800000 l;...............

X&r\J3K|2c5B0

.r8u A(M|'p5m0 dda90780 00000000 00000000 00000000 lݩ..............

`;eS:]gP6u6~0CNOUG博客首页?&d4qB+Hh|#r

00000000 00000000 00000000 00000000 l................CNOUG博客首页&V#x8eA|:w ~.C/u(f

3oB1Hr];Js)cu0 0000000000000000 00000000 00000000 l ................

tdO?!Y @0CNOUG博客首页V,p%iO(wxs-J(Z

00000000 00000000 00000000 00010200 l................CNOUG博客首页!Dy;C#ZW7q

Be,|?wlp#@0 CNOUG博客首页h p^6xB@u

CNOUG博客首页g]5H@G)sw Z:MY

<16 bytes per line>

s fNs{ U3l9C4N-B0CNOUG博客首页(p5A0f:`}x+`x

w#[C:k dZ;]1PK0

!D6V t:E/Pqts%P0BBED> modify /x 12345678 offset 0CNOUG博客首页D PJ'g$N6G8P

CNOUG博客首页$P#t[6Y J j

File: /u01/app/oracle/oradata/dave2/dave01.dbf(6)CNOUG博客首页2r['j2?B%aT5OM7t3k

.f9S2S9r`0 Block: 28 Offsets: 0to 127 Dba:0x0180001cCNOUG博客首页5]-|6Mo-Ik

G1x]~1mq;L)r.^0------------------------------------------------------------------------CNOUG博客首页,f@(_'tI P`+d"vLP

0CY e @;fu0 12345678 1c008001 f4a90780 00000104 f5b4000001000000 61df0000 f4a90780 CNOUG博客首页3N*ko2?z

CNOUG博客首页9mDw So9f[i#`

00000000 03003200 19008001 03001000 3b0a000000000000 00000000 00800000 CNOUG博客首页&| XI1K"W$s

t&PM-{0v9\0 dda90780 00000000 00000000 00000000 0000000000000000 00000000 00000000

%N6~um;HzLi"P0CNOUG博客首页V(@I4ueD P

00000000 00000000 00000000 00000000 0000000000000000 00000000 00010200

9Prh\-B6ex0

L\?$`7gKYc Y1Dl-I|0

2m#y wK$?oW(g,_0CNOUG博客首页#Q)J1L L:~!i

<32 bytes per line>

w/U.TKnW;EQ0

c}2Iq1_#PJ-Cn0 CNOUG博客首页Ke2j1P$L

1O[]Y%v"w5C.?#Eu0BBED> sum applyCNOUG博客首页S&d;M4|%\y0M

CNOUG博客首页'sQ _3F#}G

Check value for File 6, Block 28:CNOUG博客首页s A"f.NQ

CNOUG博客首页(dU#\l`G p'v9m

current = 0x5ab7, required = 0x5ab7

X/aXfj Rkm0

m9k j e'y SVF"^V0 CNOUG博客首页#pc Z {"G#d mm

CNOUG博客首页9~@|%Sl:k

SYS@dave2(db2)>alter system flush buffer_cache;CNOUG博客首页'Nf"?{9qy

~sl} EC _y/tU(}0System altered.

8fK e,y7c3M8t @ I0

X(nL[b)b,o0 CNOUG博客首页&c_2AYu"K6E D#a

\ [dhWS6DdF$bHD0SYS@dave2(db2)> select * from dvd;

6t#g9q`1V0

/j*RWQj ^0select * from dvdCNOUG博客首页j_ |g7~Q1i

CNOUG博客首页;| u&R v'\S ~.}

*CNOUG博客首页:h$}]l6Et(R#N

CNOUG博客首页R;jW)R Yw)xQJ

ERROR at line 1:

u5LmX(v{7?0

qs{3YT;cQW0ORA-01578: ORACLE data block corrupted(file # 6, block # 28)

n:T9K{~i(j"o0CNOUG博客首页+@y(K~-SU

ORA-01110: data file 6:'/u01/app/oracle/oradata/dave2/dave01.dbf'

NCt:} {8?uUIz&U0

nF*L3g8Ie(B0 CNOUG博客首页 x.s7n Ih%V

CNOUG博客首页qVbuz[

这里提示块有错误,我们查看下一下:v$database_block_corruption:CNOUG博客首页4Ciq,HZa#Z)y`

CNOUG博客首页8h,fQKiQ K

CNOUG博客首页+c[m3wt%S:^~[+t#n

CNOUG博客首页,Mr1j Zn"aaL y s

SYS@dave2(db2)> select * fromv$database_block_corruption;

u,zK ?5R+N7P!g s0

W.M*WU1eOK0no rows selected

B'QgM'k/h`rSD e#Dk0CNOUG博客首页 O2]Ep8V^G,S

CNOUG博客首页:Xl9xz G

CNOUG博客首页4C%MoWB$j)BO.D)l

这里显示为空,但是我们之前看该视图的定义的时候,说是自上次备份以来的坏块。所以这里我们验证一下:CNOUG博客首页T/M)OF-|j

CNOUG博客首页Ve:V1e$]{u'o0j

RMAN> backup validate datafile 6;CNOUG博客首页[ A E|\"wV$][V'z,Z

k\3l*N'P"G1BY0 CNOUG博客首页@ R _8s&\j7h

CNOUG博客首页Tp4Sl%?+~

Starting backupat 15-AUG-11CNOUG博客首页?5Uj#ZD8_9X*WO3W

6|KtF'?!xN5b/p7c0using target database control file insteadof recovery catalog

3@nK h jT s0

6kN UK&AN0allocated channel: ORA_DISK_1CNOUG博客首页(xu`dU.JS _

;]~p lGEC$rb0channel ORA_DISK_1: sid=141 devtype=DISKCNOUG博客首页%u-xa(jXP

CNOUG博客首页7m:{"{P{2q

channel ORA_DISK_1: starting full datafilebackupsetCNOUG博客首页k/?*No*S5G8~

QsGN3L*`0channel ORA_DISK_1: specifying datafile(s)in backupsetCNOUG博客首页ba!O/GnB2?

CNOUG博客首页9YX*?] Bf

input datafile fno=00006 name=/u01/app/oracle/oradata/dave2/dave01.dbf

bLMz8t*Q7a0

k:e#ys2K3?"r^0channel ORA_DISK_1: backup set complete,elapsed time: 00:00:02

/Q2_-rd+y*yJ'j0

d)p^D$_ JN7P0Finished backup at 15-AUG-11CNOUG博客首页0y*xr"cy0S Q

CNOUG博客首页)z yA*m9X(s/q

CNOUG博客首页kQ \ Gf\

CNOUG博客首页lM r s,A,}iV Z

在次select 查询:CNOUG博客首页^#a%g3]g{6_1rg/yR a

CNOUG博客首页a)Zs't*AM:z

SYS@dave2(db2)> select * from v$database_block_corruption;CNOUG博客首页+}L)t)r!@YQ

CNOUG博客首页GO.a E1W

6c.j(~4HWqJG0

U{%P|K H1oe1a0FILE# BLOCK# BLOCKSCORRUPTION_CHANGE# CORRUPTIOCNOUG博客首页[+`Qc lZv/M

0sY!@/@ Z'h7c0---------- ---------- ---------------------------- ---------

[4Wd(Z;R_0

D-yE%f+V m6S)v0 6 15 1 0 CORRUPT

RJk5r0N9u&o/s0CNOUG博客首页%UD/E-X'UW

6 28 1 0 CORRUPTCNOUG博客首页'DjFlD FU _/sn`

1?&} u E2w0 CNOUG博客首页;t9HN2r0Unl.V

)X+p;G%_Z ?0这次就查询到结果了。 视图显示block的状态为corrupt。 对于该类型,共有一下几种:

\t$V*k~Sm0

1[a6~E;WCI$U0 (1)ALL ZERO:Block header on disk contained only zeros. The block may be valid ifit was never filled and if it is in an Oracle7 file. The buffer will bereformatted to the Oracle8 standard for an empty block.CNOUG博客首页0u;[V"UH F,b|

CNOUG博客首页D)lW~4N,Vy

(2)FRACTURED: Block header looks reasonable, but the front and back of the blockare different versions.

U J&T{7}2Mm7c*F X!|B0

p$p3_*r?0 (3)CHECKSUM: optional check value shows that the block is not self-consistent.It is impossible to determine exactly why the check value fails, but itprobably fails because sectors in the middle of the block are from differentversions.

j~5x7b.e._~0

8vq&N#Z-_J+_TjR0 (4)CORRUPT: Block is wrongly identified or is not a data block (for example,the data block address is missing)CNOUG博客首页VLg?N!ip2Z)N

2RcV5a5H3Z%yV0 (5)LOGICAL: Specifies the range is for logically corrupt blocks.CORRUPTION_CHANGE# will have a nonzero value.CNOUG博客首页Bdl$y?6z

0J ??*IoM!a}0 CNOUG博客首页G8f9IV-Z7zF$SX#pC

CNOUG博客首页X$O^f1hV

现在用BBED还原block:

[+T Vb ve8TY0

6wj*?$Oad&J&\0BBED> revertCNOUG博客首页y2JF(_9nyh

S7F}h {Nk qO @0All changes made in this session will berolled back. Proceed? (Y/N) yCNOUG博客首页I)Sx$|:O ^/n'aRYk

CNOUG博客首页/]Ej6ls(wA2XN

Reverted file'/u01/app/oracle/oradata/dave2/dave01.dbf', block 28

Um!d8cr9[0

? t}k#c`*Oe0Warning: contents of previous BIFILE willbe lost. Proceed? (Y/N) y

_kz0w#s"m?Ry6l0CNOUG博客首页~F'~2{HHS@O%B C

A9TK~FoB0

G+d$j'C*v0BBED> sum applyCNOUG博客首页Uc J8LL&Ey

Ga+{AVR)a%[0Check value for File 6, Block 28:CNOUG博客首页g3MvIeg0ka |&h

CNOUG博客首页6|5|K,x8vx9N k+j!_

current = 0xb4f5, required = 0xb4f5

G tq;@9P0CNOUG博客首页6~B2T&hYgTL7S

z W'c#q Tx0

/Cz5o Q-`7Je3|.Y7H"w4t0在次查询,block 正常:

,GQW)Rk c/aY0CNOUG博客首页h1l [ a1n_ld*]+kV

SYS@dave2(db2)> alter system flushbuffer_cache;

OHO8ts9g0CNOUG博客首页 b,V*]9M_viQ

System altered.

W U`\:xPG)o%C0

#Y)D|/H*SnO&L@8M0

!?'R]P?Y-L/Ob0CNOUG博客首页p!B"F'E[0z+t@

SYS@dave2(db2)> select * from dvd;

*o8Y w5{l3A6c0CNOUG博客首页;[8k4n2P0i

JOBCNOUG博客首页8Xor"d4F:o l!V#f

4obDy%T3b u0--------------------------------------------------------------------------------

!k7I!~M*dJq+Aj0

5|5T#O i {H"cA]S0DMM is DBA!

%B.zEH!Z8on0Z0

9LE1ybmK0dmme like Oracle!CNOUG博客首页-p*rg~1SX3k

CNOUG博客首页 EU_;^O6~Z-B

A2@~/C,FqT0

LzP$K y,a!s0但是注意我们的v$database_block_corruption 视图:CNOUG博客首页$Z)[5K U0Xw V w

CNOUG博客首页m,d P;x$A!T'[U

SYS@dave2(db2)> select * fromv$database_block_corruption;

&{b*]Vpl3z`7f8N.S0

3x*H A4_ F0P&lc0FILE# BLOCK# BLOCKSCORRUPTION_CHANGE# CORRUPTIO

3a2h*UUX JN-]j0

Rm3?`Y+K^0---------- ---------- ---------------------------- ---------

n e|5y5rA Y0

0`,gV2j [J0 6 15 1 0 CORRUPTCNOUG博客首页&LL!R@@a

!IIZ^l0 6 28 1 0 CORRUPT

+| t$b aZ^%C0

/P2Ix4YXM*m9eB0

^:fwb0ti ?F,Dt"y0CNOUG博客首页Q#]1h[ V`n?

corruption block的信息还存在里面。 之前经过该视图和备份有关,我们用rman validate 一下datafile,之后就ok了。CNOUG博客首页9sj(R/I_S m

CNOUG博客首页+hB(K!d3XXvMp*H

2`*I)VEa#[I+B0CNOUG博客首页X[[ c"F

RMAN> backup validate datafile 6;

O7h-| M(h)e K0

:Q4uyWJ!ob&L,Xw$u0

W:? xtK.}6c+q0

-l6I.m$V j FPF0Starting backupat 15-AUG-11

{WT @r$U"Hit0CNOUG博客首页!ZA2| pe5S j,x

using channel ORA_DISK_1

S0wZsJ d+R0CNOUG博客首页j'] vh }5YJc

channel ORA_DISK_1: starting full datafilebackupsetCNOUG博客首页'H:]%FRs

CNOUG博客首页!zKeZ{

channel ORA_DISK_1: specifying datafile(s)in backupsetCNOUG博客首页w"[:sUD ]+T.O T

CNOUG博客首页q\ Wf!Nn](q#tq

input datafile fno=00006name=/u01/app/oracle/oradata/dave2/dave01.dbf

m(b J%g-{]0CNOUG博客首页B1PtrXm

channel ORA_DISK_1: backup set complete,elapsed time: 00:00:01

eM p1}(E&s0

S1BH D m8G4_2]0q0Finished backup at 15-AUG-11

c%N.y o Y|6}8S%k [~0CNOUG博客首页a#}cIz"\4]mC

$v'Z"~S"{?*y4CR0CNOUG博客首页i Y RO}7U0oaQ

SYS@dave2(db2)>select * from v$database_block_corruption;CNOUG博客首页2N/mc^o0xD

CNOUG博客首页 J/@-y-t*y:E5cx)bH

y{s-u+gA2Q0CNOUG博客首页yuG2gOj ubLBK6_

FILE# BLOCK# BLOCKSCORRUPTION_CHANGE# CORRUPTIOCNOUG博客首页3Dd?%k'_/caL9l~k\

@_+T+fZ&]0---------- ---------- ---------------------------- ---------

.G8^V%b^X#~!U-n0CNOUG博客首页)j Ty{wh g7NU

6 15 1 0 CORRUPT

S~,l-jr5@V8K Ly(G0

!a zGu3i uP0

,A*@%R:Qt3b\0G-KY0CNOUG博客首页{eCS4Nd W

--说明,我们修改的是block 28,它已经消失了。block 15 不是我们这本次测试修改的。 它是历史遗留问题。这里就不讨论了。

;_"s ab;y0

,W__G{0 CNOUG博客首页J(k]/m&S KdN

CNOUG博客首页:OFZ[ra(_

如果用rmanvalidate 之后还没有消失,可能是oracle的bug,参考:CNOUG博客首页:Ix!v qB,O:Ydl'i w

0H;L q]u?v0 V$Database_Block_CorruptionDoes not clear after Block Recover Command [ID 422889.1]CNOUG博客首页6Z"f/ul&}*H U

P6~k*rRyn0

'{pLA{0

1.4 使用RMAN 验证和recover corruption

D_B1iuW\{E-[ f0 之前有整理相关的文章,参考:

7x {*n9Xc8K0CNOUG博客首页4PI+a%{ ?

RMAN 验证 数据文件 和 备份 的有效性

0m-z3u1B:h0CNOUG博客首页7SJMn;Fe"m ml6^

http://blog.csdn.net/tianlesoftware/article/details/6460464CNOUG博客首页$m/XZW4JE\

F B3n^k$Rmo`0

%X(Av'k'C rO4{:K8e0CNOUG博客首页+o(j(MFb A*R1r'y#Ed#An5S|

RMAN的默认validate 只验证物理坏块,不验证逻辑坏块。

/gM4]6g(cv5]$O0

YC%s1w5W0{P0 CNOUG博客首页-^biHRZ

CNOUG博客首页ib;`+gh`

验证所有datafile 和归档是否有物理坏块:

2UE|h6w @c0CNOUG博客首页~'l)r f c$VJ{O

RMAN>backup validate database archivelogall;CNOUG博客首页3[|!s:lm3aDr1Se

}?Tx:T0或者

7m+F!j9``0CNOUG博客首页$l5z^eo4j

RMAN>backup validate database;

e @N"v3L6X8u0CNOUG博客首页w2\p2c:mq e$`7W`8tD

+L%SVM'PdUnyD}0CNOUG博客首页\C9b^&pf7|+D

验证所有datafile 和归档的物理坏块和逻辑坏块:CNOUG博客首页'o.Lq^ _2^%YP

CNOUG博客首页`Ul&n3h1~ zb

RMAN>backup validate check logicaldatabase archivelog all;

$lT sEwZ7kUy0CNOUG博客首页2U+Yj"z1t xt8B

或者:

1s'h E_9f9e_p0CNOUG博客首页A[&YBH i

RMAN>backup validate check logicaldatabase;

SI7x1Y Y4BU0

l"Q:DX$R-Y*e0

A[:_g'p'U u0CNOUG博客首页S3]+EM#D0GH h

注意: 如果加上了archivelog all,就必须要有归档文件存在。CNOUG博客首页2e4PO$s#V"JlTd%q

CNOUG博客首页1[ca[1XL"yS

CNOUG博客首页k7r3X"N![ k

iSs_b3O7P:B5Y0在Oracle 11g里还可以单独验证某一个数据块:

0V+qb-D o Z2go0

d[b1q4uc*` a UsAQ p0 RMAN>VALIDATE DATAFILE 1 BLOCK 10;

R;UV(i V J0

ThE4T*Jn_0

1[V rId0i Y5C0CNOUG博客首页uy!u}2^

对于物理坏块,我们可以通过recover database 或者recover datafile 来解决,但是对于逻辑坏块这种方法就不行。 在后面单独讲到逻辑坏块时有说明。对于逻辑坏块可以尝试对对象进行重建,如重建索引,重建表在导入数据。CNOUG博客首页/V]7sNn2N/Jeg;B

CNOUG博客首页3gsY3xxsK@B#Q

4v"n$|0sk F/u0CNOUG博客首页$ka/e7w s4X;^

对于物理坏块,如果不使用recover,那么块上的data 基本是丢失的。 我们可以采用相关的event或者通过rowid来跳过block,导出数据。 要保证块上数据不丢失,就需要通过RMAN有效的备份来进行recover。CNOUG博客首页nDJx4[ { y&C

CNOUG博客首页"T*`jK.A:a2PN

CNOUG博客首页E-l;F3v]z_

CNOUG博客首页J!BqFi

相关的recover 命令如下:

-k5t;u UB$UR*h0

E9hwR([4sFV9W7{0RMAN>blockrecover datafile 6 block 15;

~$f2M _o(SZ0CNOUG博客首页X @\(Tr7w

或者:

D` ]X^ TE)aWu0V5_U)j0

]/Itd-z S0RMAN> blockrecover corruption list;CNOUG博客首页U#|:i0QU*?f

CNOUG博客首页.c+\v i'r8M-B/ja

该命令recover 的所有block 来自v$database_block_corruption视图。

G*U;s*N.L*h*q0CNOUG博客首页 @0o4C/qA~I

CNOUG博客首页O_%?)Ot9U&` t

2o+X x6OT#u yX0RMAN : Block-Level Media Recovery - Concept& Example [ID 144911.1]CNOUG博客首页)N_Uyp+g:b

CNOUG博客首页5Hvi|8d V+b og

th&]6Wb&K0

二. Memory Corruption

CNOUG博客首页zA+e7]/U kze

2.1 BackgroundCNOUG博客首页2qE,y6N)o V w

CNOUG博客首页\+n3Yn[f V

Oracle allocates both shared and private memory. Shared memory is allocated when an Oracle instance starts and all processes(or threads) connecting to an Oracle database can access it. Oracle softwaredefines how this shared resource is accessed to prevent multiple processes fromsimultaneously writing to the same address. It also has to recover any incomplete changes made to memory by aprocess that dies abnormally. The amountof shared memory allocated is static in size and is only freed when theinstance is shut down. Private memory isallocated and freed as needed by each process (or thread) at the OS level. CNOUG博客首页!Zi9Qwiv wm%I*}h^

CNOUG博客首页4t5~_#f.\T

Corruptionis more likely to occur within shared memory than private memory so we focusattention to the structures and algorithms used within shared memory (alsoknown as the Oracle SGA).

.th$D,e:\7[0CNOUG博客首页/S*C GW6^IB,D

The SGA is divided into four portions - fixed, variable,Database Buffer cache, and Redo log buffer. A diagram appears below. CNOUG博客首页v5}&B%zLD

1X+X P/\6]z0 CNOUG博客首页K-u;@u_?_{

\,~.N&V(To0CNOUG博客首页`q.aA yN ` \:r

r? bm.B8C0

2.2 Definition

CNOUG博客首页d r~i$R

Memory corruption can be defined as inconsistencies in the data structures that arerelated to handling memory. Thisinconsistency could appear in any of the different parts of memory discussedabove. As discussed in the sectionabove, corruption in memory can be caused either in the SGA or the PGA. CNOUG博客首页'v] ~"g/{0F [

CNOUG博客首页6o:X0]!LL

Onlycorruption in the database buffer cache portion of the SGA can potentially leadto data loss. CNOUG博客首页v:kWRX_qBf3J

7m;j-h4`dp0 Thisis termed as ‘Cache corruption’ and is discussed in detail below. Corruption in theother parts of SGA do not result in loss of data, but can still cause theinstance to crash. On the otherhand, a corruption in the PGA causes only the corresponding process tocrash. If this process is updating ablock in the buffer cache when this happens, then the background process, PMONdoes the necessary recovery on the block being changed by this process. SMON and otherprocesses will rollback any other uncommitted data. CNOUG博客首页fZIK\

CNOUG博客首页3q"M$DIh+\8^W a-[8x

CNOUG博客首页 NY(\u#Q{T

2.3 Cache corruption

~D2~:om,p0 TheOracle buffer cache is a mechanism where frequently accessed blocks are storedin memory for quicker access. The cache also maintains older versions of blocksfor consistent read purposes. If thereis a corruption in this part of memory then there is a possibility of loss ofdata.

1n}'CWRzt0

.|4Q%pTI0 Theforeground processes read Oracle blocks from the disk into the buffercache. There arecertain checks done on the data block when it is read from the disk. CNOUG博客首页g'BY,Obr,w2x!q

CNOUG博客首页 ?W?.p/L J

For example, one of the checks is to compare the Incarnation Number (INC) andSequence Number (SEQ) data structures from the header of the data block withthe INCSEQ structure in the footer to make sure that the block versions match.This is done to avoid reading a block from disk whose header is corrupt. CNOUG博客首页+K{I#F!^8b3?

CNOUG博客首页3l b;_6@3J0m

C6`7r `|o |-u N0

K)fw'X ?6WG9qB0

*J&j8A'j!mm"~0CNOUG博客首页5`E Y5W1O8UEI

The structuresdiscussed above is specific to version 7.

a0PiM:`%@/?v0

9l }(i/?6R-iE0

@%X"d~`%c0

2.4 Causes

CNOUG博客首页l;LO7vq.OQ

In general, memory corruption is usually identified by abackground or shadow process whenever ittries to access the part of memory that is corrupted. Cache corruption, which might cause a loss ofdata, is usually caught by:

-J{s!NX Dm0

+z i+Y{ s G#Ta0 (1)the shadow process when trying to read or update a block in memory, CNOUG博客首页Y9H?~g-c

CNOUG博客首页"JiT(l/V @M {x

(2)by the background process, DBWR, when trying to write a dirtied block frommemory to disk,CNOUG博客首页3I o0i fG&Q'F+o

hWqt w?t3z0 (3)by the background process, PMON, while performing block recovery. CNOUG博客首页;V&i"X^I

j^^!G(bAc%G2n!F.V0 CNOUG博客首页w#u5O:K}"w-I5B

/Z/Q:d7uK&n l0Common causes include:

5mXG,Q#U~S0

6Z9oo-?7s s5NzP0 (1)Operatingsystem bugs causing bad reads or bad writes CNOUG博客首页g0e_P4@+v

LU.r+O?]/`2wN ?R0 (2)Hardware issues CNOUG博客首页J-g8J,VP Xq*w

CNOUG博客首页%Y Xu2ht$T4Vl

(3)Oracle bug

U K2y{\ W @0

R ~q*GXV0 (4)Non-Oracle program attaching and illegally writing to the sameshared memory address

i(Rn;g-O0CNOUG博客首页5U mmq h

CNOUG博客首页'?&{,{&E:e4m"k

2.5 Prevention

CNOUG博客首页;w)Y`,X gm'ja K

There is very little that can be done from the user’s perspective to prevent memorycorruption. An INIT.ORA parameter, DB_BLOCK_CHECKSUM can be set to true. CNOUG博客首页X;h6R.U*zT;M!A!P

K#zd"u1kV0 This enables another check where the block checksum is calculated and compared withthe checksum stored in the block header. If they aredifferent then the block is considered corrupt on disk, and the block is notread into memory. This prevents corrupt blocks from entering the cache.When a block is changed and being written to disk from memory, DBWR calculatesa new checksum for the block by summing up its contents and writes it in theblock header. CNOUG博客首页+wC,vrV'`tvvx\*R

T-},fz u"G i[0 There is a CPU overhead associated with this parameter since the checksum is calculated every time a block is read and written. CNOUG博客首页k0_A\;_#LK`,N

CNOUG博客首页n \Ml#u;FU

A similar parameter, LOG_BLOCK_CHECKSUM, can be set totrue in the INIT.ORA for verifying the records written to the redo log buffer. This extra test prevents bad redo from beingapplied to a block in cache during recovery. There is CPU overhead for reasons similar to the DB_BLOCK_CHECKSUM. CNOUG博客首页!O0[#xS&V6S0LH

CNOUG博客首页7l2j$n%p;C'n

The best form. of corruption prevention from occurring in a production environmentis to test the hardware, operating system, database, application and so on forbugs before rolling them into production. This is also true when introducing new hardware, patches and upgrades.

{1uoEnc0CNOUG博客首页.g!iw;n;g3F&Ge

&SUDva-P3L0

2.6 Detection

CNOUG博客首页y Q{qU

Memorycorruption can be detected from errors in the operating system logs indicatingany kind of memory problems. These canalso be found from the Oracle ALERT.LOG by certain ORA-600 errors. The first argument ofthe ORA-600 could be from 17000 through 17999 in case of memory corruption. CNOUG博客首页O7ZeVZX"j4A

CNOUG博客首页O6S pQ4m-s}eZ

Somecache corruption can be detected by ORA-600s in the range from 2000 through8000. One thing to remember is that notall ORA-600s imply memory corruption.

R7Ay,AT(}1T5I v0CNOUG博客首页'j)^ V/NC%{!X+k3fO

对于memory corruption的错误提示,是ORA-600的第一个参数值从17000到17999或者2000到8000. 这里只是一种可能,并不完全肯定。

X:UPg;N1xGbY0CNOUG博客首页3G#iI"~X {

ORA-600 各个参数含义说明

` QaH9G4dL.v0CNOUG博客首页.rcSr&]_?.rD;I"Q

http://blog.csdn.net/tianlesoftware/article/details/6645809

o zH${GK~ H0

oj8Z5~r*~0 CNOUG博客首页:u%k ~hs%J(b

2.7 Repair

jS:Vdw%g)H z0Location

[-K;G2}v6eg0
CNOUG博客首页2TIs` X d/X2D`W

Data loss CNOUG博客首页"SK4M J4G)o$v;u

CNOUG博客首页HbR2v!SBz8V

Repair

I V H#x4M*Kn9n0
CNOUG博客首页%X9W9t:qic v([

SGA - Buffer cache

4Iv0l%?+B~9F Z k0

2HIj$aU'n&e3oy$E|a0Probable data loss

&e `*P.I0qA@s1v0

`4[ip6Tp#vu0⇒ If the corrupt block has been written to disk, then the object to which the block belongs to has to be repaired by methods discussed under Media corruption. ⇒ SHUTDOWN and STARTUP the instance ⇒ To diagnose the causes for the corruption, call Oracle support with appropriate files listed below the table.

y*sG$\wY'i SP0

vWC2P8l GW-R/y0SGA - Redo buffer

7X1r^ V7?[o%s0
CNOUG博客首页WwD,Z0fe*r

No data loss CNOUG博客首页u ~4\g ]3l.e

CNOUG博客首页9c k._0p |x

⇒ SHUTDOWN and STARTUP the instance. ⇒ To diagnose the causes for the corruption, call Oracle support with appropriate files listed below the table CNOUG博客首页L9_8Yt#_^U

CNOUG博客首页7U b FG\6w

SGA - Shared SQL Area CNOUG博客首页8d3l.K+_b F

WU-~C Y:PHC|0No data loss

2UknkX,t0

_aL/JEB3n!Ms:R9J0⇒ SHUTDOWN and STARTUP the instance. ⇒ To diagnose the causes for the corruption, call Oracle support with appropriate files listed below the table CNOUG博客首页4wCz@0sP

CNOUG博客首页 s"~i9?f

PGA

(B~&d$c9a{:yXi0

-n W)tw-M,@/e_qX0No data loss CNOUG博客首页9CT|:c5cb0qx_

Ra-F-Us0⇒ To diagnose the causes for the corruption, call Oracle support with appropriate files listed below the table

/v7`(ip|%sKlQ0
CNOUG博客首页5kun5f4{~U

k3f4z6c0p)|3v {0CNOUG博客首页-h1cW Gr `c

To diagnose the cause of the corruption, call Oracle support with the followinginformation: CNOUG博客首页[o#V}@r

9yn$V,C4E ihJ8m`0 (1)INIT.ORA file

ANY\;Yt1WKzF0CNOUG博客首页B/~lT!k*?i

(2)ALERT.LOG CNOUG博客首页{(H'pc9z2CbT

1sQ3y\q4S0 (3)Trace files for any ORA-600s found in the directory specified by theINIT.ORA parameter, USER_DUMP_DEST

5IQT*G^Zx@0CNOUG博客首页X(Z BHXX5G

(4)Heap dump : this can be obtained by executing the following commandin SVRMGR or SQLDBA:

m+`@ q\'O)h$r0CNOUG博客首页%? mw1P&f5{f

SQL>ALTER SESSION SET EVENTS ‘IMMEDIATE TRACE NAME HEAPDUMP, LEVEL 10’;

,o7w.x8M;U |'P}0

U9[3AE2R*EGI;q4g0 This creates a trace file in the USER_DUMP_DEST.

"tq1_TB6u0

K/yMa*X"Xd~0 (5)Reproducibletest case CNOUG博客首页.~)r\QoE W

CNOUG博客首页D&V@[wyc

(6)Thorough history of events that led to the corruption

1ANFj Jm\1\e0CNOUG博客首页)B1Y:MC(h4[t7N'Q;MS%C

(7)Record any noticeable changes to the environment such as newINIT.ORA parameters, new code, patches, and upgrades.

|]E Cq0CNOUG博客首页OCS}L|

CNOUG博客首页s4da&H?0gYe

三. Logical Corruption (soft corruption)

CNOUG博客首页+JrXDsoCf&o&i2LE

LogicalCorruption can be defined as a situation where the actual data is not corruptedin a data block but a query results in a wrong set of data due to a problem inthe way data was loaded into the database or due to a misexecution of theoptimizer path. A logical corruption is not an inconsistencyin a data block but an inconsistency in the result of a query.

$JFUB%_5A0

qS(qr;|m\3I0 逻辑坏块通常不是data block的不一致,而是查询结果的不一致。CNOUG博客首页0_;Din lR VhcN;B

CNOUG博客首页!A;QO+d.~!l K A(fU

Forexample, a query that is expected to fetch 5 rows might result in 10 rowsbecause the data in the table was duplicated due to the lack of a primary orunique key. CNOUG博客首页4]5u Us$Ij

CNOUG博客首页DU9L3u_BKS

比如我们查询5行记录,实际却返回10行。

@*Pf~a;FI0

,Oz$m)~?[|*?0dH0

:A xJ \2f%zu4u/J0

3.1 Causes

CNOUG博客首页7R6[-rf6| d&J

Badapplication design that lacks validation or proper integrity checks OptimizerBugs (in rare cases) CNOUG博客首页xq JXl

CNOUG博客首页!P9JU*Ad9@3xx;L-{9_

通常是应用设计不完善或者是优化器的bug造成。

n8m:zU;^S)_0

U-{V [C[!W0o k|r+~0

,M&z'v7Cb6M%FT0

3.2 Prevention

%J/t `0_v-C u8c0 The only kind of prevention methodology for avoiding user errors is to test thatapplications return valid results thoroughly before implementing them inproduction environments. CNOUG博客首页,m oO S0Z9l+b:c

9g8eL8G`? N0 There cannot be a way to prevent logical corruption caused due to optimizer problemsunless the appropriate patches are applied or the database is upgraded to themost recent version.

f.F2GW{0CNOUG博客首页|)d bq5aP*nv

&O$z6a(\}{"v8[k0

3.3 Detection

CNOUG博客首页7Y9?2h(|4i:ZZ Q-`v-_

When logical corruption is caused by user errors, they are more difficult to detectthan those caused by optimizer problems. In case of user errors, the user should have a good knowledge of theapplication that is being run to identify inconsistencies in the queryresults. In the case of optimizerproblems, inconsistencies may be accompanied by changes in the query executionplan leading to a different response time. CNOUG博客首页xc0_3o1H3k

#b VU ?5{v K0 Also one may notice, invalid results only when using the cost based optimizer rather than the rule based optimizer. Other changes inthe query path can be caused by changing the optimizer mode, specifying a different optimizer hint, dropping or creatingindexes, or analyzing objects to generate new statistics.

+s8c1}zl$};`[5r0CNOUG博客首页(Yg-n/Rl#}9VQ

b#]4`Fs1q0g&As0

3.4 Repair

#C(Ax"|*[8WJ#`Go dW0 Whenthese problems are caused by user errors, they can be fixed by making theapplication more robust. CNOUG博客首页 {r3_ z?0zD

CNOUG博客首页#Qpo$O)n[0H1] p,\

解决这个问题需要完善系统的设计。CNOUG博客首页{y}$`}2c{

y g.?Y-\!Eb(D7l"U0 Fo rexample, if invalid data is successfully inserted into a table because of alack of integrity checking , then constraints should be created and the invaliddata will have to be found and deleted. In case of optimizer problems, contactWorldwide Customer Support Services to determine if this is a bug with anavailable patch. CNOUG博客首页f}Kv qCIB

CNOUG博客首页%G,E"{krD?iA

They will need to be provided with the query, EXPLAIN PLAN and potentially theexport dump of the tables involved.

&{W6|ge1A4EpOXB0CNOUG博客首页 L {,J _G$L

CNOUG博客首页;N[5M:E9l W9e

四. Media Corruption(physical corruption )

CNOUG博客首页*Dq)xw A7u7j U&v4~

Media corruption can be defined as a situation where an inconsistency has occurred inthe data block structures in the physical disk as a result of mediafailures. Media failures are failuresthat are caused due to hardware problems, operating system problems, controllerproblems, logical volume problems, and so on. As a result of a media corruption, the data in the corrupted block islost.

2fkQ3b o4n c0CNOUG博客首页7]Lb,L\R6Z

物理坏块通常是block上的不一致,造成物理坏块的原因可能是硬件故障,操作系统问题,控制器问题,逻辑卷问题等。 对于物理坏块,其block上的数据会丢失。

T R#A$zp7N/A0CNOUG博客首页0i?hA9o!L

'S Y f(aY5p\0

$C7_)})H'@3f0 MediaCorruption could occur in different parts of the database and the detection,prevention and repair are different depending on the object that iscorrupted. The following are differentobjects that could be corrupted:

X4|0U Kh N0CNOUG博客首页&`"nX'Ub{X0V7K

物理坏块可以存在数据库的不同部分,对应不同部分的处理方法也不一样,具体可以以下下几种:

p"G7d;blg%WH0CNOUG博客首页*O"oc.f5e

∗ Control file CNOUG博客首页MVEG%J G.|

CNOUG博客首页q3XSD/O iBC

∗ Redo log file

V,|3N Hh k0

hR(r1Cd sLh0 ∗ Data file The block could belong to one of the following categoriesin case of data file corruption: CNOUG博客首页4\L5ZW-Jej:Sg-A

3t5Z*`)[1C)b]T0 (1)File header block

7UM9^ ^0{[Tiq0

8o \hijR0 (2)Data dictionary object (SYSTEM tablespace) CNOUG博客首页P2^ l"nn1b)QS

CNOUG博客首页]6zmVXbr

(3)Undo header and Undo blocks (ROLLBACK tablespace)

z0w.s$N)A)X"?:^p0CNOUG博客首页eq Z9K C]5Ke

(4)Sort blocks (TEMP tablespace) CNOUG博客首页#nd9Xd/y7S

CNOUG博客首页z EN;A J e H

(5)Data/Index blocks (DATA/INDEX tablespace) CNOUG博客首页,d4C-Q4w+`

CNOUG博客首页[i4`b _ CIP `

=>Tables CNOUG博客首页f CSD%M:i \

CNOUG博客首页9cq z&cq%^M d*}Z

=>Clusters CNOUG博客首页o}zaD

JP3~ N]o0 =>Indexes CNOUG博客首页DWo W4T_I

n#N1G pB0

DKD#\8l0

4.1 Control filecorruption

4}8Uzc.\.O0 TheControl file is the file that has the structural information of thedatabase. The control file hasinformation such as the database name, names and locations of the data filesand the redo log files belonging to the database, the creation timestamp of thedatabase, log sequence information, checkpoint information and so on. CNOUG博客首页QrC/C@S

CNOUG博客首页|IU\!e

控制文件包含了数据库的一些结构信息。 CNOUG博客首页F q%cb U3j

CNOUG博客首页? U-R5?$\U

CNOUG博客首页)k.p)P?;iw-i

)x#Z+h|Q0The control file can be dumped in asciiformat by executing the command: CNOUG博客首页 SIO)I*M^X

6{_ PE8@(r!u;Z0 ALTERSESSION SET EVENTS ‘IMMEDIATE TRACE NAME CONTROLF LEVEL 10’;

F R"tY X l@0CNOUG博客首页5X M4U#p9?"io

CNOUG博客首页8en S'i.U/wx.K

7Qv,h3b1Qz-U0 This command creates a trace file in the location defined by the INIT.ORA parameter,USER_DUMP_DEST. CNOUG博客首页 `8i%|P8LPv6R

CNOUG博客首页L?E3S4Gy

CNOUG博客首页y!Gl*gg

CNOUG博客首页N*O }fL$Zl

可以dump 控制文件。 有关控制文件的更多内容参考我的blog:

| sMBae-UB0CNOUG博客首页&|4G!T#Er"zMw"z

Oracle 控制文件

6~ V6`Bsh0

%~;`6N]{ eHE*|8T}%y0 http://blog.csdn.net/tianlesoftware/article/details/4974440CNOUG博客首页c)j?]1pX'g

CNOUG博客首页8}G!@0f:K*?

e7_u~8R4g0CNOUG博客首页xn/d)RL

Whenany of the mirrors (Oracle’s multiplexing) of the control file is corrupted,critical information about the database cannot be accessed which will result ina database crash. The following tablesexplain the potential causes, detection, prevention and repair of a corruptionin the current control file.

_(NJffEB~0

_,D1JT)iTR+m0 虽然控制文件有冗余,但是任何一个控制文件出现损坏都会导致db crash。CNOUG博客首页'a0G _ okN'R

^ m,H^T/o.}0

.q(t e|[*}u0CNOUG博客首页(R#l&Uk.[j

CNOUG博客首页/B-I7u3A)O:lf4K

4.1.1 Causes and Prevention

CNOUG博客首页P*i6c L3V5I'Ge

\gI@T*F?'_!K7L0CNOUG博客首页8i4y^0g` T5m3G"x

4.1.2 Detectionand Repair

l)K1]!w%u#EWd2tR0

]4h+X!M{[J0CNOUG博客首页+?7? \ WjX'x

;n#Q-\q1uR!A"g {s0 控制文件通常有三个,任何一个出现corrupt都会使db crash。 这种情况下,可以修改初始话参数,使用其他的几个控制来启动db,如果能启动,就ok。不能启动,就需要重建控制文件来解决。 关于控制文件的重建,我上面贴的链接里有。

^,qb5{@,dQT*~0CNOUG博客首页1r{/Ui5D

CNOUG博客首页c3~b%lq(M

4.2 Redo log file corruption

CNOUG博客首页[*Ez3z9a+Nd T

Redolog files are critical in protecting a database from failures. The changes made to data in a database arerecorded in the redo log files.

D SPd6S;OA:Z0CNOUG博客首页*a K!ay!bQ

redo 是在db failures来进行恢复的,所有的事务操作都会记录到redolog里。

8Lc1]C&q0Dh a%C0

+vy~!C@}2Wl@g*^0 CNOUG博客首页K6{7Sk4s^ uOH

rf+g @Y ].I/U%W0 When there is a failure which prevents data from being written to the data files ondisk from memory, the changes can be obtained from the redo log files. When a data file is corrupted, a backup froman earlier day can be restored and the changes from that day onwards can beapplied to the data file from the redo log files. CNOUG博客首页+H!i|6U}7H

8aDfS}+w3Jg0 CNOUG博客首页 M#sP%](F)zy{8a

}L,Hp:b)[ Q;_6|0 The redo log files are used only when a database is recovered from a failure. There are two kinds of redo log files: Onlineredo log files and Archived redo log files. Archived redo log files are the spooled copies of the online redo logfiles.

'U;T%xf [im~0CNOUG博客首页$K0f0P5hw4de

~p7y:G*of6K5`.k0

$j|'g&Q hI0 Corruption could occur in an online redo log file or an archived redo log file. If a corruption occurs on an online redo logfile, the instance crashes if there are no mirrors of the redo log file or ifthe mirrors are corrupted as well. Ifthe corruption occurs in an archived redo log file, the database is notaffected unless a backup is restored and recovery is being done for which it isneeded. CNOUG博客首页@X3yw9K\

C6C xy_0D0 corruption 可能发生在online log 或archived log。 如果发生在online log,并且log 没有镜像或者镜像log也出现了坏块,这种情况下,db 会crash。 如果出现在归档文件上,仅当使用备份进行恢复时才会有影响。

_0W9y;fiBc$K ?0CNOUG博客首页 u3w NE`z5n

.lqJ;Z Wlo4_0

4.2.1 Causes and Prevention


\^0Z8^.t Vp0
CNOUG博客首页G)k0mh6J Y{

4.2.2 Detectionand RepairCNOUG博客首页+OwVt6h v

CNOUG博客首页)cO+X iyw

CNOUG博客首页 H"f+~WQ4ux-vt,m$]

CNOUG博客首页#K@m$UH

CNOUG博客首页ywd9A|

6B J|)kv}0\e_0Forcing the database tostartup using _ALLOW_RESETLOGS_CORRUPTION:

]X\2Oo:b(K9R0

1w{,g)Sl0 This parameter is undocumented and unsupported. CNOUG博客首页 R"[!He)?6y

#z*{4M3Iag9NM[3o`0 The_allow_resetlogs_corruptionshould only be done as a last resort. Usually when a database is opened witheither the RESETLOGS or NORESETLOGS option, the status and checkpointstructures in all the file headers of all data files are checked to make surethat they are consistent. Once this ischecked, the redo logs are zeroed out in case of RESETLOGS. When the _ALLOW_RESETLOGS_CORRUPTIONparameter is set, the file header checks are bypassed. This means that we do not make sure that thefiles are consistent and open the database. It will potentially cause some lost data and lost data integrity. The database should be rebuilt since data andthe data dictionary could be corrupt in ways that are not immediatelydetectable. This could lead to futureoutages or put the database in a state where it cannot be salvaged at all. There is no guarantee that this will work. CNOUG博客首页!r;i#Q|.{?#U

CNOUG博客首页0n8W$^&r;J&u F'\

T@` D5qtN_0

XaiWsO*?5kg0Advantages CNOUG博客首页-j LH P1F z

6j!n V Q5mdW3AaR0 nsome circumstances, database can be brought up even when no valid backups areavailable

iG\ i3n!p i0CNOUG博客首页 [T` z TS'x!_$Y

CNOUG博客首页(|#c-FMg r:O

&XtMIQI0Disadvantages

*V&snH\"`9_0G0CNOUG博客首页 X|W0r ?0U

(1)The database will not be in aconsistent state once the undocumented parameter is used and so it has to berebuilt by doing a full database export, recreate the database and a fulldatabase import.

QPj#b0W~ {5o\q)n0CNOUG博客首页 b#n0I#Kt\D5It

(2)Not guaranteed to work

b4om6G3ZBS;J5K0CNOUG博客首页.{G8Y#c4y\$X7u oJ-V

CNOUG博客首页 xd-Jp-e

&@rT8kj0关于online redocorrupt,曾经整理过,参考:CNOUG博客首页:D C\`%]

1_s6^)A*T)]+N0Current online Redo 和 Undo 损坏的处理方法

E;j'R|k.b0CNOUG博客首页7{TT {7~l-J NO

http://blog.csdn.net/tianlesoftware/article/details/6261475

eI\4~*dg"B[ y0CNOUG博客首页4Z \#UV4K

CNOUG博客首页5L}H8_|

CNOUG博客首页 rY^ I8E O9s3~sI(s ^

Oracle 不同故障的恢复方案

:AC6l]]p7|0

;Ck E;f{9~K K0http://blog.csdn.net/tianlesoftware/article/details/6106178CNOUG博客首页9Kw*z{_9Sw{X

CNOUG博客首页K,K LS|_k#~z

CNOUG博客首页(r/?6[ O0z_

4.3 Data file corruption

-{V'lL8t z0 The data files are the physical storage unit of data stored in a database. Each data file ismade up of data blocks which can be divided into 5 different types (in thecontext of media corruption):

U1e1u`yl9A0

2cH#j"`r1r-K4_0b0 (1)File header blocks : File header block is the first Oracle block inevery data file in an Oracle database. This block keeps track of a lot of information about the data file thatit belongs to.

je o7T UO3n"S1a0CNOUG博客首页CO"O(pdT@

(2)Data Dictionary blocks : SYSTEM tablespace consists of datadictionary objects. Data dictionaryobjects are objects that keep track of information stored in the database suchas the information about the tablespaces, information about the data files,information of amount of free space in each tablespace. CNOUG博客首页 q(W\ f,P"[

CNOUG博客首页 V0qj/xQ

(3)Undo header and Undo blocks: ROLLBACK tablespace consists ofrollback segments that are made up of undo header blocks and undo blocks. These blocks are used to undo a transactionwhen it fails or when the user executes a ROLLBACK command.

vKh,v8[ Pe,V*N0

f:v5d*T~L\0 (4)Sort blocks: TEMP tablespace consists of temp segments that are madeup of sort blocks. Sorts are usually done in memory where they are allocated asize specified by the INIT.ORA parameter, SORT_AREA_SIZE amount of space. If the sort is so huge that it cannot fit inthe allocated space in memory, then temp segments are created in the user’stemporary tablespace for doing the sort on disk. CNOUG博客首页ew'U;gy6P+@ K

YKP2}{p V1?;Q0 (5)Data blocks: DATA tablespace consists of tables, clusters andindexes. CNOUG博客首页-fYw)pXj5B1P*]J

Bd%B@?0

h9B0vM`H+I&h~L0

N7H9xVX q$A"m*pc0 The following tables explain the potential causes of data file corruption and alsothe different ways to prevent data file corruption.

2CIsI:rS#R zmq+Ax4J0

1n'TQSP&E_.g B D0

0\ XA5F$p{s"h0

4.3.1 Causes and Prevention

o^#H UcP0

.g&ZxB5dp r*?;_z0CNOUG博客首页_fKNM){XE

CNOUG博客首页.x Vq)Wa$l

Now that we have discussed the causes and the prevention, let us discuss thedetection and repair which is different for corruption in different blocks.

7w Z] ~K0CNOUG博客首页D*H6[ Q4s[ \

#S#Zu6?v6{&a$X*dZ0

4.3.2 File header block

.l ~4Z(tXi:]z:c0 Fileheader block is the first Oracle block in a data file. This block keeps track of information aboutthe data file itself (i.e., file metadata) including different checkpointstructures (explained below), status of the file (e.g., hot backup in progress,hot backup ended, media recovery required, instance recovery required), andresetlogs information (information on the time when the database has beenbrought with resetlogs option most recently).

C%gu h6rAR.y0CNOUG博客首页m"i1t1y X/Kv/?

File header block 是data file的第一个block。 它保存了datafile的一些信息。CNOUG博客首页iw.N.^}7b,YT"d(E

CNOUG博客首页} S_)RN-AJ ~8n

CNOUG博客首页y2I]%C%L0fA

CNOUG博客首页Iz#F,x L0AT

Checkpointingis the process of writing the blocks that have been changed in memory to disk.The control file and the data file headers are updated after every checkpointis done in the database. This is anautomatic action executed by the background process called the Database Writer(DBWR). This can also be forced bycertain user commands such as a normal SHUTDOWN, a normal OFFLINE of atablespace and so on.

R4n4H K4_s,Pf-_0

0Z,l$JH6^3m&]3a2S0 checkpoint进程会将已经变更的block从内存写如磁盘。 每次执行checkpoint时,dbwr 进程会更新controlfile 和 datafileheaders。 当normal shutdown 或者normal offline tablespace时,也会更新control file 和datafile headers.

/D+mZ#v)?)`0

] b/Y F Cv0 CNOUG博客首页.}z7S.[c'R%s

U:C:oik:pV0 Thedata file header block keeps track of the most recent checkpoint informationwhich denotes that all blocks in this data file that has been changed beforethis checkpoint has been written to disk from memory and so a failure in thememory will not affect the data in this data file before the checkpoint.

O&v0iZ9da Tn1g0

U/a(U LIQ0 datafile header 保存了最近一次checkpoint的信息,它表示该checkpint 之前已经改变的block已经从内存写入磁盘了。 当memory 发生错误时,不会影响该checkpoint 之前的data。

&O:Jh#I$D8@0

(a$R&`iYN,a0 CNOUG博客首页*i\GP9s

CNOUG博客首页m&W].N#`P

Whena file header block is corrupted, the information stored in this block cannotbe accessed which means that the objects in the data file cannot be accessedeither. The following tables give anidea of the potential causes for a corruption in a file header block and theprevention, detection and repair of the same. CNOUG博客首页?XR,i%B};a*}'f,Z

J\]lW/]"a Q0 当 fileheader block 发生corrupted时,存储在该block里的信息无法读取,那么的data file 也就无能读取。 CNOUG博客首页!h.b Wa7E'p*Vj

CNOUG博客首页`hU@#gg'c?

CNOUG博客首页C.\;iKDUdl*C(V
CNOUG博客首页XnjX+gI5{

.{eB }gB0

p&Z3Jf;w[T0在我的blog 里的示例四,就是使用bbed修改data file header的:

)~u.iQ1`z3s0

6_$V+g:Z9Y0Oracle bbed 五个 实用示例CNOUG博客首页L+r8J`#qi1b3{X:b

CNOUG博客首页3x n+X*RE M.C

http://blog.csdn.net/tianlesoftware/article/details/6684505

.rb(_x7PmJ-q-^0CNOUG博客首页Iv.|(u3xt2~

CNOUG博客首页6t+F\v#um

4.3.3 Data dictionary object (SYSTEM tablespace)

y)`t2E n/? X0 Datadictionary objects are objects that reside in the SYSTEM tablespace which hascritical information about the objects in the database and their relationshipsand attributes.

.X@-beS&M.}6E_:g0CNOUG博客首页7s?&[6gr5[ f2L

Data dictionary 对象存放在system 表空间,它保存了数据库中对象的重要信息,如对象之间的关系和属性等。CNOUG博客首页2]LM1WWp!Y }

q$?_1ap0 CNOUG博客首页Wc `'x6\0X

7[!f@u0}_a0Data dictionary objects found in the systemtablespace are described below: CNOUG博客首页E#i.~ t}q ^

CNOUG博客首页vz+s2Ul,~H3fim

SYSTEM 表空间下的data dictionary objects 有如下几种:CNOUG博客首页 TZmJk+_u

CNOUG博客首页+s"^ T-KF

1)Objects created by the script. SQL.BSQ run by the CREATEDATABASE command found under $ORACLE_HOME/dbs directory. There are certain tables, indexes andclusters that cannot be dropped and recreated in the SYSTEM tablespace. These are the tables that are used whenbringing up the database. They arecalled the bootstrap objects and are found in the SQL.BSQ. It is not an easy task to locate datadictionary objects that can be dropped and recreated since the relationsbetween the different objects could result in an inconsistent database if wedrop the wrong object.

9s0}Z\'`WsM0

6NE eC+Y3dPV0 datadictionary 是在创建数据库时通过$ORACLE_HOME/dbs/sql.bsq脚本创建的,并且这些核心的表,索引和clusters 不能被drop 和recreate。 他们在db 启动时使用。

tO%w*k^7g%i0CNOUG博客首页qZ5CP0w9X{~+A|

2) Views createdon the fixed data structures (V$ views).

,La)d!UP0

z#|0lpl d^ U)D0 3)SYSTEM rollback segment created after the databasecreation. If the corruption is in this segment, then the most recentbackup should be restored and a point in time recovery should be done on thedatabase up to the time when the corruption could have occurred.

'O5_pD!H3u0

.CZ&?.F-WhI0 system rollback segment 在数据库创建之后创建。 关于systemrollback segment在我的blog里有说明:

n#K |:^*^9`@ q7z0CNOUG博客首页6C ?y{1]/x

Current online Redo 和 Undo 损坏的处理方法

$liC"k,gi4w0CNOUG博客首页z"w*g,haH

http://blog.csdn.net/tianlesoftware/article/details/6261475CNOUG博客首页#S/RO)v'_6X)Oo

CNOUG博客首页F*k;dm5E?1m c H

4)Compatibility segment (this is the only segment of type ‘CACHE’ in the SYSTEMtablespace). The Compatibility segment is a segment that keeps track of thefeatures being used in the database which will be used when the database isbeing downgraded to an earlier version. This segment is used to make sure thatthe features being used in the current version are disabled before beingdowngraded to the earlier version. Ifthe compatibility segment has a corruption then, the database can be brought upby shutting down and starting it up. Ifthe problem is still not fixed call Oracle support with appropriate trace filesand the alert.log. CNOUG博客首页b^+Q`-cf&]}Cp

+Chi?3T'NEW0 CNOUG博客首页'M2j xLCl

CNOUG博客首页6d2B.\no

The supported way of fixing data dictionary corruption is to restore from a backupand roll forward using the archived redo logs.

!wI J`E(o@o0CNOUG博客首页5V4h"S(e*t ]-V1C

;rLb-S(~(?O |.n0

P2f$w)} qu&x$i0 CNOUG博客首页 ?mMfy m9i8W#~

CNOUG博客首页8_? aQ M.vrf

CNOUG博客首页%ys{P0N7H1R.G

4.3.4 Undo header and Undo blocks (ROLLBACK tablespace)

1wS[-Y7F.u1y^ F qT0 Rollback segments are undo segments that have information about the transaction that hasbeen executed so that it can be rolled back in case of failure of thetransaction or when the user asks for the transaction to be rolled backexplicitly.

El6s] G f0

+C9WA2h/@l#GL0 They are made up of undo header blocks and undo blocks which are required to accessundo information to provide for consistent reads and transactionconsistency. If the rollback segment iscorrupted, the transaction consistency of the data blocks (including datadictionary objects) can be jeopardized.

*k L%P,dX0M0

n.W7ej4l c @0 CNOUG博客首页_c$k{ x"a.Xx4i.h

5X3WdFb1J2q0

CNOUG博客首页+{W di/Q5i!jG`]

CNOUG博客首页[c%@l-u1x?

Vc,y;x`G|0

T{%]gb$Jos)~0

q Z2N7U5Z!?5k~\0The corruption found when undoing atransaction could fall under three categories :CNOUG博客首页/Y$~-Q_'I,a@%b U

CNOUG博客首页1n*{4u @ cl0~9c*c

在以下三种情况下,可以会出现corruption:CNOUG博客首页m'aMX8H

CNOUG博客首页"Z[%AFlS)T,nm

(1)belongs to the object (table/index/cluster) that has the data onwhich the transaction was executed (data block) CNOUG博客首页UN#D&`)r t-MR3U

CNOUG博客首页ZJ FYnvq'z z-P/z

(2)belongs to the undo block that is being used to undo the transaction(undo header)

&cAdQ5n+iN&g(I0

[0Frp;r(m+rPr0 (3)belongs to the undo segment header block of the segment where theundo block is found (undo block) CNOUG博客首页0m h3aJ R6M oF\wd

A APHlF0 CNOUG博客首页 {[#_OZ5y\

CNOUG博客首页d1q I~r {

对于第一种情况,出现corruption 的位置是data block。

#Bn:^%`*x)q0

9ju S"|Uq0 Thefirst case where the corruption is in the object to which the activetransaction belongs to, we have to identify the object first. This can be done by setting an event in theINIT.ORA as follows:

y Q4{~W4s0

H+FXC/^t(e9W]0 event= “10015 trace name context forever, level 10” CNOUG博客首页U5yj&u&Uk+c

2JxBV%k9wY8em0 这种情况的坏块是active transaction,当我们重启DB后,会进行相关的transaction recover(Rolling Back)。 当recover 完成,就可以正常访问对应的block了。 相关文章参考:CNOUG博客首页1uB&HS,M2M/Y

CNOUG博客首页x*Lfb3[4f j ]

还原真实的cache recovery

)\g!b]x;Vb0

EH vV$qi0 http://blog.csdn.net/tianlesoftware/article/details/6547891

5H!`4E!}9F0CNOUG博客首页g%ko \;?&X2i3o

Oracle 实例恢复时 前滚(roll forward) 后滚(rollback) 问题CNOUG博客首页0M}h DqlT

CNOUG博客首页!{+^,| Jb1K&pX

http://blog.csdn.net/tianlesoftware/article/details/6286330

n/XX*i$W0c3[ r0

"JI{s0JX@0

+T!p\/Vw2Y"N2P0

mCBKCtH+JJ0 Thisevent traces the undo segment recovery when the database is started, the eventputs out a trace in the directory specified by the INIT.ORA parameter,USER_DUMP_DEST. This trace file containsa transaction table for each of the rollback segments that are onlined in thedatabase. The trace file has a messagethat says ‘error recovering tx(#, #) object #’. Tx(#, #) refers to thetransaction information and the object # is the object id of the object thathas a corruption. CNOUG博客首页`b,i l"L

O `m'JDp6X0 设置event时候,会dump DB 启动是的undo segment recovery,在trace里会有‘error recovering tx(#, #) object#’信息,其中Tx(#, #)指的是事务信息,object #是corruption 的对象id。找到对象ID 后可以通过如下SQL查询:CNOUG博客首页%K+rxqX0}7w9ah

s5i|(j*wb0

9r2~*c1SI%H6J t0CNOUG博客首页q*} IiK$Myp]

The following query gives the name of theobject that is corrupted: CNOUG博客首页T-{)z"Q{_yo.T

a/u*@qW0Vz C q0 SQL>SELECTOWNER, OBJECT_NAME, OBJECT_TYPE, STATUS FROM SYS.DBA_OBJECTS WHERE OBJECT_ID = <object #_from_tracefile>;

7MB$gn9\X0CNOUG博客首页8d2o tg?%`^6n w

(]_|N/F T:XF8` E0CNOUG博客首页H1e[?XsG"b

对于第二种情况和第三种情况的处理,参考我的blog:

_eF{Z xn0Rq#O^0

3z8A)H`ny E0 Current online Redo 和 Undo 损坏的处理方法CNOUG博客首页Kj2U~4a w"h

CNOUG博客首页-}%_[wwh

http://blog.csdn.net/tianlesoftware/article/details/6261475CNOUG博客首页_:lQnn(|~Hj*ky

t\h'Q4Y:HL6C)P0

D\)w1yx2_E(~3_/m0

4.3.5 Sort blocks (TEMP tablespace)

CNOUG博客首页Iy7|.ZRJ

Sortsare usually done in the part of memory allocated from the SGA. This is defined by the INIT.ORA parameterSORT_AREA_SIZE. If the sort space neededfor a sort is so big that it cannot fit in the sort area defined in memory,then it is done on disk by creating segments called the Temporary segments.

dmCv*f0

k F%?I0G|#SkG0 当SORT_AREA_SIZE 指定的sort 空间不够时,会在磁盘上创建一个temporary segments来作为排序使用。 建议每个用户指定自己的temporary tablespace。

{Ko6T:u[0CNOUG博客首页o0A5o8{u&K(GE

Itis advisable to create a separate tablespace called the TEMP tablespace. After creating this tablespace, alter theusers to use this as their temporary tablespace by executing the followingcommand:

v` {!?S(IM3h0

FH![3q)@;HlM0 ALTERUSER user_name TEMPORARY TABLESPACE TEMP;

'pL,[zW2@0

*ML+U5X1W_+G0 CNOUG博客首页y,r$ddzd

CNOUG博客首页U v#Y@&IBf

This way, the temporary segments created by any user will be in the TEMP tablespaceand it provides easy manageability. CNOUG博客首页'FC v9q.h"J`Iy"|I$z9py

b6[#T3?1mN"d0

!{8cG6ozh0CNOUG博客首页:n `t5h6n s#{/Rw

Detection

+b"p5a0ZO e2Q0

;a1Ft-H B0· Usually thissegment is never corrupted since they are reformatted every time they get used

;?Z6x8Lm3] Q0

)n?*a]#E/F0

j:I3`Z0s0CNOUG博客首页4LJD/R7s1X u!_k

RepairCNOUG博客首页@URJ5~z

CNOUG博客首页|vIea L

· Tempsegments are reused frequently

Pp!O2p-yJ/n0CNOUG博客首页*Z-Nj*Zd#W BKw

· If problempersists, either move or drop and recreate the temp tablespace

r| F&YL!v@0

)kp` C lS9o:V$@5J0

LhbI$m!x0

4.3.6 Data/Index blocks (DATA/INDEX tablespace)

CNOUG博客首页+\Q+z#f,b Q

Whena data block is corrupted, when it belongs to a table segment, cluster segmentor an index segment, the detection mechanisms are the same:

J!q bzTG6T{0

P'OZ sk4{O9C \0 datablock的corrupt可以出现在table segment,cluster segment和index segment。CNOUG博客首页6|/n$Sm;Tx3h

CNOUG博客首页 H2eH xv u c

I#tSG N{Nf0CNOUG博客首页 Me-M+@u#u,b

可以通过以下方法来检测corruption:

&L th4Q|!A9X0CNOUG博客首页,c:yE"` t%D\

(1)DBVERIFY can be used to detect the corrupted blocks in thedata file CNOUG博客首页'G%Y }H+X5u

GJ jx[E0 (2)ANALYZE command run on the objects give errors (ANALYZE<table/cluster/index> <table/cluster/index_name> VALIDATESTRUCTURE;) When an ANALYZE (with CASCADE option) is run on a table or cluster,it cross verifies the index and data/cluster blocks along with the integritychecks done for the block. CNOUG博客首页Y$])pAt {v U2}Z

0|"X2m1r nI|1Db Q0 (3)DB_BLOCK_CHECKSUM can be set to TRUE in the INIT.ORA file.When a block is changed and being written to disk from memory, DBWR calculatesa checksum for the block by summing up its contents and writes it in the blockalong with it on disk. The next time when the block is being read by theforeground process, it calculates the checksum again for the block that isbeing read and compared with the checksum already written in the block ondisk. If both are different then theblock has been corrupted on disk and so the block is not read into memory sothat it prevents cache corruption. There is an overhead associated with this parameter since thechecksum is calculated each time it is read and written. CNOUG博客首页/P2_J%B g'F%A,g

I}T\|0 (4)Events 10210, 10211, 10212 can be set in the INIT.ORA file todetect software corrupt blocks. When there is a corruption in a block, it is not detecteduntil the block is being updated. So any SELECTs on a corrupted block is executed until it is marked assoftware corrupt. When the events areset in the INIT.ORA, the blocks are checked for integrity by comparing certaindata structures and once there is an inconsistency found, the seq or the sequence of the block is set to 0 in theblock header representing that the block is software corrupt.

+sy5TM@C6c0CNOUG博客首页!FBe7MfeY\

The events can be set as follows:

R}r Va9?A y0z;O S3~0CNOUG博客首页9~`)EO/T6~ h

event= “10210 trace name context forever, level 10” (for data blocks)

sx#fa~ V~0CNOUG博客首页]&ve?%Y"]9c)i

event= “10211 trace name context forever, level 10” (for index blocks)

H h;f)w3] Ef7O0CNOUG博客首页)H5wP~3^!G

event= “10212 trace name context forever, level 10” (for cluster blocks) CNOUG博客首页!Iq%K%X2U:|z5sq

CNOUG博客首页O|5vE-z&S!{

(5)Users receiving ORA-1578 when trying to access an object. The query from DBA_EXTENTS given in pg# 30shows that the error is on a table, cluster or index in the data tablespace,SQL语句如下:

Y.C(},AB.Pm0

n0j(y0m;g4Qo_0 SQL>selectsegment_type, segment_name from sys.dba_extents where file_id =<file_id_from_ora-1578> and <block_id_from_ora-1578> betweenblock_id and (block_id+blocks-1);

swA-uNp?6T-BiK0CNOUG博客首页B @!o_d n

(6)ALERT.LOG shows ORA-1578 or ORA-600s with the first argument in therange of 2000 to 8000

U$O2Nz8bEF_mq0CNOUG博客首页:w N1X)oRF9f

_RSpqZ&x0

4.3.6.1 Tables

CNOUG博客首页4j-f ~I/r `5[V1Vb

Whena data block is corrupted in a table, it should be understood that the data inthe corrupted block is lost. The onlyway to not lose any data from the table is to restore from a valid backup andrecover until a point in time before the corruption occurred.

oI-zD^l,d0

#P jcG%Ll0 datablock 坏块通常意味着数据的丢失,如果要保证没有数据丢失,需要通过有效的备份进行恢复。这块参考1.4节。

`r&Z/sP/x,U'ku0

$v1[:Tds%t(o"r)^0

5W$_s4u-^L|I0

方法一:Event method

CNOUG博客首页 gh!VSv@G

Event10231 can be set to skip corrupted blocks on full table scans in the INIT.ORAfile. The object can be exported aftersetting this event. This is notguaranteed to work for every kind of corruption. CNOUG博客首页4?N4r5ij7S}

CNOUG博客首页*i'Hai!?k(~m

This works only when the block is soft corrupted(逻辑坏块), sequence is set to 0. The event can be set as follows:

?[u:T.k{)J#e0

F {)k(Po:o4p`0 event= “10231 trace name context forever, level 10” CNOUG博客首页oFC%}@

CNOUG博客首页(p6x$J8t+nT[`

对于table上的逻辑坏块,并且sequence 设置为0,可以设置10231 event,当全表扫描时,可以跳过corruption,从而读取数据。

~o3J J8rU0CNOUG博客首页6Q+[L4d @_*V

CNOUG博客首页 RbQ7~ BI/w#q%S3_(}q

CNOUG博客首页KEO(|!S!|"D1I

CNOUG博客首页8xC] `h)\{9mt)gn{

方法二:ROWID method

j(VS-_0a-]~0 Extractthe data that does not belong to the corrupted block using ROWIDs. Every row inevery table in an Oracle database has a ROWID column which is usually not displayedunless SELECTed explicitly.

PY.N-}+bC#yk!]b%}0CNOUG博客首页7OsKe!r,b

通过rowid,我们可以抽取出非corrupted block上的数据。关于ROWID的更多内容,参考我的Blog:CNOUG博客首页N(cV7q3RM3p

CNOUG博客首页gU*f My&a

Oracle Rowid 介绍CNOUG博客首页%U!HkFT

CNOUG博客首页Q/n&v:Z7M$K4a2z\

http://blog.csdn.net/tianlesoftware/article/details/5020718CNOUG博客首页 [5T Ew@6?bu

CNOUG博客首页0{(xx crFJA2Nk

CNOUG博客首页2Q2X4o]2nO.ty

CNOUG博客首页 _;z'`-ES s

(1)通过函数构建ROWIDCNOUG博客首页#L a)GTZ,W*r J#D7T4^

CNOUG博客首页T8il%TU:I

函数参数如下:

k$b{2b*_r F0

b6en$v N'h#xRu@x0function ROWID_CREATE(rowid_type IN number,CNOUG博客首页J.Tgu!N?

!b:g;H_wd0 object_number INnumber,CNOUG博客首页?H'aj!p

!R!T0Z$nQ/upvs9`0 relative_fno IN number,CNOUG博客首页'm7gt a:S K&A ];L

XONDD+epYOp0 block_number IN number,CNOUG博客首页`'b]k-U

CNOUG博客首页 bj z^A(do

row_number IN number)CNOUG博客首页9k1~)N9PR:a(s9o

TCF&e A q|r0 return ROWID;CNOUG博客首页c|:~&n!u

rHuH&PR:f L0

2x a9fD%J e``p0

(B4~M5eP5qZ(w0 -- rowid_type - type(restricted=0/extended=1)CNOUG博客首页_3q Jp/L

[ L8jO~:]0 -- object_number - data objectnumber

G+?+a5Sg{|3O0

"~*B#c Gl?pn }0 -- relative_fno - relative filenumber

o(] L]X*}d0CNOUG博客首页)fV!t5DAs

-- block_number - block numberin this fileCNOUG博客首页uR2O?1el

yg"~2rE_+U{g |0 -- row_number - row number inthis blockCNOUG博客首页%Z:ah%qIJR

CNOUG博客首页OP&LL;^/E

CNOUG博客首页*[xx)lY{

V]})B i1zm!I7t0这些参数可以通过如下方式获取:CNOUG博客首页t)h`R9b9q~

CNOUG博客首页R3p9{/q-Q A~~FAP

ROWID_TYPE:CNOUG博客首页4S!v%MYU/o

CNOUG博客首页A9v.vH(P'd m:jy*B

Thisis 1 because we are using the extended rowid format.

l|$t~'V3]"~ g9vu?0

_3~7c"vF0 CNOUG博客首页^B/X&\1U6W J;w

CNOUG博客首页3sT3@f#MX(A)u(N-J

RELATIVE_FNO:CNOUG博客首页S8ga4w([

!u y9tjW*yf)F0 Thisshould have been available when you came to this article. It can also be foundfrom the DBA_EXTENTS view given the absolute file number and block number ofthe corrupt block:

JJZf4pZ:Stc0

.\`'^7R6Q[0 SQL>SELECTtablespace_name, relative_fno, segment_type, owner, segment_name, partition_nameFROM dba_extents WHERE file_id = <AFN> AND <BL> between block_id and block_id + blocks-1;CNOUG博客首页/[ nM)`u

CNOUG博客首页g,e2A? Wz/{$m

CNOUG博客首页%}/Ii._ ` b$V|*C

CNOUG博客首页X8{Wj,j#N&mt

OBJECT_NUMBER:CNOUG博客首页 Lu1ip4GO}_

CNOUG博客首页{4mf2Ux,p6u

For a non-partitioned table, select the DATA_OBJECT_ID from DBA_OBJECTS for theproblem table:

0S`[ n \Y?)@\z#a0

1icwA:Bi8Q0

$tN&E`5W+F^ jo0v(^?;~0

2L)JD\$B!p'n0SQL>SELECT data_object_id FROM dba_objectsWHERE object_name = '<TABLE-NAME>' AND wner = '<TABLE-OWNER>' ;CNOUG博客首页xb-eRw&h+L'nf

%Rl"r"j0Mt0

]8Yr4F*BbJk]0

)M ^ MB*E3I$E0Note that a partitionedtable has an object number for each partition.CNOUG博客首页+PD*\b)\M`

CNOUG博客首页!].z7h*i hk

--注意,对于分区表,每个分区有一个对象id:

4^2y8vhBa.OYM0

^+PF9}rC0Select the DATA_OBJECT_ID from DBA_OBJECTSthus:

1k#vA;_d$z~/t0CNOUG博客首页.M;Ws)y{Pm/`6M

SQL>SELECTdata_object_id FROM dba_objects WHERE object_name = '<TABLE-NAME>' ANDowner = '<TABLE-OWNER>' AND subobject_name = '<PARTITION-NAME>' ;

6J(kxF'M_6t^0CNOUG博客首页']5yv6Gxe5z:J0q

相对与普通表,普通表多了一个subojbect_name 条件。CNOUG博客首页5wy L-oO

V!e9mEu{#l0 CNOUG博客首页]:k8|$c%O;y(dG

Y] \].ZX~0BLOCK_NUMBER andROW_NUMBER:CNOUG博客首页9a:cV'wGIw

CNOUG博客首页!f7{O'I9K y

Theblock number of the corrupt block should be available before you came to thisarticle. (Eg: It is reported in an ORA-1578 error, or as a Page Number byDBVerify).

z*n1Qs0oz*Xsm0CNOUG博客首页X,[|v{)nsDB%z"J

Fora ROWID range scan we generally want to select all rows BEFORE the corruptblock, then all rows AFTER the corrupt block. The first row in a block is rowzero (0) and so we want all rowids LESS THAN "Block <BL> row 0"and then GREATER THAN OR EQUAL TO "Block <BL>+1 row 0".CNOUG博客首页ti)a[u

CNOUG博客首页0M$U2Y|&Ky

?*i7ny9mF] H"L0

0QTJ EWJ~0(2)创建ROWIDCNOUG博客首页"] p:h0xRV

CNOUG博客首页(^9zWe}p-v9D

You can now create the rowid strings to use in a predicate thus:CNOUG博客首页vr B/Oz I|.XO

O%wkw Iikn0现在可以创建rowid:

y1fJ/~I0|0

y&VD)PA$R#V:ZH0 CNOUG博客首页 @qL0d s M!M}

'A&~-c xuk,A0The "LOW_RID"is the lowest rowid INSIDE the corrupt block:CNOUG博客首页;QX2wj J,?+P gw

1`6` V N/U)[0SQL>SELECT dbms_rowid.rowid_create(1,<DATA_OBJECT_ID>,<RFN>,<BL>,0)LOW_RID from DUAL;CNOUG博客首页)p'].WJL{

-r A$[Ds`(L9Z|%c0

!w/@p{ug0CNOUG博客首页s%Z4Zo;P!Z

The "HI_RID" isthe first rowid AFTER the corrupt block:CNOUG博客首页/t3S UW;KSFj T

CNOUG博客首页f:c:?/Te2L5?/I}

SQL>SELECT dbms_rowid.rowid_create(1,<DATA_OBJECT_ID>,<RFN>,<BL>+1,0)HI_RID from DUAL;

{ d]+?jd!o8H#t!zz*n0

Ku HS;[/ui,@N0 CNOUG博客首页'w[8o3q:e1oS+T

CNOUG博客首页 f6Pq9fN"i\

(3)重建数据CNOUG博客首页*YYU:Go Q

CNOUG博客首页F'h*y|oq}1FU

Itis now possible to use CREATE TABLE AS SELECT or INSERT ... SELECT to get datawithout accessing the corrupt block using a query of the form.:

qzE;~x9yk0CNOUG博客首页 mA)o3t:h$nEt

根据刚才查询的rowid,跳过corrupt block来进行createtable 或者insert 操作:CNOUG博客首页+A:E p4N!f@XM9{

CNOUG博客首页2e0C7Y"L[ w.T

SQL>CREATE TABLE salvage_table AS SELECT/*+ ROWID(A) */ * FROM <owner.tablename> A WHERE rowid <'<low_rid>' ;

$e;Bt;b;C g,u$Q _#U0CNOUG博客首页 y)g/w;G6g @#j8c!Q}

SQL>INSERT INTO salvage_table SELECT /*+ROWID(A) */ * FROM <owner.tablename> A WHERE rowid >='<hi_rid>';

6Ay*["K1[+p'\8qE0

1`:j1@ BbLc@@0注意hint里的A是表的别名。CNOUG博客首页R-pmp}U8_H

CNOUG博客首页5T#|]2L7q1Jpj

:\ pL gv0CNOUG博客首页8F8C(wV _@G:J$^F

Fora table partition then only the problem partition need be selected from byusing the PARTITION(xxx) option in the FROM clause:CNOUG博客首页6W JB]j$@

k8|7Gpw8f pv0 对于分区表,仅需要对问题分区进行处理:

o7JqRm0

j s!o;[N%W0Z(B;p0

!y2F3i9A0FB0CNOUG博客首页*[;J4U+?"X?1HOLa

SQL>CREATE TABLE salvage_table AS SELECT/*+ ROWID(A) */ * FROM <owner.tablename> PARTITION(<partition_name>) A WHERE rowid < '<lo_rid>';CNOUG博客首页ac+z5M\/jx3sYy

#t f#j#V!CQ p0SQL>INSERT INTO salvage_table SELECT /*+ROWID(A) */ * FROM <owner.tablename> PARTITION (<partition_name>) AWHERE rowid >= '<hi_rid>';

$zu4P? yW0CNOUG博客首页I U$MI7D_U d

注意: 采用上面这种rowid的方法,不能处理含有LONG字段的表,对于LONG字段的表,只能使用带有where 条件的export/import.

;p0q/BX)E2oZ;|0CNOUG博客首页!V+B`,XR0xhSu

"b|!dv1Y6]'gI0

'{(E-D7bzLiB0 If the corrupt block is the table segment header, this method won't work. You stillhave the option of using any indexes on the corrupt table to extract the data.

Ys'C8vJ0

h$Z \csw0 如果是块头出现corrupt,那么这个方法不使用。 当块头出现问题,整个块的data 都不可读取。 如果是非块头,我们可以使用这种方法挽回更多的数据。CNOUG博客首页cCg'S sv

YD/B|(a*F)D0

ha{}6F L1P7`g0

Ye*X3RL/xP0 Use the following query to determine if the affected block is thesegment header :CNOUG博客首页"{?MD1~:oyI.x

CNOUG博客首页jn0`o+?[]

可以使用如下SQL判断是否是块头block:

Rl/iXO0

#P#K.Xv"Z e0SQL>selectfile_id,block_id,blocks,extent_id from dba_extents where wner='<owner>'and segment_name='<table_name>' and segment_type='TABLE' order by extent_id;

/j jW[?3xgJ`m0CNOUG博客首页2|-nM|[[/BQ+o }

$M$?dQ,D%Y5G0

U/ftiI-Q0FILE_ID BLOCK_ID BLOCKS EXTENT_IDCNOUG博客首页f(Wf1f~.O

!D:b,_7LI(?(Xx0--------- --------- --------- ---------CNOUG博客首页M$bf:g7} q

#F"F!M#n:Khx T08 94854 20780 0 <- EXTENT_IDZERO is segment headerCNOUG博客首页T?4G [y"X

j9~%{#k"j%^0 CNOUG博客首页OB_ |8u6f

方法三: Index method

CNOUG博客首页xS9SdO2gw(`

If there are any indexes on the corrupt table then it is possible to get someinformation about what data was in the corrupt block from the index. Thisrequires selecting indexed columns from the table for rowids in the corruptblock. We already know the ROWID range covered by the corrupt block from theSELECT dbms_rowid.rowid_create ... statements above.

]:K s!`s5b9a*mWI0CNOUG博客首页x,a ? l%HFU

To extract the column data use one of the following forms of select statement:

1F}Sp!|Pw0

6J1`Y KWO*~ Z8^d0 CNOUG博客首页[` V3A4o w;mv&H+~

(NI3T$u1tW0If the columns requiredat NOT NULLable you can use a fast full scan:CNOUG博客首页Au[Oa(v0t

CNOUG博客首页0a VH6c0{qg

如果列是非空的,可是使用fast full scan:

qcG1d-r.hK,t0CNOUG博客首页F0z0s9UO*Xld1e

SQL>SELECT/*+ INDEX_FFS(X <index_name>) */ <index_column1>,<index_column2> ... FROM<tablename> X WHERE rowid >= '<low_rid>' AND rowid < '<hi_rid>' ;

+T9}&F^ oRO+c0CNOUG博客首页#QV[c;^ a

CNOUG博客首页 u6Ab U%b}W#XH3FpH

CNOUG博客首页_5ALO l

If the columns required are NULLable thenyou cannot use an index fast full scan and must use a range scan. This requiresyou to know a minimum possible value for the leading index column to ensure youenable the index scan:CNOUG博客首页#AV!TEsJ7G

CNOUG博客首页 O/[h&?D l

如果列是可以null的,那么必须使用range scan:

xW3uu_"c;|0CNOUG博客首页3g]~7h A&p

SQL>SELECT /*+ INDEX(X<index_name>) */ <index_column1>, <index_column2> ... FROM <tablename> X WHERE row

TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

Open Toolbar