暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

使用BBED模拟和修复坏块

原创 Eygle 2019-07-24
1074

其实在模拟坏块的过程中,更好的工具是BBED,利用BBED可以查看或更改数据块的内容,甚至是修复数据块的损坏。以下是一个简单的示范,首先创建测试表:

SQL> create table bbed tablespace users as select * from dba_tables;
Table created.
SQL> select count(*) from bbed;
  COUNT(*)
----------
       523
SQL> select segment_name,file_id,block_id from dba_extents where segment_name='BBED';
SEGMENT_NA    FILE_ID   BLOCK_ID
---------- ---------- ----------
BBED                3          9
BBED                3         17
BBED                3         25

类似前面介绍创建BBED参数文件等

[oracle@jumper conner]$ more filelist.txt
         1 /opt/oracle/oradata/conner/system01.dbf   440401920
         2 /opt/oracle/oradata/conner/undotbs01.dbf  104857600
         3 /opt/oracle/oradata/conner/users01.dbf     27262976
[oracle@jumper conner]$ more par.bbd
blocksize=8192
listfile=filelist.txt
mode=edit

接下来就可以使用BBED来打开数据文件,使用modify命令进行相应的数据块内容更改:

[oracle@jumper conner]$ bbed parfile=par.bbd
Password:
BBED: Release 2.0.0.0.0 - Limited Production on Sun Sep 11 20:01:01 2005
Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
 
************* !!! For Oracle Internal Use only !!! ***************
BBED> set file 3
        FILE#           3
BBED> modify 1000 file 3 block 17
 File: /opt/oracle/oradata/conner/users01.dbf (3)
 Block: 17               Offsets: 1000 to 1511           Dba:0x00c00011
------------------------------------------------------------------------
 03e80000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
 00000000 00000000 002c002f 03535953 18415050 4c59245f 434f4e46 5f48444c
 525f434f 4c554d4e 53065359 5354454d ffff02c1 0b02c129 02c10203 c2033804
 c3073825 ff02c102 06c51630 31252eff 02c10202 c1020359 4553014e ffffffff
 ffffffff 0a202020 20202020 2020310a 20202020 20202020 20310520 2020204e
 07454e41 424c4544 ffff024e 4fff014e 014e024e 4f074445 4641554c 54084449
 
 <32 bytes per line>

使用verify命令,可以发现刚才修改的file 3 block 17已经被标记为损坏(有时候这样的修改不一定能够损坏一个数据块,通过CORRUPT命令可以直接将一个数据块标记为损坏)。

BBED> verify
DBVERIFY - Verification starting
FILE = /opt/oracle/oradata/conner/users01.dbf
BLOCK = 17
 
Block 17 is corrupt
***
Corrupt block relative dba: 0x00c00011 (file 0, block 17)
Bad check value found during verification
Data in bad block -
 type: 6 format: 2 rdba: 0x00c00011
 last change scn: 0x0000.20a3b575 seq: 0x1 flg: 0x04
 consistency value in tail: 0xb5750601
 check value in block header: 0x3006, computed block checksum: 0xe803
 spare1: 0x0, spare2: 0x0, spare3: 0x0
***

重新启动数据库以后,执行全表扫描,此时错误出现:

SQL> select count(*) from bbed;
select count(*) from bbed
                     *
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 3, block # 17)
ORA-01110: data file 3: '/opt/oracle/oradata/conner/users01.dbf'

这就模拟了数据块的损坏,以上方法仅供测试使用,切记不可用于重要环境。BBED不仅可以破坏数据块,当然还可以修复数据块,上面的测试,由于事先备份了相关的数据文件,下面就可以通过BBED的COPY命令来恢复损坏的数据块。首先需要将备份文件加入BBED文集列表,然后打开该文件,通过copy命令在两个文件之间进行数据块的复制恢复:

BBED> set file 4
        FILE#           4
BBED> copy file 4 block 17 to file 3 block 17;
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) Y
 File: /opt/oracle/oradata/conner/users01.dbf (3)
 Block: 17               Offsets:    0 to  511           Dba:0x00c00011
------------------------------------------------------------------------
 06020000 1100c000 75b5a320 00000104 06300000 01000000 611e0000 72b5a320
 00000000 03003201 0900c000 ffff0000 00000000 00000000 00000000 00800000
 72b5a320 00000000 00000000 00000000 00000000 00000000 00000000 00000000
 <32 bytes per line>
BBED> verify
DBVERIFY - Verification starting
FILE = /opt/oracle/oradata/conner/users01.dbf
BLOCK = 17
 
DBVERIFY - Verification complete

善用BBED可以从很多棘手的问题中拯救我们的数据库,但是由于其使用较为不便,所以不推荐使用。


「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论