方法一:recover database using backup controlfile until cancel恢復。
SQL> startup
ORACLE instance started.
Total System Global Area167772160 bytes
Fixed Size2019320 bytes
Variable Size117440520 bytes
Database Buffers46137344 bytes
Redo Buffers2174976 bytes
Database mounted.
ORA-01122: database file 1 failed verification check
ORA-01110: data file 1: '/orac/oradata/jason/system01.dbf'
ORA-01207: file is more recent than control file - old control file
SQL> shutdown immediate
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area167772160 bytes
Fixed Size2019320 bytes
Variable Size117440520 bytes
Database Buffers46137344 bytes
Redo Buffers2174976 bytes
Database mounted.
SQL> recover database using backup controlfile until cancel;
ORA-00279: change 867108 generated at 07/21/2011 05:49:08 needed for thread 1
ORA-00289: suggestion : /orac/archive/1_3_757050028.dbf
ORA-00280: change 867108 for thread 1 is in sequence #3
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
auto
ORA-00308: cannot open archived log '/orac/archive/1_3_757050028.dbf'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
ORA-00308: cannot open archived log '/orac/archive/1_3_757050028.dbf'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1: '/orac/oradata/jason/system01.dbf'
這種恢復方式,不會自動去找在線redo日誌文件,所以必須要手工指定!
SQL> recover database using backup controlfile until cancel;
ORA-00279: change 867108 generated at 07/21/2011 05:49:08 needed for thread 1
ORA-00289: suggestion : /orac/archive/1_3_757050028.dbf
ORA-00280: change 867108 for thread 1 is in sequence #3
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/orac/oradata/jason/redo01.log
ORA-00328: archived log ends at change 866593, need later change 867108
ORA-00334: archived log: '/orac/oradata/jason/redo01.log'
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1: '/orac/oradata/jason/system01.dbf'
不是需要的在線日誌文件,繼續執行。
SQL> recover database using backup controlfile until cancel;
ORA-00279: change 867108 generated at 07/21/2011 05:49:08 needed for thread 1
ORA-00289: suggestion : /orac/archive/1_3_757050028.dbf
ORA-00280: change 867108 for thread 1 is in sequence #3
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/orac/oradata/jason/redo02.log
ORA-00328: archived log ends at change 846266, need later change 867108
ORA-00334: archived log: '/orac/oradata/jason/redo02.log'
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1: '/orac/oradata/jason/system01.dbf'
不是需要的在線日誌文件,繼續執行。
SQL> recover database using backup controlfile until cancel;
ORA-00279: change 867108 generated at 07/21/2011 05:49:08 needed for thread 1
ORA-00289: suggestion : /orac/archive/1_3_757050028.dbf
ORA-00280: change 867108 for thread 1 is in sequence #3
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/orac/oradata/jason/redo03.log
Log applied.
Media recovery complete.
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
恢復成功後需要使用resetlogs方式打開數據庫,這個時候需要對庫進行一次全部的備份。
SQL> alter database open resetlogs;
Database altered.
SQL>
方法二:重新創建控制文件。
SQL> startup
ORACLE instance started.
Total System Global Area167772160 bytes
Fixed Size2019320 bytes
Variable Size 134217736 bytes
Database Buffers29360128 bytes
Redo Buffers2174976 bytes
Database mounted.
ORA-01122: database file 1 failed verification check
ORA-01110: data file 1: '/orac/oradata/jason/system01.dbf'
ORA-01207: file is more recent than control file - old control file
生成控制文件的trace文件(nomount狀態不可以)
SQL> alter database backup controlfile to trace as '/orac/controlfile.txt';
Database altered.
SQL>
查看此文件,修改此文件爲以下內容:
[oracle@jason orac]$ vi controlfile.sql
#STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "JASON" NORESETLOGSARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/orac/oradata/jason/redo01.log'SIZE 50M,
GROUP 2 '/orac/oradata/jason/redo02.log'SIZE 50M,
GROUP 3 '/orac/oradata/jason/redo03.log'SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/orac/oradata/jason/system01.dbf',
'/orac/oradata/jason/undotbs01.dbf',
'/orac/oradata/jason/sysaux01.dbf',
'/orac/oradata/jason/users01.dbf',
'/orac/oradata/jason/jason01.dbf',
'/orac/oradata/jason/cat.dbf',
'/orac/oradata/jason/girl.dbf',
'/orac/oradata/jason/boy.dbf',
'/orac/oradata/jason/stone.dbf',
'/orac/oradata/jason/soft.dbf',
'/orac/oradata/jason/dog.dbf',
'/orac/oradata/jason/stone01.dbf'
CHARACTER SET ZHS16CGB231280
;
將原數據庫啓動到nomount狀態執行腳本,執行之前刪除舊的控制文件。
SQL> @/orac/controlfile.sql;
Control file created.
注意1:控制文件創建成功之後,數據庫自動被掛載。可以在alter日誌中看到。
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: '/orac/oradata/jason/system01.dbf'
由於系統突然斷電等原因,所以在重啓以後數據庫從redo file中恢復數據進行前滾。
SQL> RECOVER DATABASE;
Media recovery complete.
SQL> alter database open;
Database altered.
SQL>ALTER TABLESPACE TEMP ADD TEMPFILE '/orac/oradata/jason/temp01.dbf' REUSE;
Note:
執行創建控制文件腳本的時候報如下錯誤:
SQL> @/orac/controlfile.sql
SP2-0042: unknown command "DATAFILE" - rest of line ignored.
SP2-0734: unknown command beginning "'/orac/ora..." - rest of line ignored.
SP2-0734: unknown command beginning "'/orac/ora..." - rest of line ignored.
SP2-0734: unknown command beginning "'/orac/ora..." - rest of line ignored.
SP2-0044: For a list of known commands enter HELP
and to leave enter EXIT.
SP2-0734: unknown command beginning "'/orac/ora..." - rest of line ignored.
SP2-0734: unknown command beginning "'/orac/ora..." - rest of line ignored.
SP2-0734: unknown command beginning "'/orac/ora..." - rest of line ignored.
SP2-0734: unknown command beginning "'/orac/ora..." - rest of line ignored.
SP2-0044: For a list of known commands enter HELP
and to leave enter EXIT.
SP2-0734: unknown command beginning "'/orac/ora..." - rest of line ignored.
SP2-0734: unknown command beginning "'/orac/ora..." - rest of line ignored.
SP2-0734: unknown command beginning "'/orac/ora..." - rest of line ignored.
SP2-0734: unknown command beginning "'/orac/ora..." - rest of line ignored.
SP2-0044: For a list of known commands enter HELP
and to leave enter EXIT.
SP2-0734: unknown command beginning "'/orac/ora..." - rest of line ignored.
SP2-0734: unknown command beginning "CHARACTER ..." - rest of line ignored.
1CREATE CONTROLFILE REUSE DATABASE "JASON" NORESETLOGSARCHIVELOG
2MAXLOGFILES 16
3MAXLOGMEMBERS 3
4MAXDATAFILES 100
5MAXINSTANCES 8
6MAXLOGHISTORY 292
7LOGFILE
8GROUP 1 '/orac/oradata/jason/redo01.log'SIZE 50M,
9GROUP 2 '/orac/oradata/jason/redo02.log'SIZE 50M,
10GROUP 3 '/orac/oradata/jason/redo03.log'SIZE 50M
11* -- STANDBY LOGFILE、
只需要執行如下語句可以解決
SQL> set sqlbl on
關於sqlbl參數解釋如下(來自官方),是因爲我們的SQL腳本中存在空白行,因此在執行腳本時會報錯。
SET SQLBL[ANKLINES] {ON | OFF}
SET SQLBLANKLINES is not supported in iSQL*Plus
Controls whether SQL*Plus puts blank lines within a SQL command or script. ON interprets blank lines and new lines as part of a SQL command or script. OFF, the default value, does not allow blank lines or new lines in a SQL command or script or script.
Enter the BLOCKTERMINATOR to stop SQL command entry without running the SQL command. Enter theSQLTERMINATOR character to stop SQL command entry and run the SQL statement
注意2:
二者的區別再於:
備份的控制文件不能自動進行完全恢復,可以手工apply日誌進行完全恢復。
重新創建的可以自動進行完全恢復。
進一步的理解是前者只能使用resetlogs選項打開數據庫,因爲oracle認爲using backup controlfile用的是不完全恢復.當使用了備份的控制文件或創建控制文件時使用了resetlogs選項時應使用using backup controlfile來進行恢復,並且最後用resetlogs打開
再引入biti的一段話就是:
對於恢復來說,如果數據庫正常關閉,在控制文件中存在着一個最大的checkpoint number and SCN(其實這裏就是end scn了) 則在做恢復的時候根據數據庫文件自動恢復到該控制文件記錄的SCN,所以對於備份的控制文件而言,如果自動恢復,則到該SCN處不再繼續恢復了,認爲恢復已經完畢。這時如果控制文件是和數據文件一個時間點冷備份的話,都不會進行恢復,會提示你無須恢復,直接就可以打開數據庫
而數據庫如若是異常關閉(abort /掉電 / )或者重建控制文件,則控制文件中記錄SCN認爲是無窮大(正常關閉的時候會修改爲當前數據庫SCN)。這樣恢復的時候要嘗試恢復到該SCN則需要應用到所有的日誌包括聯機日誌使用完畢,而如果是備份的控制文件,雖然不能自動進行完全恢復,但在using backup controlfile 下,因爲是可以手工 apply 日誌,則你可以一個一個的apply 到 聯機日誌完畢,這樣也可以實現完全恢復。