ORA-01578: ORACLE 数据块损坏 之奇妙处理 DBV

来源:互联网 发布:日本遗孤知乎 编辑:程序博客网 时间:2024/04/30 03:30

下午接到研发人员报告: ORA-01578: ORACLE 数据块损坏

 

根据网上诸多仁兄的处理方案,具体采用下面检查:

 

ORA-01578: ORACLE 数据块损坏 (文件号 6, 块号 20)
ORA-01110: 数据文件 6: 'F:/ORACLE/PRODUCT/10.2.0/ORADATA/MOVO/BLOCK.DBF'
 
 
数据块的损坏与恢复
数据库的恢复有时是件很复杂的事情,轻率的操作和尝试可能导致数据库的永久损坏
 
所以在操作前 一定要做好备份,对于重要的数据,如果自己不能确定恢复步骤
 
和后果的话,可以先向专业人士咨询,以免造成损失
 
 
这里是做模拟数据块的损坏和恢复
 
 
 
1.插入数据
 
C:/Documents and Settings/Administrator>sqlplus / as sysdba
 
SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 6月 12 17:38:46 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
 
SQL> select name from v$datafile;
 
NAME
------------------------------------------------------------------------------
 
F:/ORACLE/PRODUCT/10.2.0/ORADATA/MOVO/SYSTEM01.DBF
F:/ORACLE/PRODUCT/10.2.0/ORADATA/MOVO/UNDOTBS04.DBF
F:/ORACLE/PRODUCT/10.2.0/ORADATA/MOVO/SYSAUX01.DBF
F:/ORACLE/PRODUCT/10.2.0/ORADATA/MOVO/USERS01.DBF
F:/ORACLE/PRODUCT/10.2.0/ORADATA/MOVO/EXAMPLE01.DBF
F:/ORACLE/PRODUCT/10.2.0/ORADATA/MOVO/BLOCK.DBF
 
已选择6行。
 
SQL> drop tablespace block including contents and datafiles;
 
表空间已删除。
 
SQL> create tablespace block
 2 datafile 'F:/ORACLE/PRODUCT/10.2.0/ORADATA/MOVO/block.dbf' size 1m
 3 extent management local;
 
表空间已创建。
 
 
 
SQL> alter user skate default tablespace block;
 
用户已更改。
 
SQL> alter user skate quota unlimited on block;
 
用户已更改。
 
SQL> conn skate/skate
已连接。
SQL> create table t as select * from dba_users;
 
表已创建。
 
SQL> insert into t select * from t;
 
已创建28行。
 
SQL> insert into t select * from t;
 
已创建56行。
 
SQL> insert into t select * from t;
 
已创建112行。
 
SQL> insert into t select * from t;
 
已创建224行。
 
SQL> insert into t select * from t;
 
已创建448行。
 
SQL> insert into t select * from t;
 
已创建896行。
 
SQL> insert into t select * from t;
 
已创建1792行。
 
SQL> insert into t select * from t;
 
已创建3584行。
 
SQL> insert into t select * from t;
insert into t select * from t
*
第 1 行出现错误:
ORA-01653: 表 SKATE.T 无法通过 8 (在表空间 BLOCK 中) 扩展
 
SQL> commit;
 
提交完成。
 
SQL> alter system checkpoint;
 
系统已更改。
 
SQL> select count(*) from t;
 
 COUNT(*)
----------
      7168
 
SQL>
 
SQL> conn /as sysdba
已连接。
SQL> shutdown immediate;
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。
SQL>
 
 
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'
 
 
SQL>
 
 
注意:因为数据块损坏,所以查询该表,将会提示错误
 
 
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)
 
C:/Documents and Settings/Administrator>
 
 
 
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'
导出成功终止, 但出现警告。
 
C:/Documents and Settings/Administrator>
 
 
 
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';  
 
系统已更改。
 
SQL>
 
注意: 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
成功终止导出, 没有出现警告。
 
C:/Documents and Settings/Administrator>
 
 
 
 
这时候数据成功导出.这是我可以drop table,然后recreate这个表,最后在imp数据
 
删除表T:
 
SQL> drop table t;
drop table t
           *
第 1 行出现错误:
ORA-00942: 表或视图不存在
 
 
SQL> drop table skate.t;
 
表已删除。
 
SQL> commit;
 
提交完成。
 
SQL>
 
 
导入数据
 
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>
 
现在这个表可以访问了
 
 
在这个例子中我们损失数据为:
 
 7168-7102=66
数据块损坏前:
 
