Oracle RESETLOGS 和 NORESETLOGS 区别说明

在网上看的,感觉挺好,收藏啦。呵呵

一.创建控制文件时:Resetlogs和Noresetlogs
当我们将控制文件备份到trace 文件时,可以看到里面包含了2部分的重建语句,一个是使用resetlogs,另一个是使用noresetlogs。



备份控制文件的SQL 如下:

SQL>alterdatabase backup controlfile to trace



有关控制文件的详细说明,参考:

Oracle 控制文件

http://blog.csdn.net/tianlesoftware/article/details/4974440





Set #1. NORESETLOGS case
The followingcommands will create a new control file and use it to open the database. Dataused by Recovery Manager will be lost.

Additional logsmay be required for media recovery of offline.

Use this only ifthe current versions of all online logs are available.

--使用noresetlogs仅是当前所有的online logs可用时。

     

Set #2. RESETLOGS case
The followingcommands will create a new control file and use it to open the database. Dataused by Recovery Manager will be lost.

The contents ofonline logs will be lost and all backups will be invalidated. Use this only ifonline logs are damaged.

--使用resetlogs,将导致online logs里的内容丢失,并且所有的备份失效,仅当online logs 随坏的情况下,才使用resetlos模式。





CREATE CONTROLFILE REUSE DATABASE"DAVE" RESETLOGS/NORESETLOGS  ARCHIVELOG

    MAXLOGFILES 16

    MAXLOGMEMBERS 2

    MAXDATAFILES 30

    MAXINSTANCES 1

    MAXLOGHISTORY 292

LOGFILE

  GROUP 1'/u01/app/oracle/oradata/dave/redo01.log'  SIZE 50M,

  GROUP 2'/u01/app/oracle/oradata/dave/redo02.log'  SIZE 50M,

  GROUP 3'/u01/app/oracle/oradata/dave/redo03.log'  SIZE 50M

-- STANDBY LOGFILE

DATAFILE

  '/u01/app/oracle/oradata/dave/system01.dbf',

  '/u01/app/oracle/oradata/dave/undotbs01.dbf',

  '/u01/app/oracle/oradata/dave/sysaux01.dbf',

  '/u01/app/oracle/oradata/dave/users01.dbf'

CHARACTER SET ZHS16GBK

;



二.打开数据库时:Resetlogs 和Noresetlogs


2.1 说明
Use RESETLOGSafter incomplete recovery (when the entire redo stream wasn't applied).RESETLOGS will initialize the logs, reset your log sequence number, and start anew "incarnation" of the database.
       --RESETLOGS会初始化logs,重置log sequence号,创建一个新的incarnation。



Use NORESETLOGSwhen doing complete recovery (when the entire redo stream was applied). Oraclewill continue using the existing (valid) log files.

--NORESETLOGS 会继续使用已经存在,且有效的log files。



可以使用RMAN命令查看incarnation的信息:

RMAN> list incarnation;



更多内容参考:

RMAN 系列(八)---- RMAN List和report命令

http://blog.csdn.net/tianlesoftware/article/details/5728116



Oracle Rman跨resetlogs版本恢复

http://blog.csdn.net/tianlesoftware/article/details/4682463



做不完全恢复必须使用resetlogs, resetlogs也可以做完全恢复。而noresetlogs则是必须做完全恢复时使用。resetlogs会重置日志序列号强制清空或重建REDO,而noresetlogs则不会这么做。





2.2 MOS 上对这个RESETLOGS和NORESETLOGS的说明:
Physical Backup and Recovery: An Insider'sPerspective [ID 16530.1]:



After recoverdatabase operation, open the database with: ALTER DATABASE OPEN [NO]RESETLOGS



(1)    NORESETLOGS

The NORESETLOGSoption does not clear the redo log files during startup and the online redologs to be used for recovery. Only used in scenario where MANUAL RECOVERY isstarted, CANCEL is used, and then RECOVER DATABASE is started.

(2)RESETLOGS



CAUTION: Never use RESETLOGS unlessnecessary.



Once RESETLOGS is used then the redo logfiles cannot be used and any completed transactions in those redo logs arelost!!



Before using the RESETLOGS option take anoffline backup of the database.



The RESETLOGSoption clears all the online redo logs and modifies all the online data filesto indicate no recovery is needed. After resetting the redo logs none of theexisting log files or data file backups can be used.



In the control file, the log sequence number is modified,which is very important for recovery purposes. Therecovery will be applied only to the log files whose sequence number is greaterthan log sequence number in the control file. One has to be very cautious whenusing RESETLOGS option. It is important to remember that all datafiles must beonline otherwise they will become useless once the database is up。





2.3 几种情况的说明


(1)    第一种情况

假设仅仅控制文件丢失,而其他文件没有丢失(主要是归档和REDO),那么恢复的时候如果选择从备份中恢复控制文件。恢复后,控制文件会去读数据文件头中与CHECKPOINT SCN对应的RBA信息来确定从那个序列的归档日志开始恢复,一直推进恢复到NEXT SCN是无穷大的那个REDOLOG,此时恢复是完全恢复的,但打开的时候还要以resetlogs方式打开,这样要重置归档日志的sequence,也就是说,如果你恢复时使用了备份控制文件,那么打开数据库时必然是要resetlogs的。



不完全恢复时是必须RESETLOGS,但是完全恢复时如果使用备份控制文件来恢复,那么使用RESETLOGS一样可以完全恢复。但是丢失控制文件也可以不使用RESETLOGS方式打开数据库,这样也就可以避免重置日志序列号带来的不变,详情请见第四种情况。



(2)    第二种情况

不完全恢复,不管是要什么样的不完全恢复,SCN,TIME,跨越REDO,都必须使用resetlogs。




(3)    第三种情况

丢失REDOLOG,这就更需要resetlogs了,因为resetlogs能够重建REDOLOG。如果你的REDOLOG、控制文件、数据文件丢失的话,需要先恢复控制文件,然后restore database;recover database;alter database open resetlogs;

注意,这时候做的是不完全恢复,因为REDO没有了。在recover过程中可能会报错然后自动退出RMAN,无视,alter database open resetlogs即可,



(4)    第四种情况

没有丢失控制文件及各种日志,仅丢失数据文件,这种问题比较常见,有可能磁盘损坏造成数据文件丢失,等磁盘故障排除后,需要恢复,此时的恢复就很简单了,restore database;recover database;alter database open;就一切OK,也就是说,在不使用备份控制文件恢复的情况下,是可以使用noresetlog方式打开数据库的。

前提有一,不能丢失日志文件。假若丢失了控制文件和数据文件但还是想以noresetlog打开的话,就必须手动以noresetlogs方式重建控制文件,而且REDOLOG的状态都必须正常,否则是无法使用noresetlogs方式打开。



几种情况的分析转自一下Blog:

http://space.itpub.net/16628454/viewspace-524593

猜你喜欢

转载自andyniu.iteye.com/blog/1766226