1>oracle在什么情况下执行undo,在什么情况下执行redo?
  我现在的理解是手工操作的时候可以直接执行redo,undo是在打开数据库时就自动执行的。  这里有一个案例,某校一卡通的数据库故障了,
  在打开一个数据库的时候出现了如下的错误:
SQL> startup force;
ORACLE instance started.Total System Global Area 1073741824 bytes
Fixed Size                  1223488 bytes
Variable Size             192939200 bytes
Database Buffers          872415232 bytes
Redo Buffers                7163904 bytes
Database mounted.
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: '/oradata/syntong/system01.dbf'
我的恢复过程如下
[oracle@database1 ~]$ sqlplus / as sysdbaSQL*Plus: Release 10.2.0.1.0 - Production on Sun Jan 18 14:32:18 2009Copyright (c) 1982, 2005, Oracle.  All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining optionsSQL> recover database until cancel using backup controlfile;  
ORA-00279: change 33318587 generated at 01/18/2009 03:21:47 needed for thread 1
ORA-00289: suggestion :
/oradata/flash_recovery_area/SYNTONG/archivelog/2009_01_18/o1_mf_1_5_%u_.arc
ORA-00280: change 33318587 for thread 1 is in sequence #5
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/oradata/syntong/redo01.log
Log applied.
Media recovery complete.
2>为什么此处可以选择archive 也可以选择 redo来进行recovery?3>因为控制文件是backup的 老的 controlfile,所以在进行恢复的时候只有采用不完全恢复的方式。(是否正确?)
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
不完全恢复(incomplete recovery),也被称为按时间点恢复(point-in-time recovery),指没有将数据库恢复到当前时间点的恢复。换句话说,用户没有将最近一次备份之后产生的所有重做日志应用到复原的数据库上。用户通常在下列情况出现时对数据库进行不完全恢复: 
介质故障(media failure)导致部分或全部联机重做日志(online redo log)损坏。 
用户操作失误(user error)导致数据丢失,例如,用户由于疏忽而移除了表。 
由于归档重做日志(archived redo log)丢失而无法进行完全恢复(complete recovery)。 
当前控制文件(control file)丢失,必须使用备份的控制文件打开(open)数据库
执行不完全介质恢复(incomplete media recovery)时,用户需要使用指定恢复时间点之前的备份复原(restore)数据文件,并在恢复(recovery)结束打开(open)数据库时使用 RESETLOGS 选项。RESETLOGS 选项的含义是使当前的数据库及重做日志有效,即令数据库使用一套新的日志序列号(从 1 开始)。摘自oracle coceptes 15章 Backup and Recovery
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
SQL> alter database open resetlogs;Database altered.SQL> select count(*) from tabs;    COUNT(*)
----------
       703到此数据库成功recover和restore,
但我是采用alter database open resetlogs方式打开库的,之前的理解是
alter database open resetlogs直接把数据库里所有的文件块scn清到一个初始值。
我想问这个操作有没有把undo里面的数据也写回数据块了。
否则文件的一致性就会有问题啊  ?4.>undo 的问题: 在进行数据库的redolog应用后,是否自动执行undo操作?
来维持一致性?
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
15.2.4.1.2 事务恢复概述 
151 You can run Oracle in either manual undo management mode or automatic undo management mode. In manual mode, you must create and manage rollback segments to record the before-image of changes to the database. In automatic undo management mode, you create one or more undo tablespaces. These undo tablespaces contain undo segments similar to traditional rollback segments. The main difference is that Oracle manages the undo for you.
  Oracle 可以运行在手工还原管理模式(manual undo management mode)或自动还原管理模式(automatic undo management mode)下。在手工模式下,用户需要手工管理用于记录数据修改前副本(before-image)的回滚段(rollback segment)。而在自动管理模式下,用户需要创建一个或多个还原表空间(undo tablespace)。还原表空间内的还原段(undo segment)与传统的回滚段类似。这两种模式的主要区别是,在自动还原管理模式下,还原信息由 Oracle 负责管理。
  
152 Undo blocks (whether in rollback segments or automatic undo tablespaces) record database actions that should be undone during certain database operations. In database recovery, the undo blocks roll back the effects of uncommitted transactions previously applied by the rolling forward phase.
  无论是回滚段还是自动还原表空间,都使用还原块(undo block)来记录有可能被还原的数据库信息。在数据库恢复(recovery)中,需要利用还原块回滚(roll back)在前滚(rolling forward)时被应用到数据文件的未提交事务。
  
153 After the roll forward, any changes that were not committed must be undone. Oracle applies undo blocks to roll back uncommitted changes in data blocks that were either written before the failure or introduced by redo application during cache recovery. This process is called rolling back or transaction recovery.
  在前滚后,所有未提交的修改必须被还原。Oracle 利用还原块来回滚数据块中未提交的修改,这些修改可能是在故障前被写入数据文件的,也可能是在缓存恢复(cache recovery)时被写入数据文件的。上述过程被称为回滚(rolling back)或事务恢复(transaction recovery)。 
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5>rman是否备份redo?
我进行rman进行还原的时候,为什么rman的备份中恢复的数据是看不到备份的redo的?6>对于rman的理解:rman进行备份,备份出来的数据块都是具有一致性scn的,从下可以看出。(求证是否如此)
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
15.1.3.1 使用 RMAN 进行联机备份 
063 Because the database continues writing to the file during an online backup, there is the possibility of backing up inconsistent data within a block. For example, assume that either RMAN or an operating system utility reads the block while database writer is in the middle of updating the block. In this case, RMAN or the copy utility could read the old data in the top half of the block and the new data in the bottom top half of the block. The block is a fractured block, meaning that the data in this block is not consistent.
  在联机备份(online backup)期间数据库仍会向数据文件中写入数据,因此备份中可能存在含有非一致性(inconsistent)数据的数据块(data block)。例如,RMAN 或操作系统工具在读取数据块的同时,数据库写进程可能会更新相同的数据块。此时,RMAN 或复制工具读取的数据块中既包含新数据,又包含旧数据。这样的数据块是无效块(fractured block),即块内的数据不具备一致性。
  
