处理ora-01578 ora-01110错误
如果没有备份如何修复坏块
(一)模拟坏块
SQL> select file_id,file_name from dba_data_files;
6 /oradata/test.dbf
[oracle@test oradata]$ dd of=/oradata/test.dbf bs=8192 conv=notrunc seek=1244 <<EOF
> crash
> EOF
0+1 records in
0+1 records out
6 bytes (6 B) copied, 2.6e-05 seconds, 231 kB/s
[oracle@test bin]$ ./dbv file=/oradata/test.dbf blocksize=8192
DBVERIFY: Release 10.2.0.5.0 - Production on Wed Mar 2 05:16:08 2016
Copyright (c) 1982, 2007, Oracle. All rights reserved.
DBVERIFY - Verification starting : FILE = /oradata/test.dbf
Page 124 is marked corrupt
Corrupt block relative dba: 0x0180007c (file 6, block 124)
Bad header found during dbv:
Data in bad block:
type: 67 format: 7 rdba: 0x65747075
last change scn: 0x636f.6c622064 seq: 0x6b flg: 0x21
spare1: 0x72 spare2: 0x72 spare3: 0x0
consistency value in tail: 0x92ce0602
check value in block header: 0xf40a
block checksum disabled
DBVERIFY - Verification complete
Total Pages Examined : 1280
Total Pages Processed (Data) : 1126
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing (Index): 0
Total Pages Processed (Other): 34
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 119
Total Pages Marked Corrupt : 1
Total Pages Influx : 0
Highest block SCN : 562020 (0.562020)
已经模拟出坏块
Corrupt block relative dba: 0x018004dc (file 6, block 124)
(二)修复坏块
select tablespace_name,segment_type,owner,segment_name from dba_extents where file_id=6 and 124 between block_id and block_id+blocks - 1;
SQL> select tablespace_name,segment_type,owner,segment_name from dba_extents where file_id=6 and 124 between block_id and block_id+blocks - 1;
TABLESPACE_NAME SEGMENT_TYPE OWNER
------------------------------ ------------------ ------------------------------
SEGMENT_NAME
--------------------------------------------------------------------------------
TEST TABLE SYS
TT1
使用exp 导出
[oracle@test bin]$ exp \"sys/system as sysdba\" file=/oradata/tt1.dmp log=/oradata/tt1log.log tables=tt1
About to export specified tables via Conventional Path ...
. . exporting table TT1
EXP-00056: ORACLE error 1578 encountered
ORA-01578: ORACLE data block corrupted (file # 6, block # 124)
ORA-01110: data file 6: '/oradata/test.dbf'
Export terminated successfully with warnings.
(三)设置导出时跳过坏块
SQL> ALTER SYSTEM SET EVENTS='10231 trace name context forever,level 10' ;
或者
execute dbms_repair.skip_corrupt_blocks('SYS','TT1');
execute dbms_repair.skip_corrupt_blocks('SYS','TT1',flags=>dbms_repair.noskip_flag);
System altered.
导出
[oracle@test bin]$ exp \"sys/system as sysdba\" file=/oradata/tt1.dmp log=/oradata/tt1log.log tables=tt1
Export: Release 10.2.0.5.0 - Production on Wed Mar 2 07:11:08 2016
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses ZHS16GBK character set (possible charset conversion)
About to export specified tables via Conventional Path ...
. . exporting table TT1 49974 rows exported
Export terminated successfully without warnings.
(四) 恢复表
将原来的表rename或者drop
rename的话alter table tt1 rename to newname
然后导入tt1.dmp或者create table tt1 as select * from newname(这种不建议,因为表的约束啥的可能不对,因为你这相当于重新建表只会复制源表的唯一约束)
删除源表
SQL> drop table tt1;
Table dropped.
导入
[oracle@test bin]$ imp \"sys/system as sysdba \" file=/oradata/tt1.dmp log=/oradata/imptt1.log full=y
Import: Release 10.2.0.5.0 - Production on Wed Mar 2 08:01:11 2016
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export file created by EXPORT:V10.02.01 via conventional path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
export client uses US7ASCII character set (possible charset conversion)
. importing SYS's objects into SYS
. importing SYS's objects into SYS
. . importing table "TT1" 49974 rows imported
Import terminated successfully without warnings.
SQL> alter system set events='10231 trace name context off';
恢复检测坏块