1、现场模样
在查询的时候,会报类似如下的错误
ORA-01578: ORACLE data block corrupted (file # 2, block # 235)
ORA-01110: data file 2: '/oracle/oradata/orcl/undotbs01.dbf'
2、模拟现场
关闭数据库后用Ultredit编辑数据文件,随便更改几个字符.然后启动数据库
SQL> startup
ORACLE 例程已经启动。
Total System Global Area 574619648 bytes
Fixed Size 1250212 bytes
Variable Size 180358236 bytes
Database Buffers 385875968 bytes
Redo Buffers 7135232 bytes
数据库装载完毕。
数据库已经打开。
SQL> select count(*) from t;
select count(*) from t
*
第 1 行出现错误:
ORA-00942: 表或视图不存在
SQL> select count(*) from skate.t;
select count(*) from skate.t
*
第 1 行出现错误:
ORA-01578: ORACLE 数据块损坏 (文件号 6, 块号 20)
ORA-01110: 数据文件 6: 'F:\ORACLE\PRODUCT\10.2.0\ORADATA\MOVO\BLOCK.DBF'
注意:因为数据块损坏,所以查询该表,将会提示错误
3、现场检测
使用DBV检查数据文件
C:\Documents and Settings\Administrator>dbv file=F:\oracle\product\10.2.0\oradat
a\movo\BLOCK.DBF blocksize=8192
DBVERIFY: Release 10.2.0.1.0 - Production on 星期四 6月 12 18:12:35 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
DBVERIFY - 开始验证: FILE = F:\oracle\product\10.2.0\oradata\movo\BLOCK.DBF
页 20 标记为损坏
Corrupt block relative dba: 0x01800014 (file 6, block 20)
Bad check value found during dbv:
Data in bad block:
type: 6 format: 2 rdba: 0x01800014
last change scn: 0x0000.0015e13c seq: 0x1 flg: 0x06
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0xe13c0601
check value in block header: 0xf7d7
computed block checksum: 0x7772
DBVERIFY - 验证完成
检查的页总数: 128
处理的页总数 (数据): 109
失败的页总数 (数据): 0
处理的页总数 (索引): 0
失败的页总数 (索引): 0
处理的页总数 (其它): 18
处理的总页数 (段) : 0
失败的总页数 (段) : 0
空的页总数: 0
标记为损坏的总页数: 1
流入的页总数: 0
最高块 SCN : 1433924 (0.1433924)
dbv检测到坏块.
4.寻求恢复
在这种情况下,如果有备份,需要从备份中恢复
如果没有备份,那么坏块部分的数据肯定要丢失了
在这个时候导出是不允许的:
C:\Documents and Settings\Administrator>exp skate/skate@movo file=t.dmp tables=t
Export: Release 10.2.0.1.0 - Production on 星期四 6月 12 18:14:54 2008
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
已导出 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集
即将导出指定的表通过常规路径...
. . 正在导出表 T
EXP-00056: 遇到 ORACLE 错误 1578
ORA-01578: ORACLE 数据块损坏 (文件号 6, 块号 20)
ORA-01110: 数据文件 6: 'F:\ORACLE\PRODUCT\10.2.0\ORADATA\MOVO\BLOCK.DBF'
导出成功终止, 但出现警告。
5.解救方法
当然,对于不同的情况需要区别对待
首先你需要检查损坏的对象,使用以下SQL:
SQL> select tablespace_name,segment_type,owner,segment_name from dba_extents
2 where file_id=6 and 20 between block_id and block_id+blocks-1
3 ;
TABLESPACE_NAME SEGMENT_TYPE OWNER
------------------------------ ------------------ ------------------------------
SEGMENT_NAME
--------------------------------------------------------------------------------
BLOCK TABLE SKATE
T
SQL>
如果损失的是数据,ok
我们可以设置内部事件,使exp跳过这些损坏的block
SQL> alter system set events='10231 trace name context forever,level 10';
系统已更改。
注意: 10231 内部事件,设置在全表扫描时跳过损坏的数据块.
然后我们可以导出未损坏的数据:
C:\Documents and Settings\Administrator>exp skate/skate@movo file=t.dmp tables=t
Export: Release 10.2.0.1.0 - Production on 星期四 6月 12 18:22:49 2008
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
已导出 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集
即将导出指定的表通过常规路径...
. . 正在导出表 T导出了 7102 行
成功终止导出, 没有出现警告。
这时候数据成功导出.这是我可以drop table,然后recreate这个表,最后在imp数据
删除表T:
SQL> drop table skate.t;
表已删除。
SQL> commit;
提交完成。
导入数据
C:\Documents and Settings\Administrator>imp skate/skate@movo file=t.dmp tables=t
Import: Release 10.2.0.1.0 - Production on 星期四 6月 12 18:29:36 2008
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
经由常规路径由 EXPORT:V10.02.01 创建的导出文件
已经完成 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集中的导入
. 正在将 SKATE 的对象导入到 SKATE
. 正在将 SKATE 的对象导入到 SKATE
. . 正在导入表 "T"导入了 7102 行
成功终止导入, 没有出现警告。
C:\Documents and Settings\Administrator>
SQL> select count(*) from skate.t;
COUNT(*)
----------
7102
SQL>
现在这个表可以访问了
–成功导出后记得要关闭10231内部事件
alter system set events='10231 trace name context off';
在这个例子中我们损失数据为:
7168-7102=66
数据块损坏前:
SQL> select count(*) from t;
COUNT(*)
----------
7168
数据块损坏后:
SQL> select count(*) from t;
COUNT(*)
----------
7102
内容转自http://blog.itpub.net/28600568/viewspace-1612783/