詳解using backup controlfile

來源:互聯網
上載者:User

using backup controlfile 通常用於恢複由於當前控制檔案丟失且原來備份的控制檔案較當前發生變化的情形之下。using backup controlfile

的 recover 方式一旦使用之後,常用的recover database命令將不可再使用,且必須要使用resetlogs方式來開啟資料庫,下面是具體的示範描述。


一、示範 using backup controlfile 時的相關變化

-->查看資料庫SYBO2SZ控制檔案的時間資訊

sys@SYBO2SZ> ho ls -hltr /u02/database/SYBO2SZ/controlf/

total 29M

-rw-r----- 1 oracle oinstall 9.7M 2012-09-10 11:59 cntl3SYBO2SZ.ctl

-rw-r----- 1 oracle oinstall 9.7M 2012-09-10 11:59 cntl2SYBO2SZ.ctl

-rw-r----- 1 oracle oinstall 9.7M 2012-09-10 11:59 cntl1SYBO2SZ.ctl


-->查看系統時間

sys@SYBO2SZ> ho date

Mon Sep 10 12:00:09 CST 2012


-->查看資料庫SYBO2SZ的狀態,此時資料庫處於關閉狀態

sys@SYBO2SZ> ho ps -ef | grep pmon_SYBO2SZ

oracle 440 32067 0 12:01 pts/4 00:00:00 /bin/bash -c ps -ef | grep pmon_SYBO2SZ

oracle 442 440 0 12:01 pts/4 00:00:00 grep pmon_SYBO2SZ


sys@SYBO2SZ> startup mount;

ORACLE instance started.


Total System Global Area 599785472 bytes

Fixed Size 2074568 bytes

Variable Size 381683768 bytes

Database Buffers 209715200 bytes

Redo Buffers 6311936 bytes

Database mounted.


-->當mount資料庫後,控制檔案的狀態及時間資訊被更新

sys@SYBO2SZ> ho ls -hltr /u02/database/SYBO2SZ/controlf/

total 29M

-rw-r----- 1 oracle oinstall 9.7M 2012-09-10 12:02 cntl3SYBO2SZ.ctl

-rw-r----- 1 oracle oinstall 9.7M 2012-09-10 12:02 cntl2SYBO2SZ.ctl

-rw-r----- 1 oracle oinstall 9.7M 2012-09-10 12:02 cntl1SYBO2SZ.ctl


sys@SYBO2SZ> select instance_name,status,database_status from v$instance;


INSTANCE_NAME STATUS DATABASE_STATUS

---------------- ------------ -----------------

SYBO2SZ MOUNTED ACTIVE


-->此時資料庫檔案的時間並沒有被更新,依舊為11:23

sys@SYBO2SZ> ho ls -hltr /u02/database/SYBO2SZ/oradata/sys*

-rw-r----- 1 oracle oinstall 501M 2012-09-10 11:23 /u02/database/SYBO2SZ/oradata/sysSYBO2SZ.dbf

-rw-r----- 1 oracle oinstall 301M 2012-09-10 11:23 /u02/database/SYBO2SZ/oradata/sysauxSYBO2SZ.dbf


sys@SYBO2SZ> alter session set nls_date_format='yyyymmdd hh24:mi:ss';


-->Author : Robinson Cheng -->Blog: <A href="http://blog.csdn.net/robinson_0612">http://blog.csdn.net/robinson_0612

</A>-->也可以看到此時controlfile_type為current,open_resetlogs為NOT ALLOWED

sys@SYBO2SZ> SELECT controlfile_type, controlfile_sequence#, controlfile_change#,controlfile_time,open_resetlogs

2 FROM v$database;


CONTROL CONTROLFILE_SEQUENCE# CONTROLFILE_CHANGE# CONTROLFILE_TIME OPEN_RESETL

------- --------------------- ------------------- ----------------- -----------

CURRENT 6012 1151639 20120910 04:30:14 NOT ALLOWED


-->使用帶using backup controlfile的recover 命令,出現Specify log提示

-->此時再開另一個session串連到執行個體,下面以idle開頭的sql提示符即為另一個session

sys@SYBO2SZ> recover database using backup controlfile;

ORA-00279: change 1160803 generated at 09/10/2012 11:23:59 needed for thread 1

ORA-00289: suggestion : /u02/database/SYBO2SZ/archive/arch_793474012_1_3.arc

ORA-00280: change 1160803 for thread 1 is in sequence #3



Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

cancel

Media recovery cancelled.


-->session2 的操作

idle> conn / as sysdba

Connected.

idle> alter session set nls_date_format='yyyymmdd hh24:mi:ss';


Session altered.


-->下面的查詢在使用recover database using backup controlfile後此時controlfile_type為BACKUP

-->且open_resetlogs為REQUIRED,相應的sequence以及change#全部發生了變化

idle> SELECT controlfile_type, controlfile_sequence#, controlfile_change#,controlfile_time,open_resetlogs

2 FROM v$database;


CONTROL CONTROLFILE_SEQUENCE# CONTROLFILE_CHANGE# CONTROLFILE_TIME OPEN_RESETL

------- --------------------- ------------------- ----------------- -----------

BACKUP 6014 1160803 20120910 11:23:59 REQUIRED


-->上面的查詢完成後,輸入cancel,提示Media recovery cancelled

-->嘗試使用open方式開啟資料庫,提示必須使用RESETLOGS or NORESETLOGS選項

sys@SYBO2SZ> alter database open;

alter database open

*

ERROR at line 1:

ORA-01589: must use RESETLOGS or NORESETLOGS option for database open


-->使用resetlogs選項開啟資料庫,注意,此時如果使用noresetlogs選項,會重複出現上述提示

-->此時提示file1需要介質恢複

