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