控制檔案丟失恢復(二)

sky850623發表於2014-01-18

 (二)控制檔案全部丟失恢復
 如果控制檔案全部丟失,也可以有兩種解決辦法:建立控制檔案恢復和使用備份的控制檔案恢復
下面模擬這兩種方法
 1)使用建立控制檔案來恢復
 a)先備份控制檔案
SQL> alter database backup controlfile to trace;    --備份的控制檔案在udmp目錄下

Database altered.
SQL> alter database backup controlfile to trace as 'c:\ctl.txt';  --備份控制檔案到指定目錄

Database altered.
b)模擬所有控制檔案損壞(刪除所有控制檔案)
 資料庫處於關閉狀態
 恢復過程: 
c)啟動到nomount
SQL> startup nomount;
ORACLE instance started.

Total System Global Area  570425344 bytes
Fixed Size                  1250188 bytes
Variable Size             201329780 bytes
Database Buffers          360710144 bytes
Redo Buffers                7135232 bytes
d)建立控制檔案
控制檔案丟失恢復(二)

由於日誌檔案沒有損壞,不需重建redo log,使用noresetlogs來建立控制檔案
建立完控制檔案資料庫自動啟到mount狀態

問題:如果控制檔案備份後資料檔案增加了怎麼辦?建立是否還會成功?
e)恢復資料庫
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: 'D:\ORACLE\ORADATA\ORCL\SYSTEM01.DBF'
SQL> recover database;  --恢復資料庫
Media recovery complete.
f)開啟資料庫
SQL> alter database open;

Database altered.

 2)從備份中恢復
     準備工作:
      1.先備份控制檔案

SQL> alter database backup controlfile to 'c:\control01.ctl';

Database altered.
      2.備份完後建立一個表插入資料來測試
SQL> create table t1(id int,name varchar2(5));

Table created.

SQL> insert into t1 values(1,'a');

1 row created.

SQL> commit;

Commit complete.
檢視當前日誌檔案
SQL> select group#,sequence#,members,status from v$log;

    GROUP#  SEQUENCE#    MEMBERS STATUS
---------- ---------- ---------- ----------------
         1         86          1 INACTIVE
         2         85          1 INACTIVE
         3         87          1 CURRENT
  切換日誌
  SQL> alter system switch logfile;

System altered.

SQL> select group#,sequence#,members,status from v$log;

    GROUP#  SEQUENCE#    MEMBERS STATUS
---------- ---------- ---------- ----------------
         1         86          1 INACTIVE
         2         88          1 CURRENT
         3         87          1 ACTIVE
  插入資料
SQL> insert into t1 values(2,'b');

1 row created.

SQL> commit;

Commit complete.
切換
SQL> alter system switch logfile;

System altered.

SQL> select group#,sequence#,members,status from v$log;  --當前日誌檔案是89

    GROUP#  SEQUENCE#    MEMBERS STATUS
---------- ---------- ---------- ----------------
         1         89          1 CURRENT
         2         88          1 ACTIVE
         3         87          1 ACTIVE
SQL> insert into t1 values(3,'c');

1 row created.

SQL> commit;

Commit complete.
SQL> alter system switch logfile;

System altered.

SQL> select group#,sequence#,members,status from v$log;

    GROUP#  SEQUENCE#    MEMBERS STATUS
---------- ---------- ---------- ----------------
         1         89          1 ACTIVE
         2         88          1 ACTIVE
         3         90          1 CURRENT
  繼續插入資料
SQL> insert into t1 values(4,'d');    --在90號當前日誌

1 row created.

SQL> commit;

Commit complete.

  3.關閉資料庫,模擬控制檔案丟失(刪除全部控制檔案)
    開始恢復
     4.把備份控制檔案的拷回原來的位置
     5.啟動到mount狀態
SQL> startup mount;
ORACLE instance started.

Total System Global Area  570425344 bytes
Fixed Size                  1250188 bytes
Variable Size             188746868 bytes
Database Buffers          373293056 bytes
Redo Buffers                7135232 bytes
Database mounted.
SQL> select file#,checkpoint_change# from v$datafile;

     FILE# CHECKPOINT_CHANGE#
---------- ------------------
         1            7008532
         2            7008532
         3            7008532
         4            7008532
         5            7008532
         6            7008532
         7            7008532
         8            7008532
         9            7008532

9 rows selected.

SQL> select file#,checkpoint_change# from v$datafile_header;

     FILE# CHECKPOINT_CHANGE#
---------- ------------------
         1            7010506
         2            7010506
         3            7010506
         4            7010506
         5            7010506
         6            7010506
         7            7010506
         8            7010506
         9            7010506

9 rows selected.

     6.恢復資料庫
SQL> recover database using backup controlfile;
ORA-00279: change 7008694 generated at 01/18/2014 11:32:55 needed for thread 1
ORA-00289: suggestion :
C:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\ORCL\ARCHIVELOG\2014_01_18\O1_MF_1_   --需要87號歸檔日誌檔案
87_%U_.ARC
ORA-00280: change 7008694 for thread 1 is in sequence #87


Specify log: {=suggested | filename | AUTO | CANCEL}   --回車

ORA-00279: change 7010506 generated at 01/18/2014 11:41:29 needed for thread 1
ORA-00289: suggestion :
C:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\ORCL\ARCHIVELOG\2014_01_18\O1_MF_1_    --需要88號歸檔日誌檔案
88_%U_.ARC
ORA-00280: change 7010506 for thread 1 is in sequence #88
ORA-00278: log file
'C:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\ORCL\ARCHIVELOG\2014_01_18\O1_MF_1    --87號歸檔不再需要
_87_9FMXZ989_.ARC' no longer needed for this recovery


