oracle10g关于数据库坏块的修复
一:创建测试用表
SQL> create table jiujian(des varchar(30)) tablespace zx;

Table created.

SQL> insert into jiujian values('zhangxu love oracle');                  

1 row created.

查询该表所在的块
SQL> select rowid,
  2        dbms_rowid.rowid_relative_fno(rowid) rel_fno,
  3        dbms_rowid.rowid_block_number(rowid) blockno,
  4        dbms_rowid.rowid_row_number(rowid) rowno
  5        from jiujian;

ROWID                 REL_FNO    BLOCKNO      ROWNO
------------------ ---------- ---------- ----------
AAAMmMAAFAAAAAkAAA          5         36          0

二 bbed构造坏块
1 bbed要加载的文件列表
[oracle@oracle ~]$ cat filelist
1 /oracle/CRM2/CRM/system01.dbf 503316480
2 /oracle/CRM2/CRM/undotbs01.dbf 26214400
3 /oracle/CRM2/CRM/sysaux01.dbf 251658240
4 /oracle/CRM2/CRM/users01.dbf 5242880
5 /oracle/CRM2/CRM/zx1.dbf
2 bbed的参数选项配置如下
[oracle@oracle ~]$ cat bbed.para
blocksize=8192
mode=edit
listfile=/oracle/filelist

3 运行bbed
[oracle@oracle ~]$ bbed parfile=bbed.para
Password: blockedit

BBED: Release 2.0.0.0.0 - Limited Production on Tue Sep 25 18:39:16 2012

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

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

4 查看配置
BBED> show
        FILE#           1
        BLOCK#          1
        OFFSET          0
        DBA             0x00400001 (4194305 1,1)
        FILENAME        /oracle/CRM2/CRM/system01.dbf
        BIFILE          bifile.bbd
        LISTFILE        /oracle/filelist
        BLOCKSIZE       8192
        MODE            Edit
        EDIT            Unrecoverable
        IBASE           Dec
        OBASE           Dec
        WIDTH           80
        COUNT           512
        LOGFILE         log.bbd
        SPOOL           No
5 查看bbed可处理的数据文件
BBED> info
 File#  Name                                                        Size(blks)
 -----  ----                                                        ----------
     1  /oracle/CRM2/CRM/system01.dbf                                    61440
     2  /oracle/CRM2/CRM/undotbs01.dbf                                    3200
     3  /oracle/CRM2/CRM/sysaux01.dbf                                    30720
     4  /oracle/CRM2/CRM/users01.dbf                                       640
     5  /oracle/CRM2/CRM/zx1.dbf                                             0
6 设置当前数据文件号和当前数据块
BBED> set dba 5,36
        DBA             0x01400024 (20971556 5,36)
  
7 确认下配置是否正确
BBED> show
        FILE#           5
        BLOCK#          36
        OFFSET          0
        DBA             0x01400024 (20971556 5,36)
        FILENAME        /oracle/CRM2/CRM/zx1.dbf
        BIFILE          bifile.bbd
        LISTFILE        /oracle/filelist
        BLOCKSIZE       8192
        MODE            Edit
        EDIT            Unrecoverable
        IBASE           Dec
        OBASE           Dec
        WIDTH           80
        COUNT           512
        LOGFILE         log.bbd
        SPOOL           No
8 查找字符zhangxu的位置
BBED> find /c zhangxu TOP
 File: /oracle/CRM2/CRM/zx1.dbf (5)
 Block: 36               Offsets: 8169 to 8191           Dba:0x01400024
------------------------------------------------------------------------
 7a68616e 67787520 6c6f7665 206f7261 636c6502 061dc6

 <32 bytes per line>
9 设置当前偏移量
BBED> set offset 8169
        OFFSET          8169
10 从当前偏移量开始显示数据块内容
BBED> dump /v
 File: /oracle/CRM2/CRM/zx1.dbf (5)
 Block: 36      Offsets: 8169 to 8191  Dba:0x01400024
