Oracle技术之通过bbed模拟和修复corrupted block

使用bbed需要注意:


1、win下oracle不提供


2、随oracle软件一起发布


3、在unix/linux下使用时需要事先relink


4、oracle最初使用bbed用来修复坏block,从9i开始可以通过rman的blockrecover来恢复,不过前提是事先做过备份




[oracle@xys oracle]$ bbed

Password:


BBED: Release 2.0.0.0.0 - Limited Production on Tue Jun 9 13:13:04 2009


Copyright (c) 1982, 2005, Oracle. All rights reserved.


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


BBED> help all;

SET DBA [ dba | file#, block# ]

SET FILENAME 'filename'

SET FILE file#

SET BLOCK [+/-]block#

SET OFFSET [ [+/-]byte offset | symbol | *symbol ]

SET BLOCKSIZE bytes

SET LIST[FILE] 'filename'

SET WIDTH character_count

SET COUNT bytes_to_display

SET IBASE [ HEX | OCT | DEC ]

SET OBASE [ HEX | OCT | DEC ]

SET MODE [ BROWSE | EDIT ]

SET SPOOL [ Y | N ]

SHOW [ <SET parameter> | ALL ]

INFO

MAP[/v] [ DBA | FILENAME | FILE | BLOCK ]

DUMP[/v] [ DBA | FILENAME | FILE | BLOCK | OFFSET | COUNT ]

PRINT[/x|d|u|o|c] [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]

EXAMINE[/Nuf] [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]

</Nuf>:

N - a number which specifies a repeat count.

u - a letter which specifies a unit size:

b - b1, ub1 (byte)

h - b2, ub2 (half-word)

w - b4, ub4(word)

r - Oracle table/index row

f - a letter which specifies a display format:

x - hexadecimal

d - decimal

u - unsigned decimal

o - octal

c - character (native)

n - Oracle number

t - Oracle date

i - Oracle rowid

FIND[/x|d|u|o|c] numeric/character string [ TOP | CURR ]

COPY [ DBA | FILE | FILENAME | BLOCK ] TO [ DBA | FILE | FILENAME | BLOCK ]

MODIFY[/x|d|u|o|c] numeric/character string

[ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]

ASSIGN[/x|d|u|o] <target spec>=<source spec>

<target spec> : [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]

<source spec> : [ value | <target spec options> ]

SUM [ DBA | FILE | FILENAME | BLOCK ] [ APPLY ]

PUSH [ DBA | FILE | FILENAME | BLOCK | OFFSET ]

POP [ALL]

REVERT [ DBA | FILE | FILENAME | BLOCK ]

UNDO

HELP [ <bbed command> | ALL ]

VERIFY [ DBA | FILE | FILENAME | BLOCK ]

CORRUPT [ DBA | FILE | FILENAME | BLOCK ]


BBED>

--======================================

SQL> create table tt(id int ,name varchar2(10)) tablespace trans;


表已创建。


SQL> insert into tt values(1,'a');


已创建 1 行。


SQL> commit;


提交完成。


SQL> select dbms_rowid.rowid_relative_fno(rowid) fno,dbms_rowid.rowid_block_numb

er(rowid) bno ,tt.* from tt;


FNO BNO ID NAME

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

5 15 1 a

SQL> select tablespace_name,file_id,file_name from dba_data_files;


TABLESPACE_NAME FILE_ID FILE_NAME

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

SYSTEM 1 /dev/raw/raw1

UNDOTBS1 2 /dev/raw/raw3

SYSAUX 3 /dev/raw/raw2

USERS 4 /dev/raw/raw6

TRANS 5 /dev/raw/raw14


SQL>

--============================================

BBED> dump file 5 block 15;

File: /dev/raw/raw14 (5)

Block: 15 Offsets: 0 to 8191 Dba:0x0140000f

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

06a20000 0f004001 a7a91000 00000306 91370000 01000000 302b0000 a2a91000

00000000 02003200 09004001 07002c00 bc000000 c2008000 58000c00 01200000

a7a91000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

00000000 00010100 ffff1400 901f7b1f 7b1f0000 0100901f 00000000 00000000

......省略无关信息

00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

00000000 00000000 00000000 00000000 00000000 2c010202 c1020161 0306a7a9


<32 bytes per line>


BBED> find /x 61 curr

File: /dev/raw/raw14 (5)

Block: 15 Offsets: 8187 to 8191 Dba:0x0140000f

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

610306a7 a9


<32 bytes per line>


BBED> sum;

Check value for File 5, Block 15:

current = 0x3791, required = 0x3791


BBED> help modify

MODIFY[/x|d|u|o|c] numeric/character string

[ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]


BBED> modify /x 62 file 5 block 15 offset 8187;

File: /dev/raw/raw14 (5)

Block: 15 Offsets: 8187 to 8191 Dba:0x0140000f

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

620306a7 a9


<32 bytes per line>


BBED> find /x 62 curr;

File: /dev/raw/raw14 (5)

Block: 15 Offsets: 8187 to 8191 Dba:0x0140000f

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

620306a7 a9


<32 bytes per line>

--=================================

SQL> select * from tt;


ID NAME

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

1 a

SQL> alter system flush buffer_cache;


系统已更改。

SQL> alter session set nls_language=american;


Session altered.


SQL> select * from tt;

select * from tt

*

ERROR at line 1:

ORA-01578: ORACLE data block corrupted (file # 5, block # 15)

ORA-01110: data file 5: '/dev/raw/raw14'



SQL>

--=================================

BBED> verify;

DBVERIFY - Verification starting

FILE = /dev/raw/raw14

BLOCK = 15


Block 15 is corrupt

Corrupt block relative dba: 0x0140000f (file 0, block 15)

Bad check value found during verification

Data in bad block:

type: 6 format: 2 rdba: 0x0140000f

last change scn: 0x0000.0010a9a7 seq: 0x3 flg: 0x06

spare1: 0x0 spare2: 0x0 spare3: 0x0

consistency value in tail: 0xa9a70603

check value in block header: 0x3791

computed block checksum: 0x300



DBVERIFY - Verification complete


Total Blocks Examined : 1

Total Blocks Processed (Data) : 0

Total Blocks Failing (Data) : 0

Total Blocks Processed (Index): 0

Total Blocks Failing (Index): 0

Total Blocks Empty : 0

Total Blocks Marked Corrupt : 1

Total Blocks Influx : 0


BBED> sum;

Check value for File 5, Block 15:

current = 0x3791, required = 0x3491

--我们发现current和required相差0x300,这个差正好是

上面verify结果显示的computed block checksum: 0x300


BBED> dump file 5 block 15;

File: /dev/raw/raw14 (5)

Block: 15 Offsets: 0 to 8191 Dba:0x0140000f

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

06a20000 0f004001 a7a91000 00000306 91370000 01000000 302b0000 a2a91000

00000000 02003200 09004001 07002c00 bc000000 c2008000 58000c00 01200000

a7a91000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

00000000 00010100 ffff1400 901f7b1f 7b1f0000 0100901f 00000000 00000000

......省略无关信息

00000000 00000000 00000000 00000000 00000000 2c010202 c1020162 0306a7a9


<32 bytes per line>


BBED>

修改前block 15的dump信息如下:

06a20000 0f004001 a7a91000 00000306 91370000 01000000 302b0000 a2a91000

00000000 02003200 09004001 07002c00 bc000000 c2008000 58000c00 01200000

a7a91000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

00000000 00010100 ffff1400 901f7b1f 7b1f0000 0100901f 00000000 00000000

......省略无关信息

00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

00000000 00000000 00000000 00000000 00000000 2c010202 c1020161 0306a7a9

对比修改前后的block# 15的dump信息:发现没有任何变化,仅仅是把61改成了62,

结果oracle就标记该block为corruption,oracle判断block corruption的依据是啥?

--===============================

--利用undo命令撤销了修改

BBED> sum;

Check value for File 5, Block 15:

current = 0x3791, required = 0x3491


BBED> undo;

BBED> modify /x 61 filename '/dev/raw/raw14' block 15. offset 8187.

File: /dev/raw/raw14 (5)

Block: 15 Offsets: 8187 to 8191 Dba:0x0140000f

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

610306a7 a9


<32 bytes per line>



BBED> sum;

Check value for File 5, Block 15:

current = 0x3791, required = 0x3791


BBED> verify;

DBVERIFY - Verification starting

FILE = /dev/raw/raw14

BLOCK = 15



DBVERIFY - Verification complete


Total Blocks Examined : 1

Total Blocks Processed (Data) : 1

Total Blocks Failing (Data) : 0

Total Blocks Processed (Index): 0

Total Blocks Failing (Index): 0

Total Blocks Empty : 0

Total Blocks Marked Corrupt : 0

Total Blocks Influx : 0


BBED>

--=================================

--再次修改使用sum修复block

BBED> help find

FIND[/x|d|u|o|c] numeric/character string [ TOP | CURR ]


BBED> find /x 61 curr

File: /dev/raw/raw14 (5)

Block: 15 Offsets: 8187 to 8191 Dba:0x0140000f

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

610306a7 a9


<32 bytes per line>


BBED> modify /x 62 file 5 block offset 8187;

BBED-00202: invalid parameter (offset)



BBED> modify /x 62 file 5 block 15 offset 8187;

File: /dev/raw/raw14 (5)

Block: 15 Offsets: 8187 to 8191 Dba:0x0140000f

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

620306a7 a9


<32 bytes per line>


BBED> modify /x 63 file 5 block 15 offset 8187;

File: /dev/raw/raw14 (5)

Block: 15 Offsets: 8187 to 8191 Dba:0x0140000f

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

630306a7 a9


<32 bytes per line>


BBED> undo --undo只能撤销本次操作

BBED> modify /x 62 filename '/dev/raw/raw14' block 15. offset 8187.

File: /dev/raw/raw14 (5)

Block: 15 Offsets: 8187 to 8191 Dba:0x0140000f

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

620306a7 a9


<32 bytes per line>



BBED> help revert;

REVERT [ DBA | FILE | FILENAME | BLOCK ]


BBED> revert; --撤销该session内的所有操作

All changes made in this session will be rolled back. Proceed? (Y/N) N

Revert cancelled.


BBED> sum;

Check value for File 5, Block 15:

current = 0x3791, required = 0x3491


BBED> help sum;

SUM [ DBA | FILE | FILENAME | BLOCK ] [ APPLY ]


BBED> sum file 5 block 15 apply; --通过apply修复corrupted block

Check value for File 5, Block 15:

current = 0x3491, required = 0x3491


BBED> verify;

DBVERIFY - Verification starting

FILE = /dev/raw/raw14

BLOCK = 15



DBVERIFY - Verification complete


Total Blocks Examined : 1

Total Blocks Processed (Data) : 1

Total Blocks Failing (Data) : 0

Total Blocks Processed (Index): 0

Total Blocks Failing (Index): 0

Total Blocks Empty : 0

Total Blocks Marked Corrupt : 0

Total Blocks Influx : 0


BBED>


--============================


SQL> select *from tt;

select *from tt

*

ERROR at line 1:

ORA-03113: 通信通道的文件结束



SQL> exit

Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Pr

oduction

With the Partitioning, OLAP and Data Mining options


C:>sqlplus xys/manager@linux


SQL*Plus: Release 10.2.0.1.0 - Production on 星期二 6月 9 14:09:48 2009


Copyright (c) 1982, 2005, Oracle. All rights reserved.



连接到:

Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options


SQL> select *from tt;


ID NAME

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

1 b


SQL>


oracle视频教程请关注:http://u.youku.com/user_video/id_UMzAzMjkxMjE2.html


你可能感兴趣的:(oracle,block,bbed,修复corrupted)