Specify log: {=suggested | filename | AUTO | CANCEL}

ORA-00279: change 7010575 generated at 01/18/2014 11:44:09 needed for thread 1
ORA-00289: suggestion :
C:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\ORCL\ARCHIVELOG\2014_01_18\O1_MF_1_
89_%U_.ARC
ORA-00280: change 7010575 for thread 1 is in sequence #89
ORA-00278: log file
'C:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\ORCL\ARCHIVELOG\2014_01_18\O1_MF_1
_88_9FMY49RF_.ARC' no longer needed for this recovery


Specify log: {=suggested | filename | AUTO | CANCEL}

ORA-00279: change 7010754 generated at 01/18/2014 11:46:28 needed for thread 1
ORA-00289: suggestion :
C:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\ORCL\ARCHIVELOG\2014_01_18\O1_MF_1_
90_%U_.ARC
ORA-00280: change 7010754 for thread 1 is in sequence #90
ORA-00278: log file
'C:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\ORCL\ARCHIVELOG\2014_01_18\O1_MF_1
_89_9FMY8OGN_.ARC' no longer needed for this recovery


Specify log: {=suggested | filename | AUTO | CANCEL}

ORA-00308: cannot open archived log
'C:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\ORCL\ARCHIVELOG\2014_01_18\O1_MF_1
_90_%U_.ARC'
ORA-27041: unable to open file      --序列號為90的歸檔日誌檔案,90號還沒有歸檔,沒有自動去找當前線上日誌去恢復
OSD-04002: unable to open file
O/S-Error: (OS 2) 系統找不到指定的檔案。

SQL> select group#,sequence#,status from v$log;   --恢復的過程中日誌序列號沒有發生變化

    GROUP#  SEQUENCE# STATUS
---------- ---------- ----------------
         1         86 INACTIVE
         3         87 CURRENT
         2         85 INACTIVE
  SQL> select sequence#,first_change#,first_time,next_change#,next_time from v$archived_log;  --90還沒歸檔

 SEQUENCE# FIRST_CHANGE# FIRST_TIME   NEXT_CHANGE# NEXT_TIME
---------- ------------- ------------ ------------ ------------
        87       7008531 18-JAN-14         7010506 18-JAN-14
        88       7010506 18-JAN-14         7010575 18-JAN-14
        89       7010575 18-JAN-14         7010754 18-JAN-14

3 rows selected.
SQL> select file#,checkpoint_change# from v$datafile;

     FILE# CHECKPOINT_CHANGE#
---------- ------------------
         1            7010754
         2            7010754
         3            7010754
         4            7010754
         5            7010754
         6            7010754
         7            7010754
         8            7010754
         9            7010754

9 rows selected.

SQL> select file#,checkpoint_change# from v$datafile_header;

     FILE# CHECKPOINT_CHANGE#
---------- ------------------
         1            7010754
         2            7010754
         3            7010754
         4            7010754
         5            7010754
         6            7010754
         7            7010754
         8            7010754
         9            7010754

9 rows selected.
繼續恢復
SQL> recover database using backup controlfile;
ORA-00279: change 7010754 generated at 01/18/2014 11:46:28 needed for thread 1
ORA-00289: suggestion :
C:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\ORCL\ARCHIVELOG\2014_01_18\O1_MF_1_
90_%U_.ARC
ORA-00280: change 7010754 for thread 1 is in sequence #90


Specify log: {=suggested | filename | AUTO | CANCEL}
D:\oracle\oradata\orcl\redo03.log    --手動指定90號歸檔即線上的3號日誌組,恢復完成
Log applied.
Media recovery complete.
SQL> select file#,checkpoint_change# from v$datafile;

     FILE# CHECKPOINT_CHANGE#
---------- ------------------
         1            7010811
         2            7010811
         3            7010811
         4            7010811
         5            7010811
         6            7010811
         7            7010811
         8            7010811
         9            7010811

9 rows selected.

SQL> select file#,checkpoint_change# from v$datafile;

     FILE# CHECKPOINT_CHANGE#
---------- ------------------
         1            7010811
         2            7010811
         3            7010811
         4            7010811
         5            7010811
         6            7010811
         7            7010811
         8            7010811
         9            7010811

9 rows selected.

SQL> select group#,sequence#,status from v$log;

    GROUP#  SEQUENCE# STATUS
---------- ---------- ----------------
         1         86 INACTIVE
         3         87 CURRENT
         2         85 INACTIVE
     7.必須以resetlogs開啟資料庫
 SQL> alter database open resetlogs;

Database altered.
日誌檔案被重新建立
SQL> select group#,sequence#,status from v$log;

    GROUP#  SEQUENCE# STATUS
---------- ---------- ----------------
         1          0 UNUSED
         2          0 UNUSED
         3          1 CURRENT
  88,89,90三組日誌又被歸檔
  SQL> select sequence#,first_change#,first_time,next_change#,next_time from v$archived_log;

 SEQUENCE# FIRST_CHANGE# FIRST_TIME   NEXT_CHANGE# NEXT_TIME
---------- ------------- ------------ ------------ ------------
        87       7008531 18-JAN-14         7010506 18-JAN-14
        88       7010506 18-JAN-14         7010575 18-JAN-14
        89       7010575 18-JAN-14         7010754 18-JAN-14
        89       7010575 18-JAN-14         7010754 18-JAN-14
        88       7010506 18-JAN-14         7010575 18-JAN-14
        90       7010754 18-JAN-14         7010812 18-JAN-14

6 rows selected.
     8.重新備份資料庫

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26937943/viewspace-1072480/,如需轉載,請註明出處,否則將追究法律責任。

相關文章