SQL> select count(*) from t;
 
 COUNT(*)
----------
      7168
 
数据块损坏后:
 
SQL> select count(*) from t;
 
 COUNT(*)
----------
      7102
 
 
 
---end----
 
在确定了具体发生损坏的表名字后,我建议研发按此法则采取部分数据损失的方法处理,临处理前多说了
一句:你用dbv检查一下那个文件看有没有其他损坏: 奇迹出现了,以下是过程:
 
 
C:/Documents and Settings/tydic>dbv file='E:/ORACLE/data/orcl/crm_iba'
DBVERIFY: Release 10.2.0.1.0 - Production on 星期三 1月 14 14:43:15 2009
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
DBVERIFY - 开始验证: FILE = E:/ORACLE/data/orcl/crm_iba
页 45465 标记为损坏
Corrupt block relative dba: 0x0180b199 (file 6, block 45465)
Bad check value found during dbv:
Data in bad block:
 type: 6 format: 2 rdba: 0x0180b199
 last change scn: 0x0888.47eebd08 seq: 0x2 flg: 0x04
 spare1: 0x0 spare2: 0x0 spare3: 0x0
 consistency value in tail: 0xbd080602
 check value in block header: 0x12ea
 computed block checksum: 0x1
页 80522 标记为损坏
Corrupt block relative dba: 0x01813a8a (file 6, block 80522)
Bad check value found during dbv:
Data in bad block:
 type: 32 format: 2 rdba: 0x01813a8a
 last change scn: 0x0888.47ef5331 seq: 0x1 flg: 0x04
 spare1: 0x0 spare2: 0x0 spare3: 0x0
 consistency value in tail: 0x53312001
 check value in block header: 0xc648
 computed block checksum: 0x1
页 134863 标记为损坏
Corrupt block relative dba: 0x01820ecf (file 6, block 134863)
Bad check value found during dbv:
Data in bad block:
 type: 6 format: 2 rdba: 0x01820ecf
 last change scn: 0x0888.47f00992 seq: 0x2 flg: 0x04
 spare1: 0x0 spare2: 0x0 spare3: 0x0
 consistency value in tail: 0x09920602
 check value in block header: 0x9484
 computed block checksum: 0x1000
页 143566 标记为损坏
Corrupt block relative dba: 0x018230ce (file 6, block 143566)
Bad check value found during dbv:
Data in bad block:
 type: 0 format: 2 rdba: 0x000230ce
 last change scn: 0x0000.00000000 seq: 0x1 flg: 0x05
 spare1: 0x0 spare2: 0x0 spare3: 0x0
 consistency value in tail: 0x00000001
 check value in block header: 0x97cc
 computed block checksum: 0x1
页 166652 标记为损坏
Corrupt block relative dba: 0x01828afc (file 6, block 166652)
Bad check value found during dbv:
Data in bad block:
 type: 0 format: 2 rdba: 0x00028afc
 last change scn: 0x0000.00000000 seq: 0x1 flg: 0x05
 spare1: 0x0 spare2: 0x0 spare3: 0x0
 consistency value in tail: 0x00000001
 check value in block header: 0x2dfe
 computed block checksum: 0x1
页 213861 标记为损坏
Corrupt block relative dba: 0x01834365 (file 6, block 213861)
Bad check value found during dbv:
Data in bad block:
 type: 0 format: 2 rdba: 0x00034365
 last change scn: 0x0000.00000000 seq: 0x1 flg: 0x05
 spare1: 0x0 spare2: 0x0 spare3: 0x0
 consistency value in tail: 0x00000001
 check value in block header: 0xe466
 computed block checksum: 0x1
DBVERIFY - 验证完成
检查的页总数: 256000
处理的页总数 (数据): 139041
失败的页总数 (数据): 0
处理的页总数 (索引): 0
失败的页总数 (索引): 0
处理的页总数 (其它): 1350
处理的总页数 (段)  : 0
失败的总页数 (段)  : 0
空的页总数: 115603
标记为损坏的总页数: 6
流入的页总数: 0
最高块 SCN            : 1206913472 (2184.1206913472)
C:/Documents and Settings/tydic>dbv file='E:/ORACLE/data/orcl/crm_iba'
DBVERIFY: Release 10.2.0.1.0 - Production on 星期三 1月 14 14:47:11 2009
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
DBVERIFY - 开始验证: FILE = E:/ORACLE/data/orcl/crm_iba
页 127276 标记为损坏
Corrupt block relative dba: 0x0181f12c (file 6, block 127276)
Bad check value found during dbv:
Data in bad block:
 type: 6 format: 2 rdba: 0x0181f12c
 last change scn: 0x0888.47f008dd seq: 0x2 flg: 0x04
 spare1: 0x0 spare2: 0x0 spare3: 0x0
 consistency value in tail: 0x08dd0602
 check value in block header: 0xedbc
 computed block checksum: 0x1
