3、场景模拟出来了,下面是修复过程
使用BBED,将文件头的SCN等关键信息修改到与控制文件control file相匹配即可
SYS@linuxidc SQL>select file#, CHECKPOINT_CHANGE# from v$datafile;
FILE# CHECKPOINT_CHANGE#
---------- ------------------
1 1233692
2 1233692
3 1233692
4 1233692
5 1233692
SYS@linuxidc SQL>select CHECKPOINT_CHANGE# from v$database;
CHECKPOINT_CHANGE#
------------------
1233692
SYS@linuxidc SQL>select file#, recover, fuzzy, CHECKPOINT_CHANGE# from v$datafile_header;
FILE# REC FUZ CHECKPOINT_CHANGE#
---------- --- --- ------------------
1 NO NO 1233692
2 NO NO 1233692
3 NO NO 1233692
4 NO NO 1233692
5 YES NO 1233063
控制文件中datafile5的scn是:1233692,而数据文件头中的scn是:1233063
使用bbed将datafile5的数据文件头对应的SCN修改为与其他文件相同,我们先看一下users01.dbf这个文件的文件头
BBED> set filename '/dbdata/oradata/linuxidc/users01.dbf'
FILENAME /dbdata/oradata/linuxidc/users01.dbf
BBED> set block 1
BLOCK# 1
BBED> map
File: /dbdata/oradata/linuxidc/users01.dbf (0)
Block: 1 Dba:0x00000000
------------------------------------------------------------
Data File Header
struct kcvfh, 860 bytes @0
ub4 tailchk @8188
因为我们要修改数据文件头,因此我们需要关注四个偏移量offset点,分别为484、492、140和148
1、datafile 的file header 存储在第一个block里
2、Oracle considers four attributes of this data structure when determining if a datafile is sync with the other data files of the database:(不同oracle版本offset可能不同)
(1)kscnbas (at offset 484) – SCN of last change to the datafile.
(2)kcvcptim (at offset 492) -Time of the last change to the datafile.
(3)kcvfhcpc (at offset 140) – Checkpoint count.
(4)kcvfhccc (at offset 148) – Unknown, but is always 1 less than thecheckpoint point count.
Oracle有4个属性来判断datafile 是否和其他的datafile 一致,如果都一致,可以正常操作,如果不一致,那么会报ORA-01113错误
下面我们看下这几个offset
BBED> set offset 484
OFFSET 484
BBED> dump
File: /dbdata/oradata/linuxidc/users01.dbf (0)
Block: 1 Offsets: 484 to 995 Dba:0x00000000
------------------------------------------------------------------------
1cd31200 00000000 bd384937 01000000 1b000000 30010000 100051f2 02000000
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 00000000 00000000 00000000 00000000 00000000 00000000 00000000
0d000d00 0d000100 00000000 00000000 00000000 02000001 03000000 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
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 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 00000000 00000000 00000000 00000000 00000000 00000000
<32 bytes per line>
BBED> set offset 492
OFFSET 492
BBED> dump
File: /dbdata/oradata/linuxidc/users01.dbf (0)
Block: 1 Offsets: 492 to 1003 Dba:0x00000000
------------------------------------------------------------------------
bd384937 01000000 1b000000 30010000 100051f2 02000000 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 00000000
00000000 00000000 00000000 00000000 00000000 00000000 0d000d00 0d000100
00000000 00000000 00000000 02000001 03000000 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 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 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
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
<32 bytes per line>
BBED> set offset 140
OFFSET 140
BBED> dump
File: /dbdata/oradata/linuxidc/users01.dbf (0)
Block: 1 Offsets: 140 to 651 Dba:0x00000000
------------------------------------------------------------------------
78000000 14ff4737 77000000 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 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
04000000 05005553 45525300 00000000 00000000 00000000 00000000 00000000
00000000 04000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 7ac92131 01000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 1cd31200 00000000
bd384937 01000000 1b000000 30010000 100051f2 02000000 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 00000000
00000000 00000000 00000000 00000000 00000000 00000000 0d000d00 0d000100
<32 bytes per line>
BBED> set offset 148
OFFSET 148
BBED> dump
File: /dbdata/oradata/linuxidc/users01.dbf (0)
Block: 1 Offsets: 148 to 659 Dba:0x00000000
------------------------------------------------------------------------
77000000 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 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 04000000 05005553
45525300 00000000 00000000 00000000 00000000 00000000 00000000 04000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 7ac92131 01000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 1cd31200 00000000 bd384937 01000000
1b000000 30010000 100051f2 02000000 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 00000000 00000000 00000000
00000000 00000000 00000000 00000000 0d000d00 0d000100 00000000 00000000
<32 bytes per line>