sys@SYBO2SZ> alter database open resetlogs;

alter database open resetlogs

*

ERROR at line 1:

ORA-01113: file 1 needs media recovery

ORA-01110: data file 1: '/u02/database/SYBO2SZ/oradata/sysSYBO2SZ.dbf'


-->根據recover的提示,查看arch_793474012_1_3.arc檔案,此時檔案並不存在

sys@SYBO2SZ> ho ls -hltr /u02/database/SYBO2SZ/archive/arch_793474012_1_3.arc

ls: /u02/database/SYBO2SZ/archive/arch_793474012_1_3.arc: No such file or directory


-->再次嘗試恢複,依然提示需要arch_793474012_1_3.arc歸檔日誌,此時在session2中查看狀態資訊

sys@SYBO2SZ> recover database using backup controlfile;

ORA-00279: change 1160803 generated at 09/10/2012 11:23:59 needed for thread 1

ORA-00289: suggestion : /u02/database/SYBO2SZ/archive/arch_793474012_1_3.arc

ORA-00280: change 1160803 for thread 1 is in sequence #3


-->將組3的聯機日誌路徑複製到Specify log處實現完全恢複

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

/u02/database/SYBO2SZ/redolog/log3aSYBO2SZ.log

Log applied.

Media recovery complete.


-->session2

-->可以看到控制檔案的sequence#發生了幾次變化

idle> SELECT controlfile_type, controlfile_sequence#, controlfile_change#,controlfile_time,open_resetlogs

2 FROM v$database;


CONTROL CONTROLFILE_SEQUENCE# CONTROLFILE_CHANGE# CONTROLFILE_TIME OPEN_RESETL

------- --------------------- ------------------- ----------------- -----------

BACKUP 6014 1160803 20120910 11:23:59 REQUIRED


idle> /


CONTROL CONTROLFILE_SEQUENCE# CONTROLFILE_CHANGE# CONTROLFILE_TIME OPEN_RESETL

------- --------------------- ------------------- ----------------- -----------

BACKUP 6015 1160803 20120910 11:23:59 REQUIRED


-->查看當前聯機日誌資訊

idle> select * from v$logfile;


GROUP# STATUS TYPE MEMBER IS_

---------- ------- ------- ------------------------------------------------------- ---

3 ONLINE /u02/database/SYBO2SZ/redolog/log3aSYBO2SZ.log NO

3 ONLINE /u02/database/SYBO2SZ/redolog/log3bSYBO2SZ.log NO

4 ONLINE /u02/database/SYBO2SZ/redolog/log4aSYBO2SZ.log NO

4 ONLINE /u02/database/SYBO2SZ/redolog/log4bSYBO2SZ.log NO


-->此時日誌組3為current狀態,因此將組3的聯機日誌路徑複製到Specify log處實現完全恢複

idle> select * from v$log;


GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIME

---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- -----------------

4 1 2 20971520 2 YES INACTIVE 1124329 20120909 09:00:49

3 1 3 20971520 2 NO CURRENT 1150957 20120910 04:00:06


-->完全恢複成功後,使用open方式依舊不成功

sys@SYBO2SZ> alter database open;

alter database open

*

ERROR at line 1:

ORA-01589: must use RESETLOGS or NORESETLOGS option for database open


-->使用open resetlogs方式成功開啟資料庫

sys@SYBO2SZ> alter database open resetlogs;


Database altered.


-->session 2

-->此時session 2中controlfile_type已經被置為CURRENT,open_resetlogs方式也被置為NOT ALLOWED

idle> SELECT controlfile_type, controlfile_sequence#, controlfile_change#,controlfile_time,open_resetlogs

2 FROM v$database;


CONTROL CONTROLFILE_SEQUENCE# CONTROLFILE_CHANGE# CONTROLFILE_TIME OPEN_RESETL

------- --------------------- ------------------- ----------------- -----------

CURRENT 6073 1160878 20120910 12:09:58 NOT ALLOWED


-->查看資料檔案的時間資訊,此時已被更新到最新狀態

sys@SYBO2SZ> ho ls -hltr /u02/database/SYBO2SZ/oradata/sys*

-rw-r----- 1 oracle oinstall 501M 2012-09-10 12:09 /u02/database/SYBO2SZ/oradata/sysSYBO2SZ.dbf

-rw-r----- 1 oracle oinstall 301M 2012-09-10 12:09 /u02/database/SYBO2SZ/oradata/sysauxSYBO2SZ.dbf


sys@SYBO2SZ> ho date

Mon Sep 10 12:10:42 CST 2012


-->相應的新的incarnation已經產生

sys@SYBO2SZ> archive log list;

Database log mode Archive Mode

Automatic archival Enabled

Archive destination /u02/database/SYBO2SZ/archive/

Oldest online log sequence 1

Next log sequence to archive 1

Current log sequence 1



二、總結

1、using backup controlfile用於恢複備份的控制檔案與當前的控制檔案不一致的情形

2、一旦使用了using backup controlfile方式,控制檔案的類型將由 current 轉移到 backup 類型,同時open_resetlogs為required

3、一旦使用了using backup controlfile方式,後續再次使用recover database將變得無效

4、必須要使用 resetlogs 方式開啟資料庫,即使我們做的是完全恢複

5、注意理解示範中時間狀態的更新情況。實際上來說是執行個體的啟動過程,即:

nomount: 根據pfile 或 spfile 啟動相關後台進程,分配SGA

mount: 開啟控制檔案,檢查控制檔案狀態一致性,將資料庫與執行個體關聯起來

open: 根據控制檔案中記錄的資料檔案記錄檔對其進行逐一檢查無誤後,整個資料庫置於open狀態


oracle視頻教程請關注:http://u.youku.com/user_video/id_UMzAzMjkxMjE2.html

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.