RAC控制檔案恢復(三種不同情況)

達芬奇的夢發表於2018-05-11

RAC控制檔案恢復(三種不同情況)

測試環境:
系統:LINUX-64
資料庫:10.2.0.1
二節點的RAC(RACDB1,RACDB2),儲存用的ASM

有備份情況下,丟失控制檔案,我們改如何恢復?

一:使用備份的控制檔案恢復,最後需要使用resetlogs開啟。
(1) 備份控制檔案
RMAN> backup current controlfile;

(2) 進行日誌切換和資料修改
RACDB1>alter system switch logfile;

System altered.

RACDB1>create table test2 as select * from dba_users;

Table created.

RACDB1>alter system switch logfile;

System altered.

RACDB1>SELECT thread#,group#,sequence#,status FROM V$log;

   THREAD#     GROUP#  SEQUENCE# STATUS
---------- ---------- ---------- ----------------
         1          1          5 ACTIVE
         1          2          6 CURRENT
         2          3          3 CURRENT
         2          4          2 INACTIVE
         1          5          4 INACTIVE

(3) 關閉資料庫,刪除控制檔案
RACDB1>shutdown abort;
RACDB2>shutdown abort;

ASMCMD> pwd
+rac_disk/racdb/controlfile
ASMCMD> ls
Current.256.794232615
ASMCMD> rm *

(4) 啟動資料庫,無控制檔案,所以只能到nomount
RACDB1>startup
ORACLE instance started.

Total System Global Area  184549376 bytes
Fixed Size                  2019448 bytes
Variable Size             142610312 bytes
Database Buffers           37748736 bytes
Redo Buffers                2170880 bytes
ORA-00205: error in identifying control file, check alert log for more info    

(5) 恢復控制檔案
RMAN> restore controlfile from '+RAC_DISK/racdb/backupset/2012_09_28/ncnnf0_tag20120928t003933_0.272.795141579';

RACDB1>alter database mount;

Database altered.

RACDB1>SELECT thread#,group#,sequence#,status FROM V$log;

   THREAD#     GROUP#  SEQUENCE# STATUS
---------- ---------- ---------- ----------------
         1          1          2 CURRENT
         1          2          0 UNUSED
         1          5          1 INACTIVE
         2          4          0 UNUSED
         2          3          1 CURRENT

(6) 恢復資料庫
先使用auto,恢復到current聯機日誌,oracle會提示找不到歸檔,這時候需要自己手動輸入聯機日誌。如下:
RACDB1>recover database using backup controlfile;
ORA-00279: change 1185078 generated at 09/28/2012 00:40:37 needed for thread 1
ORA-00289: suggestion : +RAC_DISK/racdb/flashback/1_6_795092359.dbf
ORA-00280: change 1185078 for thread 1 is in sequence #6 


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
+rac_disk/racdb/onlinelog/group_2.258.794232619  --輸入RACDB1的current聯機日誌
ORA-00279: change 1185078 generated at 09/28/2012 00:40:10 needed for thread 2
ORA-00289: suggestion : +RAC_DISK/racdb/flashback/2_2_795092359.dbf
ORA-00280: change 1185078 for thread 2 is in sequence #2     


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
+rac_disk/racdb/onlinelog/group_4.266.794234285  --這個不是RACDB2的current聯機日誌,其實也可以輸入歸檔。
ORA-00279: change 1185082 generated at 09/28/2012 00:40:38 needed for thread 2
ORA-00289: suggestion : +RAC_DISK/racdb/flashback/2_3_795092359.dbf
ORA-00280: change 1185082 for thread 2 is in sequence #3
ORA-00278: log file '+rac_disk/racdb/onlinelog/group_4.266.794234285' no longer
needed for this recovery


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
+rac_disk/racdb/onlinelog/group_3.265.794234279   --這個是RACDB2的current聯機日誌
Log applied.
Media recovery complete.
總結:RAC環境下,要使用current聯機日誌時,必須要用的每個節點的聯機日誌。

(7) 開啟資料庫,以resetlogs方式。
RACDB1>alter database open resetlogs;

