环境:Linux+oracle 11.2.0.2
描述:这次主要是模拟在恢复过程中有丢失归档日志,但有想跳过这个归档日志继续恢复,简单的思路是这样子,如果我们把需要恢复的datafile header scn改到跟下个归档日志的scn一致(v$archived_log.next_change#)是否就可以跳过了呢?答案是否定的,下面我们就开始模拟测试下。
1.模拟环境
[oracle@dg1 dbs]$ sqlplus ‘/as sysdba’;
SQL*Plus: Release 11.2.0.2.0 Production on Thu Aug 1 07:04:55 2013
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.Total System Global Area 217157632 bytes
Fixed Size 2225064 bytes
Variable Size 159386712 bytes
Database Buffers 50331648 bytes
Redo Buffers 5214208 bytes
Database mounted.
Database opened.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit[oracle@dg1 app]$ cp -r oradata oradata2 ―-备份一下,用于等会的恢复
2.模拟一下数据,并生成很多archive log
SQL> insert into test_arch values(1);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
SQL> insert into test_arch values(2);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
SQL> insert into test_arch values(3);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
SQL> insert into test_arch values(4);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
SQL> insert into test_arch values (5);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
SQL> insert into test_arch values (6);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
SQL> /
System altered.
SQL>
发现生成了很多归档日志:
[oracle@dg1 arch]$ ls -lrt
total 756
-rw-r―�C 1 oracle oinstall 205312 Aug 1 07:04 1_150_822066437.arc
-rw-r―�C 1 oracle oinstall 1536 Aug 1 07:04 1_151_822066437.arc
-rw-r―�C 1 oracle oinstall 120832 Aug 1 07:05 1_152_822066437.arc
-rw-r―�C 1 oracle oinstall 49152 Aug 1 07:05 1_153_822066437.arc
-rw-r―�C 1 oracle oinstall 118784 Aug 1 07:08 1_154_822066437.arc
-rw-r―�C 1 oracle oinstall 34304 Aug 1 07:08 1_155_822066437.arc
-rw-r―�C 1 oracle oinstall 130048 Aug 1 07:11 1_156_822066437.arc
-rw-r―�C 1 oracle oinstall 14848 Aug 1 07:11 1_157_822066437.arc
-rw-r―�C 1 oracle oinstall 9216 Aug 1 07:11 1_158_822066437.arc
-rw-r―�C 1 oracle oinstall 9216 Aug 1 07:12 1_159_822066437.arc
-rw-r―�C 1 oracle oinstall 13312 Aug 1 07:12 1_160_822066437.arc
-rw-r―�C 1 oracle oinstall 24576 Aug 1 07:13 1_161_822066437.arc
-rw-r―�C 1 oracle oinstall 3072 Aug 1 07:13 1_162_822066437.arc接着我们需要关闭数据库,并删除中间的一些归档日志,然后将一开始备份的datafile替换回去.然后开始恢复。
3.开始恢复
将原备份的datafile还原回来后:
SQL> startup
ORACLE instance started.Total System Global Area 217157632 bytes
Fixed Size 2225064 bytes
Variable Size 159386712 bytes
Database Buffers 50331648 bytes
Redo Buffers 5214208 bytes
Database mounted.
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: ‘/u01/app/oradata/system.dbf’
SQL>SQL> recover database;
ORA-00279: change 454419 generated at 08/01/2013 07:05:28 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/arch/1_154_822066437.arc
ORA-00280: change 454419 for thread 1 is in sequence #154
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/u01/app/oracle/arch/1_154_822066437.arc
ORA-00279: change 454422 generated at 08/01/2013 07:08:06 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/arch/1_155_822066437.arc
ORA-00280: change 454422 for thread 1 is in sequence #155
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/u01/app/oracle/arch/1_155_822066437.arc
ORA-00279: change 454508 generated at 08/01/2013 07:08:13 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/arch/1_156_822066437.arc
ORA-00280: change 454508 for thread 1 is in sequence #156
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/u01/app/oracle/arch/1_156_822066437.arc
ORA-00279: change 454760 generated at 08/01/2013 07:11:02 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/arch/1_157_822066437.arc
ORA-00280: change 454760 for thread 1 is in sequence #157
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/u01/app/oracle/arch/1_157_822066437.arc
ORA-00279: change 454789 generated at 08/01/2013 07:11:28 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/arch/1_158_822066437.arc
ORA-00280: change 454789 for thread 1 is in sequence #158
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/u01/app/oracle/arch/1_158_822066437.arc
ORA-00279: change 454807 generated at 08/01/2013 07:11:43 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/arch/1_159_822066437.arc
ORA-00280: change 454807 for thread 1 is in sequence #159
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/u01/app/oracle/arch/1_159_822066437.arc
ORA-00308: cannot open archived log ‘/u01/app/oracle/arch/1_159_822066437.arc’
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
cancel
Media recovery cancelled.应用159这个log的时候发现已经不存在啦.这个时候我们就要想办法跳过这个归档日志继续应用后面的log
SQL> select checkpoint_change# from v$datafile;
CHECKPOINT_CHANGE#
――――――
455246
455246
455246
455246SQL> select checkpoint_change# from v$datafile_header;
CHECKPOINT_CHANGE#
――――――
454807
454807
454807
454807NAME FIRST_CHANGE# NEXT_CHANGE#
―――――――――――――- ――――- ――――
/u01/app/oracle/arch/1_155_822066437.arc 454422 454508
/u01/app/oracle/arch/1_156_822066437.arc 454508 454760
/u01/app/oracle/arch/1_157_822066437.arc 454760 454789
/u01/app/oracle/arch/1_158_822066437.arc 454789 454807
/u01/app/oracle/arch/1_159_822066437.arc 454807 454827―-
/u01/app/oracle/arch/1_160_822066437.arc 454827 454853―-我们可以尝试吧scn修改成454827-
/u01/app/oracle/arch/1_161_822066437.arc 454853 454902
/u01/app/oracle/arch/1_162_822066437.arc 454902 454908尝试修改scn跳过归档
4.BBED修复
BBED> p kcvfhckp
struct kcvfhckp, 36 bytes @484
struct kcvcpscn, 8 bytes @484
ub4 kscnbas @484 0x0006f097―scn:454807,可以先修改成上面说的454827(6f0ab)
ub2 kscnwrp @488 0×0000
ub4 kcvcptim @492 0x310338af
ub2 kcvcpthr @496 0×0001
union u, 12 bytes @500
struct kcvcprba, 12 bytes @500
ub4 kcrbaseq @500 0x0000009f
ub4 kcrbabno @504 0×00000002
ub2 kcrbabof @508 0×0000
ub1 kcvcpetb[0] @512 0×02
ub1 kcvcpetb[1] @513 0×00
ub1 kcvcpetb[2] @514 0×00
ub1 kcvcpetb[3] @515 0×00
ub1 kcvcpetb[4] @516 0×00
ub1 kcvcpetb[5] @517 0×00
ub1 kcvcpetb[6] @518 0×00
ub1 kcvcpetb[7] @519 0×00
BBED> modify /x abf0 dba 1,1 offset 484
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
File: /u01/app/oradata/system.dbf (1)
Block: 1 Offsets: 484 to 499 Dba:0×00400001
――――――――――――――――――――――――
abf00600 00000000 af380331 01000000<32 bytes per line>
BBED> sum apply
BBED> modify /x abf0 dba 2,1 offset 484
File: /u01/app/oradata/sysaux.dbf (2)
Block: 1 Offsets: 484 to 499 Dba:0×00800001
――――――――――――――――――――――――
abf00600 00000000 af380331 01000000<32 bytes per line>
BBED> sum apply
BBED> modify /x abf0 dba 3,1 offset 484
File: /u01/app/oradata/undotbs1.dbf (3)
Block: 1 Offsets: 484 to 499 Dba:0x00c00001
――――――――――――――――――――――――
abf00600 00000000 af380331 01000000<32 bytes per line>
BBED> sum apply
BBED> modify /x abf0 dba 4,1 offset 484
File: /u01/app/oradata/test.dbf (4)
Block: 1 Offsets: 484 to 499 Dba:0×01000001
――――――――――――――――――――――――
abf00600 00000000 af380331 01000000<32 bytes per line>
BBED> sum apply
Check value for File 4, Block 1:
current = 0xf40b, required = 0xf40bBBED> verify
DBVERIFY �C Verification starting
FILE = /u01/app/oradata/test.dbf
BLOCK = 1
DBVERIFY �C Verification completeTotal Blocks Examined : 1
Total Blocks Processed (Data) : 0
Total Blocks Failing (Data) : 0
Total Blocks Processed (Index): 0
Total Blocks Failing (Index): 0
Total Blocks Empty : 0
Total Blocks Marked Corrupt : 0
Total Blocks Influx : 0
Message 531 not found; product=RDBMS; facility=BBED尝试重启打开数据库
SQL> startup mount;
ORACLE instance started.Total System Global Area 217157632 bytes
Fixed Size 2225064 bytes
Variable Size 159386712 bytes
Database Buffers 50331648 bytes
Redo Buffers 5214208 bytes
Database mounted.
SQL> recover database;
ORA-00279: change 454827 generated at 08/01/2013 07:11:43 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/arch/1_159_822066437.arc
ORA-00280: change 454827 for thread 1 is in sequence #159
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}发现还是会找159这个归档,所以考虑是否datafile header里面有记录sequence号啊?往下看
BBED> p kcvfhckp
struct kcvfhckp, 36 bytes @484
struct kcvcpscn, 8 bytes @484
ub4 kscnbas @484 0x0006f0ab
ub2 kscnwrp @488 0×0000
ub4 kcvcptim @492 0x310338af
ub2 kcvcpthr @496 0×0001
union u, 12 bytes @500
struct kcvcprba, 12 bytes @500
ub4 kcrbaseq @500 0x0000009f――159.找到啦.
ub4 kcrbabno @504 0×00000002
ub2 kcrbabof @508 0×0000
ub1 kcvcpetb[0] @512 0×02
ub1 kcvcpetb[1] @513 0×00
ub1 kcvcpetb[2] @514 0×00
ub1 kcvcpetb[3] @515 0×00
ub1 kcvcpetb[4] @516 0×00
ub1 kcvcpetb[5] @517 0×00
ub1 kcvcpetb[6] @518 0×00
ub1 kcvcpetb[7] @519 0×00所以需要手动在改一下seq为160试试看
BED> modify /x a0 dba 1,1 offset 500
File: /u01/app/oradata/system.dbf (1)
Block: 1 Offsets: 500 to 515 Dba:0×00400001
――――――――――――――――――――――――
a0000000 02000000 00000000 02000000<32 bytes per line>
BBED> sum apply
Check value for File 1, Block 1:
current = 0x52ed, required = 0x52edBBED> modify /x a0 dba 2,1 offset 500
File: /u01/app/oradata/sysaux.dbf (2)
Block: 1 Offsets: 500 to 515 Dba:0×00800001
――――――――――――――――――――――――
a0000000 02000000 00000000 02000000<32 bytes per line>
BBED> sum apply
Check value for File 2, Block 1:
current = 0x23e5, required = 0x23e5BBED> modify /x a0 dba 3,1 offset 500
File: /u01/app/oradata/undotbs1.dbf (3)
Block: 1 Offsets: 500 to 515 Dba:0x00c00001
――――――――――――――――――――――――
a0000000 02000000 00000000 02000000<32 bytes per line>
BBED> sum apply
Check value for File 3, Block 1:
current = 0x1da4, required = 0x1da4BBED> modify /x a0 dba 4,1 offset 500
File: /u01/app/oradata/test.dbf (4)
Block: 1 Offsets: 500 to 515 Dba:0×01000001
――――――――――――――――――――――――
a0000000 02000000 00000000 02000000<32 bytes per line>
BBED> sum apply
Check value for File 4, Block 1:
current = 0xf325, required = 0xf325BBED> verify
DBVERIFY �C Verification starting
FILE = /u01/app/oradata/test.dbf
BLOCK = 1
DBVERIFY �C Verification completeTotal Blocks Examined : 1
Total Blocks Processed (Data) : 0
Total Blocks Failing (Data) : 0
Total Blocks Processed (Index): 0
Total Blocks Failing (Index): 0
Total Blocks Empty : 0
Total Blocks Marked Corrupt : 0
Total Blocks Influx : 0
Message 531 not found; product=RDBMS; facility=BBED重启数据库
5.开启数据库
SQL> recover database;
ORA-00279: change 454827 generated at 08/01/2013 07:11:43 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/arch/1_160_822066437.arc
ORA-00280: change 454827 for thread 1 is in sequence #160
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/u01/app/oracle/arch/1_160_822066437.arc
ORA-00283: recovery session canceled due to errors
ORA-00600: internal error code, arguments: [3020], [3], [346], [12583258], [], [], [], [], [], [], [], []
ORA-10567: Redo is inconsistent with data block (file# 3, block# 346, file offset is 2834432 bytes)
ORA-10564: tablespace UNDOTBS1
ORA-01110: data file 3: ‘/u01/app/oradata/undotbs1.dbf’
ORA-10560: block type ‘KTU UNDO BLOCK’
ORA-01112: media recovery not started
SQL>从上面看已经跳过159啦.但是出现不一致的情况,这个可以去metalink查一下
SQL> recover database allow 10 corruption;
Media recovery complete.我就直接跳过啦,不过你也可以用dbv去看看。
继续打开数据库
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01092: ORACLE instance terminated. Disconnection forced
ORA-01578: ORACLE data block corrupted (file # 3, block # 208)
ORA-01110: data file 3: ‘/u01/app/oradata/undotbs1.dbf’
Process ID: 24093
Session ID: 16 Serial number: 3又报错,但是这个报错应该好解决多啦.你可以尝试用offline undo.我下面就直接修改undo_management=manual;
[oracle@dg1 dbs]$ sqlplus ‘/as sysdba’;
SQL*Plus: Release 11.2.0.2.0 Production on Thu Aug 1 07:39:30 2013
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.Total System Global Area 217157632 bytes
Fixed Size 2225064 bytes
Variable Size 159386712 bytes
Database Buffers 50331648 bytes
Redo Buffers 5214208 bytes
Database mounted.
Database opened.
SQL> select * from test_arch;ID
―――-
1
2
3
5
6SQL>
发现上面少了一个4.就是跳过归档的那部分数据.
6.结束