三 舉例如下:
最上面的錯誤是由bbed模擬的,下面構造一個比較接近實際的例子。
既然我們已經知道,ora-01190錯誤是由於數據文件頭部resetlogs信息和控制文件中resetlogs信息不匹配造成,那麼當我們alter database open resetlogs 打開一個數據庫時,如果某個文件頭部沒有被alter database open resetlogs動作更新,比如open resetlogs 打開數據庫前有一個offline的數據文件,那麼open resetlogs 之後此數據文件要online時就會報ora-01190錯誤。
1 構造一個ora-01190錯誤
SQL> select file#,name,status from v$datafile;
FILE# NAME STATUS
---------- ---------------------------------------- -------
1 /oracle/test/system1.dbf SYSTEM
2 /oracle/test/zxb.dbf ONLINE
3 /oracle/test/sysaux01.dbf ONLINE
4 /oracle/test/users01.dbf ONLINE
5 /oracle/test/zxa.dbf ONLINE
6 /oracle/test/test1.dbf ONLINE
7 /oracle/test/zxc.dbf ONLINE
8 /oracle/test/undotbs1.dbf ONLINE
9 /oracle/test/undotbs3.dbf ONLINE
11 /oracle/test/jiujian1.dbf ONLINE
13 /oracle/test/test2.dbf ONLINE
SQL> alter database datafile 13 offline;(注意open resetlogs數據庫前需要offline drop 數據文件這裏先offline觸發報錯時在改成offline drop)
Database altered.
SQL> select file#,name,status from v$datafile;
FILE# NAME STATUS
---------- ---------------------------------------- -------
1 /oracle/test/system1.dbf SYSTEM
2 /oracle/test/zxb.dbf ONLINE
3 /oracle/test/sysaux01.dbf ONLINE
4 /oracle/test/users01.dbf ONLINE
5 /oracle/test/zxa.dbf ONLINE
6 /oracle/test/test1.dbf ONLINE
7 /oracle/test/zxc.dbf ONLINE
8 /oracle/test/undotbs1.dbf ONLINE
9 /oracle/test/undotbs3.dbf ONLINE
11 /oracle/test/jiujian1.dbf ONLINE
13 /oracle/test/test2.dbf RECOVER
11 rows selected.
SQL> select hxfil,fhrba_seq from x$kcvfh;
HXFIL FHRBA_SEQ
---------- ----------
1 5
2 5
3 5
4 5
5 5
6 5
7 5
8 5
9 5
11 5
13 5
11 rows selected.
SQL> select group#,archived,sequence#,status from v$log;
GROUP# ARC SEQUENCE# STATUS
---------- --- ---------- ----------------
1 YES 7 ACTIVE
2 NO 8 CURRENT
6 YES 6 ACTIVE
4 YES 4 INACTIVE
5 YES 5 ACTIVE
3 YES 3 INACTIVE
6 rows selected.
SQL> startup force mount;
ORACLE instance started.
Total System Global Area 322961408 bytes
Fixed Size 2020480 bytes
Variable Size 96471936 bytes
Database Buffers 218103808 bytes
Redo Buffers 6365184 bytes
Database mounted.
SQL> recover database until cancel;
ORA-00279: change 2781702590 generated at 01/21/2013 22:22:06 needed for thread
1
ORA-00289: suggestion : /oracle/archive/1_5_805259716.dbf
ORA-00280: change 2781702590 for thread 1 is in sequence #5
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
cancel
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01194: file 1 needs more recovery to be consistent
ORA-01110: data file 1: '/oracle/test/system1.dbf'
ORA-01112: media recovery not started
SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-01194: file 1 needs more recovery to be consistent
ORA-01110: data file 1: '/oracle/test/system1.dbf'
注意這裏由於一致性原因不能open resetlogs我們加下面的隱含參數規避該錯誤
SQL> alter system set "_allow_resetlogs_corruption"=true scope=spfile;
System altered.
SQL> startup force mount;
ORACLE instance started.
Total System Global Area 322961408 bytes
Fixed Size 2020480 bytes
Variable Size 96471936 bytes
Database Buffers 218103808 bytes
Redo Buffers 6365184 bytes
Database mounted.
SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-01245: offline file 13 will be lost if RESETLOGS is done
ORA-01110: data file 13: '/oracle/test/test2.dbf'
注意:這裏提示如果以resetlogs打開數據庫,則13號文件會丟失。所以我們用如下命令增加關鍵字for drop 意思就是告訴數據庫,這個數據文件我後面可能會丟棄,不會在online了。
SQL> alter database datafile 13 offline for drop;
Database altered.
SQL> alter database open resetlogs;
Database altered.
SQL> select resetlogs_change#, to_char(resetlogs_time,'mm/dd/yyyy hh24:mi:ss') time from v$database;
RESETLOGS_CHANGE# TIME
----------------- -------------------
2781863029 01/21/2013 23:15:55
SQL> select hxfil,fhrls change#,fhrlc_i,fhrlc time from x$kcvfh;
HXFIL CHANGE# FHRLC_I TIME
---------- ---------------- ---------- --------------------
1 2781863029 805331755 01/21/2013 23:15:55
2 2781863029 805331755 01/21/2013 23:15:55
3 2781863029 805331755 01/21/2013 23:15:55
4 2781863029 805331755 01/21/2013 23:15:55
5 2781863029 805331755 01/21/2013 23:15:55
6 2781863029 805331755 01/21/2013 23:15:55
7 2781863029 805331755 01/21/2013 23:15:55
8 2781863029 805331755 01/21/2013 23:15:55
9 2781863029 805331755 01/21/2013 23:15:55
11 2781863029 805331755 01/21/2013 23:15:55
13 2781842874 805330675 01/21/2013 22:57:55
11 rows selected.
SQL> alter database datafile 13 online;
alter database datafile 13 online
*
ERROR at line 1:
ORA-01190: control file or data file 13 is from before the last RESETLOGS
ORA-01110: data file 13: '/oracle/test/test2.dbf'
2 用bbed更改數據文件頭部規避ora-01190錯誤
BBED> dump /v dba 1,1 offset 112 count 30
File: /oracle/test/system1.dbf (1)
Block: 1 Offsets: 112 to 141 Dba:0x00400001
-------------------------------------------------------
2b630030 75dccfa5 00000000 00000000 l +c.0u芟?.......
00000000 00000000 00000420 3408 l ........... 4.
<16 bytes per line>
BBED> dump /v dba 13,1 offset 112 count 30
File: /oracle/test/test2.dbf (13)
Block: 1 Offsets: 112 to 141 Dba:0x03400001
-------------------------------------------------------
f35e0030 ba8dcfa5 00000000 00000000 l 骬.0?膝........
00000000 00000000 00000400 6c02 l ............l.
<16 bytes per line>
BBED> modify /x 2b63
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
File: /oracle/test/test2.dbf (13)
Block: 1 Offsets: 112 to 141 Dba:0x03400001
------------------------------------------------------------------------
2b630030 ba8dcfa5 00000000 00000000 00000000 00000000 00000400 6c02
<32 bytes per line>
BBED> dump /v dba 1,1 offset 116 count 30
File: /oracle/test/system1.dbf (1)
Block: 1 Offsets: 116 to 145 Dba:0x00400001
-------------------------------------------------------
75dccfa5 00000000 00000000 00000000 l u芟?...........
00000000 00000420 34080000 2a61 l ....... 4...*a
<16 bytes per line>
BBED> dump /v dba 13,1 offset 116 count 30
File: /oracle/test/test2.dbf (13)
Block: 1 Offsets: 116 to 145 Dba:0x03400001
-------------------------------------------------------
ba8dcfa5 00000000 00000000 00000000 l ?膝............
00000000 00000400 6c020000 785f l ........l...x_
<16 bytes per line>
BBED> modify /x 75dc
File: /oracle/test/test2.dbf (13)
Block: 1 Offsets: 116 to 145 Dba:0x03400001
------------------------------------------------------------------------
75dccfa5 00000000 00000000 00000000 00000000 00000400 6c020000 785f
<32 bytes per line>
BBED> sum apply
Check value for File 13, Block 1:
current = 0xf50b, required = 0xf50b
SQL> select hxfil,fhrls change#,fhrlc_i,fhrlc time from x$kcvfh;
HXFIL CHANGE# FHRLC_I TIME
---------- ---------------- ---------- --------------------
1 2781863029 805331755 01/21/2013 23:15:55
2 2781863029 805331755 01/21/2013 23:15:55
3 2781863029 805331755 01/21/2013 23:15:55
4 2781863029 805331755 01/21/2013 23:15:55
5 2781863029 805331755 01/21/2013 23:15:55
6 2781863029 805331755 01/21/2013 23:15:55
7 2781863029 805331755 01/21/2013 23:15:55
8 2781863029 805331755 01/21/2013 23:15:55
9 2781863029 805331755 01/21/2013 23:15:55
11 2781863029 805331755 01/21/2013 23:15:55
13 2781863029 805331755 01/21/2013 23:15:55
11 rows selected.
注意下面,我們上面雖然用bbed調整了數據文件頭部的restlogs scn 和resetlogs count 使之和控制文件保持一樣,不過我們online 數據文件時會接着報需要介質恢復。如下:
SQL> alter database datafile 13 online;
alter database datafile 13 online
*
ERROR at line 1:
ORA-01113: file 13 needs media recovery
ORA-01110: data file 13: '/oracle/test/test2.dbf'
3 用bbed調整數據文件頭部檢查點以及scn相關值
我們還應改如下偏移量
ub4 kcvfhcpc @140 0x00000308------檢查點計數
ub4 kcvfhccc @148 0x00000307------總是比檢查點計算少1
ub4 kcvcptim @492 0x2f9af923-----檢查點時間
ub4 kscnbas @484 0x8013ea80-------- scn的低位
ub2 kscnwrp @488 0x0000--------- scn的高位
BBED> dump /v dba 1,1 offset 140 count 30
File: /oracle/test/system1.dbf (1)
Block: 1 Offsets: 140 to 169 Dba:0x00400001
-------------------------------------------------------
34080000 2a610030 33080000 00000000 l 4...*a.03.......
00000000 00000000 00000000 0000 l ..............
<16 bytes per line>
BBED> dump /v dba 13,1 offset 140 count 30
File: /oracle/test/test2.dbf (13)
Block: 1 Offsets: 140 to 169 Dba:0x03400001
-------------------------------------------------------
6c020000 05690030 6b020000 00000000 l l....i.0k.......
00000000 00000000 00000000 0000 l ..............
<16 bytes per line>
BBED> modify /x 3408
File: /oracle/test/test2.dbf (13)
Block: 1 Offsets: 140 to 169 Dba:0x03400001
------------------------------------------------------------------------
34080000 05690030 6b020000 00000000 00000000 00000000 00000000 0000
<32 bytes per line>
BBED> dump /v dba 1,1 offset 148 count 30
File: /oracle/test/system1.dbf (1)
Block: 1 Offsets: 148 to 177 Dba:0x00400001
-------------------------------------------------------
33080000 00000000 00000000 00000000 l 3...............
00000000 00000000 00000000 0000 l ..............
<16 bytes per line>
BBED> dump /v dba 13,1 offset 148
File: /oracle/test/test2.dbf (13)
Block: 1 Offsets: 148 to 177 Dba:0x03400001
-------------------------------------------------------
6b020000 00000000 00000000 00000000 l k...............
00000000 00000000 00000000 0000 l ..............
<16 bytes per line>
BBED> modify /x 3308
File: /oracle/test/test2.dbf (13)
Block: 1 Offsets: 148 to 177 Dba:0x03400001
------------------------------------------------------------------------
33080000 00000000 00000000 00000000 00000000 00000000 00000000 0000
<32 bytes per line>
BBED> dump /v dba 1,1 offset 492 count 30
File: /oracle/test/system1.dbf (1)
Block: 1 Offsets: 492 to 521 Dba:0x00400001
-------------------------------------------------------
7f630030 01000000 01000000 02000000 l .c.0............
10000000 02000000 00000000 0000 l ..............
<16 bytes per line>
BBED> dump /v dba 13,1 offset 492 count 30
File: /oracle/test/test2.dbf (13)
Block: 1 Offsets: 492 to 521 Dba:0x03400001
-------------------------------------------------------
4f600030 01000000 02000000 25000000 l O`.0........%...
100068be 02000000 00000000 0000 l ..h?.........
<16 bytes per line>
BBED> modify /x 7f63
File: /oracle/test/test2.dbf (13)
Block: 1 Offsets: 492 to 521 Dba:0x03400001
------------------------------------------------------------------------
7f630030 01000000 02000000 25000000 100068be 02000000 00000000 0000
<32 bytes per line>
BBED> dump /v dba 1,1 offset 484 count 30
File: /oracle/test/system1.dbf (1)
Block: 1 Offsets: 484 to 513 Dba:0x00400001
-------------------------------------------------------
76dccfa5 00000000 7f630030 01000000 l v芟?....c.0....
01000000 02000000 10000000 0200 l ..............
<16 bytes per line>
BBED> dump /v dba 13,1 offset 484 count 30
File: /oracle/test/test2.dbf (13)
Block: 1 Offsets: 484 to 513 Dba:0x03400001
-------------------------------------------------------
49dccfa5 00000000 7f630030 01000000 l I芟?....c.0....
02000000 25000000 100068be 0200 l ....%.....h?.
<16 bytes per line>
BBED> modify /x 76dc
File: /oracle/test/test2.dbf (13)
Block: 1 Offsets: 484 to 513 Dba:0x03400001
------------------------------------------------------------------------
76dccfa5 00000000 7f630030 01000000 02000000 25000000 100068be 0200
<32 bytes per line>
BBED> sum apply
Check value for File 13, Block 1:
current = 0xc02f, required = 0xc02f
SQL> recover datafile 13;
Media recovery complete.
--------------------------------------------------------完------------------------------------------------
總結
對於ora-01190,往往是ora-01190和數據文件的不一致共同出現。所以用bbed解決了ora-01190錯誤後,還需要處理數據文件的不一致問題。