Database altered.

RACDB2>startup
ORACLE instance started.

Total System Global Area  184549376 bytes
Fixed Size                  2019448 bytes
Variable Size             138416008 bytes
Database Buffers           41943040 bytes
Redo Buffers                2170880 bytes
Database mounted.
Database opened.

RACDB1>select count(*) from test2;

  COUNT(*)
----------
        11

 

二:用noresetlogs方法重建控制檔案
(1) 備份控制文

RMAN> backup current controlfile;

(2) 切換日誌和運算元據
RACDB1>alter system switch logfile;

System altered.

RACDB1>create table test3 as select * from dba_data_files;

Table created.

RACDB1>alter system switch logfile;

System altered.

(3) 關閉資料庫,刪除控制檔案
RACDB1>shutdown abort
RACDB2>shutdown abort

ASMCMD> pwd
+rac_disk/racdb/controlfile
ASMCMD> ls
Current.256.795142367
ASMCMD> rm *

RACDB1>startup
ORACLE instance started.

Total System Global Area  184549376 bytes
Fixed Size                  2019448 bytes
Variable Size             146804616 bytes
Database Buffers           33554432 bytes
Redo Buffers                2170880 bytes
ORA-00205: error in identifying control file, check alert log for more info

(4) 恢復控制檔案
RMAN> restore controlfile from '+RAC_DISK/racdb/backupset/2012_09_28/ncnnf0_tag20120928t015109_0.285.795145873';

RACDB1>alter database mount;

Database altered.

RACDB1>alter database backup controlfile to trace;    --把控制檔案備份到trace檔案

Database altered.

(5) 重建控制檔案。
RACDB1>shutdown immediate
刪除控制檔案。
RACDB1>startup nomount;

(6) 用noresetlogs方式重建控制檔案
由於是RAC環境,所以先需要修改如下引數:

不修改引數報錯如下:
ORA-01503: CREATE CONTROLFILE failed
ORA-12720: operation requires database is in EXCLUSIVE mode


RACDB1>alter system set cluster_database=FALSE scope=spfile sid='*';

System altered.

RACDB1>shutdown immediate
ORA-01507: database not mounted


ORACLE instance shut down.
RACDB1>startup nomount;
ORACLE instance started.

Total System Global Area  184549376 bytes
Fixed Size                  2019448 bytes
Variable Size             146804616 bytes
Database Buffers           33554432 bytes
Redo Buffers                2170880 bytes

CREATE CONTROLFILE REUSE DATABASE "RACDB" NORESETLOGS  ARCHIVELOG
    MAXLOGFILES 192
    MAXLOGMEMBERS 3
    MAXDATAFILES 1024
    MAXINSTANCES 32
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 (
    '+RAC_DISK/racdb/onlinelog/group_1.257.795091225',
    '+RAC_DISK/racdb/onlinelog/group_1.295.795091229'
  ) SIZE 50M,
  GROUP 2 '+RAC_DISK/racdb/onlinelog/group_2.258.794232619'  SIZE 50M,
  GROUP 3 '+RAC_DISK/racdb/onlinelog/group_3.265.794234279'  SIZE 50M,
  GROUP 4 '+RAC_DISK/racdb/onlinelog/group_4.266.794234285'  SIZE 50M,
  GROUP 5 (
    '+RAC_DISK/racdb/onlinelog/group_5.269.795092365',
    '+RAC_DISK/racdb/onlinelog/group_5.296.795092369'
  ) SIZE 100M
-- STANDBY LOGFILE
DATAFILE
  '+RAC_DISK/racdb/datafile/system.259.794232627',
  '+RAC_DISK/racdb/datafile/undotbs1.260.794232647',
  '+RAC_DISK/racdb/datafile/sysaux.261.794232657',
  '+RAC_DISK/racdb/datafile/undotbs2.263.794232675',
  '+RAC_DISK/racdb/datafile/users.264.794232683'
CHARACTER SET ZHS16GBK
;
 27 