页 139882 标记为损坏
Corrupt block relative dba: 0x0182226a (file 6, block 139882)
Bad check value found during dbv:
Data in bad block:
 type: 6 format: 2 rdba: 0x0182226a
 last change scn: 0x0888.47f009ab seq: 0x2 flg: 0x04
 spare1: 0x0 spare2: 0x0 spare3: 0x0
 consistency value in tail: 0x09ab0602
 check value in block header: 0x69a0
 computed block checksum: 0x1
页 159164 标记为损坏
Corrupt block relative dba: 0x01826dbc (file 6, block 159164)
Bad check value found during dbv:
Data in bad block:
 type: 0 format: 2 rdba: 0x00026dbc
 last change scn: 0x0000.00000000 seq: 0x1 flg: 0x05
 spare1: 0x0 spare2: 0x0 spare3: 0x0
 consistency value in tail: 0x00000001
 check value in block header: 0xcabe
 computed block checksum: 0x1
页 203628 标记为损坏
Corrupt block relative dba: 0x01831b6c (file 6, block 203628)
Bad check value found during dbv:
Data in bad block:
 type: 0 format: 2 rdba: 0x00031b6c
 last change scn: 0x0000.00000000 seq: 0x1 flg: 0x05
 spare1: 0x0 spare2: 0x0 spare3: 0x0
 consistency value in tail: 0x00000001
 check value in block header: 0xbc6f
 computed block checksum: 0x1
页 244631 标记为损坏
Corrupt block relative dba: 0x0183bb97 (file 6, block 244631)
Bad check value found during dbv:
Data in bad block:
 type: 0 format: 2 rdba: 0x0003bb97
 last change scn: 0x0000.00000000 seq: 0x1 flg: 0x05
 spare1: 0x0 spare2: 0x0 spare3: 0x0
 consistency value in tail: 0x00000001
 check value in block header: 0x1c94
 computed block checksum: 0x1
DBVERIFY - 验证完成
检查的页总数: 256000
处理的页总数 (数据): 139041
失败的页总数 (数据): 0
处理的页总数 (索引): 0
失败的页总数 (索引): 0
处理的页总数 (其它): 1351
处理的总页数 (段)  : 0
失败的总页数 (段)  : 0
空的页总数: 115603
标记为损坏的总页数: 5
流入的页总数: 0
最高块 SCN            : 1206913472 (2184.1206913472)
C:/Documents and Settings/tydic>dbv file='E:/ORACLE/data/orcl/crm_iba'
DBVERIFY: Release 10.2.0.1.0 - Production on 星期三 1月 14 14:57:07 2009
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
DBVERIFY - 开始验证: FILE = E:/ORACLE/data/orcl/crm_iba
页 178109 标记为损坏
Corrupt block relative dba: 0x0182b7bd (file 6, block 178109)
Bad check value found during dbv:
Data in bad block:
 type: 0 format: 2 rdba: 0x0002b7bd
 last change scn: 0x0000.00000000 seq: 0x1 flg: 0x05
 spare1: 0x0 spare2: 0x0 spare3: 0x0
 consistency value in tail: 0x00000001
 check value in block header: 0x10bf
 computed block checksum: 0x1
页 182362 标记为损坏
Corrupt block relative dba: 0x0182c85a (file 6, block 182362)
Bad check value found during dbv:
Data in bad block:
 type: 0 format: 2 rdba: 0x0002c85a
 last change scn: 0x0000.00000000 seq: 0x1 flg: 0x05
 spare1: 0x0 spare2: 0x0 spare3: 0x0
 consistency value in tail: 0x00000001
 check value in block header: 0x6f58
 computed block checksum: 0x1
DBVERIFY - 验证完成
检查的页总数: 256000
处理的页总数 (数据): 139043
失败的页总数 (数据): 0
处理的页总数 (索引): 0
失败的页总数 (索引): 0
处理的页总数 (其它): 1351
处理的总页数 (段)  : 0
失败的总页数 (段)  : 0
空的页总数: 115604
标记为损坏的总页数: 2
流入的页总数: 0
最高块 SCN            : 1206913472 (2184.1206913472)
C:/Documents and Settings/tydic>