关于Oracle Restore Point

还原点(Restore point)是Oracle10gR2配合Flashback database推出的一个新特性。Restore point可以单独使用,也可以和Flashback database联合使用。

我们知道,Flashback database提供了一种将数据库整个的回滚到之前某个时间点的功能,相当于使用之前的某个备份做基于时间点的恢复,但是比基于时间点的恢复更有效率,因为无需执行备份数据文件的复制,只需要使用flashback log执行数据库回滚即可。也就是说,要使用flashback database功能,必须保证所需要的所有flashback log存在。flashback log存放在flashback recovery area中。由于falshback log中需要包含变更的数据块的映象,设置过长的flashback retention target,可能导致flashback recovery area空间不足。

Restore point有两种类型:Normal和Guaranteed。

Normal restore point相当于某个时间点或者SCN的一个别名。restore point的名字和对应的SCN会保存在控制文件中。创建了normal restore point后,如果需要执行flashback database/flashback table/point-in-time recovery等操作时,就可以制定目标时间点为该restore point,而不需要指定当时的SCN了。在很多关于恢复和闪回的试验中,作者都是在试验前查询系统当前的SCN,执行某些操作,然后恢复或者闪回到之前查询到的SCN。有了normal restore point后,就不再需要查询系统当前scn了,只需要创建一个有意思的normal restore point名,以后使用该名字即可。

Guaranteed restore point的功能和normal restore point的功能基本一致,也是作为SCN的一个别名。但是它还有一些和flashback database相关的特性。前面也提到,在执行flashback database到之前的某个时间点时,必须保证所需要的flashback log存在。

创建一个guaranteed restore point,可以保证能将数据库flashback到该点,即使没有系统启用flashback database日志!这是因为,在创建guaranteed restore point之后,对于任何block的第一次变更,都会将其前映象整个的记录下来。

如果系统启用了flashback database日志,那么guaranteed restore point可以保证能将数据库flashback到guaranteed restore point之后的任何时间点。

启用flashback database日志功能,需要使用alter database flashback on并且设置DB_FLASHBACK_RETENTION_TARGET参数(默认为1天)。默认情况下,会启用所有tablespace的flashback日志,也可以针对某个tablespace单独设置,如ALTER TABLESPACE tbs_3 FLASHBACK OFF。

有了Guaranteed restore point,甚至可以将数据库flashback到几天或者几个星期之前,只要flashback recovery area中空间足够。所以创建了guaranteed restore point后,需要对flashback recovery area空间保持密切的监控。

a.创建normal restore point

SQL> CREATE RESTORE POINT before_upgrade;

Restore point created.

b.创建guaranteed restore point

SQL> CREATE RESTORE POINT before_upgrade GUARANTEE FLASHBACK DATABASE;

Restore point created.

c.列举系统中已经创建的restore point

SQL> SELECT NAME, SCN, TIME, DATABASE_INCARNATION#,

GUARANTEE_FLASHBACK_DATABASE,STORAGE_SIZE

FROM V$RESTORE_POINT;

d.列举系统中已经创建的guaranteed restore point

SQL> SELECT NAME, SCN, TIME, DATABASE_INCARNATION#,

GUARANTEE_FLASHBACK_DATABASE, STORAGE_SIZE

FROM V$RESTORE_POINT

WHERE GUARANTEE_FLASHBACK_DATABASE=’YES’;

对于normal retore point,storage_size为0。而guaranteed restore point的storage_size则为保证系统能够flashback到该点所需要的记录前映象的磁盘空间。

e.删除restore point

SQL> DROP RESTORE POINT before_app_upgrade;

Restore point dropped.

 还原点是10GR2新增加的一个功能,它是建立在数据库层面上的, 跟savepoint不同. 必须在数据库处于ARCHIVELOG模式下才可以使用,主题思想是在数据库的某个时间点创建一个restore point,在随后的某个时间点可以将表或数据库falshback 到这个restore point.那么能否真正的完成flashback,依赖于创建的restore point类型和flashback要操作的对象.flashback database需要SYSDBA权限,flashback table需要 FLASHBACK ANY TABLE的权限.

    guarantee restore point for flashback database  

    guarantee restore point必须在数据库处于flashback on 的状态下,才可以定义的一中restore point,它的主题思想是保证数据库能够准确完整的flashback 到定义的 restore point. 操作依赖于flashback log和archivelog, 如果定义了guarantee restore point,那么flashback logs将不受db_recovery_retention_target参数的限制,oracle不会删除flashback log,只要flashback arae有足够的磁盘空间,oracle就会保存足够的flashback logs,满足flashback database to restore point. 

    如果数据库没有处于flashback on,那么定义一个guarantee restore point必须在database mount状态下进行.其实这个也可以理解,oracle根据定义的restore point,可以个保证database open后的归档可以不被删除.但有一点必须明确的是,guarantee restore point是针对flashback database而言的,不对flashback table起作用,为什么呢, 因为flashback table依赖于undo,如果在guarantee时间范围内,undo过期了, 那么flatable table 还是不能还原到定义的guarantee restore point.

    Normal restore point 

    普通的restore point 非常简单, 如果要flashback database,那么数据库必须处于flashback on 状态,但这个时候不一定可以flashback database到定义的restore point,oracle会根据db_recovery_retention_target自动维护创建的restore ponit和flashback logs,如果超过db_recovery_retention_target 定义的restore point,oracle会自动删除 , 无论是flashback table或者flashback database都不能完成.

    

猜你喜欢

转载自buralin.iteye.com/blog/1991695