CREATE CONTROLFILE REUSE DATABASE "RACDB" NORESETLOGS  ARCHIVELOG
*
ERROR at line 1:
ORA-01503: CREATE CONTROLFILE failed
ORA-01276: Cannot add file +RAC_DISK/racdb/controlfile/current.256.795146237.
File has an Oracle Managed Files file name.   -–由於使用OMF方式,所以需先在引數檔案中註釋掉controlfile。

RACDB1>show parameter control_files

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
control_files                        string      +RAC_DISK/racdb/controlfile/cu
                                                 rrent.256.795146237
RACDB1>alter system set control_files=false scope=spfile sid='*';

System altered.

RACDB1>alter system reset control_files scope=spfile sid='*';

System altered.

RACDB1>shutdown immediate;
ORA-01507: database not mounted


ORACLE instance shut down.
RACDB1>startup nomount;
ORACLE instance started.

Total System Global Area  184549376 bytes
Fixed Size                  2019448 bytes
Variable Size             146804616 bytes
Database Buffers           33554432 bytes
Redo Buffers                2170880 bytes
RACDB1>show parameter control_files

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
control_files                        string      /u01/app/oracle/product/10.2.0
                                                 /db_1/dbs/cntrlRACDB1.dbf
CREATE CONTROLFILE REUSE DATABASE "RACDB" NORESETLOGS  ARCHIVELOG
    MAXLOGFILES 192
    MAXLOGMEMBERS 3
    MAXDATAFILES 1024
    MAXINSTANCES 32
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 (
    '+RAC_DISK/racdb/onlinelog/group_1.257.795091225',
    '+RAC_DISK/racdb/onlinelog/group_1.295.795091229'
  ) SIZE 50M,
  GROUP 2 '+RAC_DISK/racdb/onlinelog/group_2.258.794232619'  SIZE 50M,
  GROUP 3 '+RAC_DISK/racdb/onlinelog/group_3.265.794234279'  SIZE 50M,
  GROUP 4 '+RAC_DISK/racdb/onlinelog/group_4.266.794234285'  SIZE 50M,
  GROUP 5 (
    '+RAC_DISK/racdb/onlinelog/group_5.269.795092365',
    '+RAC_DISK/racdb/onlinelog/group_5.296.795092369'
  ) SIZE 100M
-- STANDBY LOGFILE
DATAFILE
  '+RAC_DISK/racdb/datafile/system.259.794232627',
  '+RAC_DISK/racdb/datafile/undotbs1.260.794232647',
  '+RAC_DISK/racdb/datafile/sysaux.261.794232657',
  '+RAC_DISK/racdb/datafile/undotbs2.263.794232675',
  '+RAC_DISK/racdb/datafile/users.264.794232683'
CHARACTER SET ZHS16GBK
 27  ;


Control file created.

RACDB1>RACDB1>show parameter control_files

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
control_files                        string      +RAC_DISK/racdb/controlfile/cu
                                                 rrent.256.795147383, +RAC_DISK
                                                 /racdb/controlfile/current.279
                                                 .795147383

RACDB1>alter system set cluster_database=true scope=spfile sid='*';   --勿忘

System altered.


(7) 恢復資料庫
RACDB1>recover database;
ORA-00279: change 1185480 generated at 09/28/2012 01:45:00 needed for thread 1
ORA-00289: suggestion : +RAC_DISK/racdb/flashback/1_1_795145477.dbf
ORA-00280: change 1185480 for thread 1 is in sequence #1


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
auto
Log applied.
Media recovery complete.

(8) 開啟資料庫
RACDB1>alter database open;

Database altered.


三:用resetlogs方法重建控制檔案。此方法恢復過程和使用備份的控制檔案類似。這裡就不在敘述。最後也需要使用resetlogs方式開啟。

 

值得注意的是,create controlfile resetlogs/noresetlogs 這兩種重建方法的卻別在於,noresetlogs重建控制檔案時,控制檔案中datafile checkpoint來自online logs中的current log頭。而用resetlogs重建控制檔案時,控制檔案中datafile checkpoint來自各資料檔案頭。

 


參考至大話oracle

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

相關文章