064 During an RMAN backup, the Oracle database server reads the datafiles, not an operating system utility. The server reads each block and determines whether the block is fractured. If the block is fractured, then Oracle re-reads the block until it gets a consistent picture of the data.
  在使用 RMAN 进行备份时,是 Oracle 数据库服务器而非操作系统工具负责读取数据文件(datafile)。数据库服务器逐一读取数据块并判断其是否有效。如果数据块是无效的,Oracle 会再次读取直道获得了具备一致性的数据块为止。
  
065 When you back up an online datafile with an operating system utility (rather than with RMAN), you must use a different method to handle fractured blocks. You must first place the files in backup mode with the ALTER TABLESPACE BEGIN BACKUP statement (to back up an individual tablespace), or the ALTER DATABASE BEGIN BACKUP statement (to back up the entire database). After an online backup is completed, you must run the ALTER TABLESPACE ... END BACKUP or ALTER DATABASE END BACKUP statement to take the tablespace out of backup mode.
  如果用户使用操作系统工具(而非 RMAN)备份联机数据,则需采用另一种方式解决无效块的问题。用户需要首先使用 ALTER TABLESPACE BEGIN BACKUP 语句(备份单独的表空间)或 ALTER DATABASE BEGIN BACKUP 语句(备份整个数据库)将数据文件置为备份模式(backup mode)。在联机备份结束后,再使用 ALTER TABLESPACE ... END BACKUP 或 ALTER DATABASE END BACKUP 将相关的数据文件恢复原状态。
  
066 When updates are made to files in backup mode, additional redo data is logged. This additional data is needed to repair fractured blocks that might be backed up by the operating system utility.
  当数据库对处于备份模式的文件进行修改操作时,系统会记录额外的重做数据(redo data)。这些数据用于修复操作系统工具备份中可能包含的无效块。
  |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

解决方案 »

  1.   

    1>oracle在什么情况下执行undo,在什么情况下执行redo? 
    据我理解,redo执行的是重做日志,undo执行的回滚操作2>为什么此处可以选择archive 也可以选择 redo来进行recovery? 
    我认为一个归档模式下备份的还原,另一个是非归档模式下的还原.....
      

  2.   

    谢谢楼上的
    1》redo, undo 已经基本搞清楚了
    redo是做前滚操作(roll forward),把所有做过的再做一次,
    undo在redo之后做回滚操作(roll back),把所有未提交的操作恢复。(具体是oracle写一个数据的时候,都会把他原来的内容放到undo下,最后如果oracle发现这个写操作没有commit,将把undo的数据写回去提交)
      

  3.   

    今天请教了下公司的有经验的DBA,针对后面几个问题,他给了我一些参考意见 ,
    3>因为控制文件是backup的 老的 controlfile,所以在进行恢复的时候只有采用不完全恢复的方式。(是否正确?) 
    正确
    当前控制文件(control file)丢失,必须使用备份的控制文件打开(open)数据库 
    使用的恢复,只有采用不完全恢复的方式来进行。4.>undo 的问题: 在进行数据库的redolog应用后,是否自动执行undo操作? 
    来维持一致性
    是会自动执行的,oracle有个机制,不需要手工来做。5>rman是否备份redo? 
    我进行rman进行还原的时候,为什么rman的备份中恢复的数据是看不到备份的redo的? 
    rman只备份归档日志,不备份联机日志6>对于rman的理解:rman进行备份,备份出来的数据块都是具有一致性scn的,从下可以看出。(求证是否如此)
    对于文档中这段话,
    If the block is fractured, then Oracle re-reads the block until it gets a consistent picture of the data. 数据库服务器逐一读取数据块并判断其是否有效。如果数据块是无效的,Oracle 会再次读取直道获得了具备一致性的数据块为止。 他也不知道这个一致性数据块是什么意思。我对第5,第6还是有点怀疑,准备再查下资料问下高人
      

  4.   

    5,rman不备份redo log,所以每次备份前,建议执行alter system archive log current
       将redo log归档;
    6,rman可以只备份更改过的数据块,这就是rman的优点,可以节省磁盘空间。
       数据块在被更新时,才被赋予一个scn值。因此rman才可以根据备份级别备份符合条件的
       数据块。
       你那里所谓的一致性,是指用于恢复数据库,保持数据库一致性的备份集。
      

  5.   


    谢谢指教,
    数据块的一致性是什么意思?我还是不是很懂。就是这句话
    During an RMAN backup, the Oracle database server reads the datafiles, not an operating system utility. The server reads each block and determines whether the block is fractured. If the block is fractured, then Oracle re-reads the block until it gets a consistent picture of the data. 
      在使用 RMAN 进行备份时,是 Oracle 数据库服务器而非操作系统工具负责读取数据文件(datafile)。数据库服务器逐一读取数据块并判断其是否有效。如果数据块是无效的,Oracle 会再次读取直道获得了具备一致性的数据块为止
     这个一致性是指block的一致性,好像datafile下面的单位是segement,再下面的单位就是blocks,这里的block一致性到底是什么意思?