-------------------------------------------------------
 7a68616e 67787520 6c6f7665 206f7261 l zhangxu love ora
 636c6502 061dc6                     l cle...?

 <16 bytes per line>
11 用字符jiujian开始从当前偏移量位置进行替换
BBED> modify /c jiujian
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
 File: /oracle/CRM2/CRM/zx1.dbf (5)
 Block: 36               Offsets: 8169 to 8191           Dba:0x01400024
------------------------------------------------------------------------
 6a69756a 69616e20 6c6f7665 206f7261 636c6502 061dc6

 <32 bytes per line>
12 查看替换后的数据块内容
BBED> dump /v
 File: /oracle/CRM2/CRM/zx1.dbf (5)
 Block: 36      Offsets: 8169 to 8191  Dba:0x01400024
-------------------------------------------------------
 6a69756a 69616e20 6c6f7665 206f7261 l jiujian love ora
 636c6502 061dc6                     l cle...?

 <16 bytes per line>
 
三 对坏块就行修复
1 offline,online 改表空间便可看到坏块的效果
SQL> alter tablespace zx offline;

Tablespace altered.

SQL> alter tablespace zx online;

Tablespace altered.

SQL> select * from jiujian;
select * from jiujian
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 5, block # 36)
ORA-01110: data file 5: '/oracle/CRM2/CRM/zx1.dbf'

SQL> select * from v$database_block_corruption;

     FILE#     BLOCK#     BLOCKS CORRUPTION_CHANGE# CORRUPTIO
---------- ---------- ---------- ------------------ ---------
         5         28          1                  0 CHECKSUM
2 运行blockrecover datafile 5 block 36; 修复该数据块
RMAN> blockrecover datafile 5 block 36;

Starting blockrecover at 25-SEP-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=154 devtype=DISK

channel ORA_DISK_1: restoring block(s)
channel ORA_DISK_1: specifying block(s) to restore from backup set
restoring blocks of datafile 00005
channel ORA_DISK_1: reading from backup piece /backup/05nkkvst_1_1
channel ORA_DISK_1: restored block(s) from backup piece 1
piece handle=/backup/05nkkvst_1_1 tag=TAG20120908T000444
channel ORA_DISK_1: block restore complete, elapsed time: 00:00:04

starting media recovery
media recovery complete, elapsed time: 00:00:03

Finished blockrecover at 25-SEP-12
3 检查数据块的修复过程注意视图v$database_block_corruption变化
[oracle@oracle ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Tue Sep 25 19:02:04 2012

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


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options

SQL> select * from jiujian;

DES
------------------------------
zhangxu love oracle
注意视图v$database_block_corruption 还有坏块的记录!!
SQL> select * from v$database_block_corruption;

     FILE#     BLOCK#     BLOCKS CORRUPTION_CHANGE# CORRUPTIO
---------- ---------- ---------- ------------------ ---------
         5         28          1                  0 CHECKSUM
4 重新验证下数据文件以清除视图v$database_block_corruption关于坏块的记录
RMAN> backup validate datafile 5;

Starting backup at 25-SEP-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=144 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00005 name=/oracle/CRM2/CRM/zx1.dbf
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
Finished backup at 25-SEP-12

SQL> select * from v$database_block_corruption;

no rows selected

四 测试下命令blockrecover corruption list能干啥 (此处已经重新构造了坏块)
RMAN> blockrecover corruption list;

Starting blockrecover at 25-SEP-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=142 devtype=DISK

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished blockrecover at 25-SEP-12
 注意上面的恢复过程没有读取备份片
-------------------------------------------------------------------
2 查询表jiujian 
SQL> select * from jiujian;
select * from jiujian
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 5, block # 36)
ORA-01110: data file 5: '/oracle/CRM2/CRM/zx1.dbf'

3 注意此处,已经清除了 v$database_block_corruption 中关于坏块的记录
SQL> select * from v$database_block_corruption;

总结:看来10g的blockrecover仅仅清除 v$database_block_corruption中关于坏块的记录,并不修复数据块,和11g的recover corruption list 差别大啊。