flashback2

闪回查询:可以再你指定的时间上运行查询,查看他们那个时间上的结果。来从不想要的改变中恢复,比如错误更新一个表,用户可以指定错误之前的一个时间来运行查询获取丢失行的内容。

闪回版本查询:可以让你在一定时间间隔内查看在一个或多个表上的行的所有版本。可以获得行的不同版本的元数据,包括开始时间,结束时间,操作,事务id。这个可以用来恢复丢失的数据和审计表的改变。

闪回表:返回表之前一个时间上的状态。你可以在数据库online的时候恢复数据,在具体表上撤销改变。

闪回drop:翻转drop table操作。

这些功能,除了闪回drop全部依赖与undo数据,闪回drop依赖recyclebin。

闪回数据库提供了一个更加有效的时间点恢复方式。不像别的闪回特色,它是在物理层面操作的。当你使用闪回数据库的时候,数据文件中的内容返回到之前时间的内容。闪回数据库使用闪回日志来访问过去版本的数据块,还有一些来自归档日志文件的信息。要使用闪回数据库来修复你的数据库,你一定要或是配置数据库产生闪回日志,或是使用有保证的闪回点来保护你的数据库。


闪回查询,在行级别的恢复

下面的查询返回了在特定时间点上的雇员john的状态

SELECT * FROM EMP AS OF TIMESTAMP
   TO_TIMESTAMP('2005-04-04 09:30:00', 'YYYY-MM-DD HH:MI:SS')
   WHERE name = 'JOHN';

闪回表

闪回表提供了一个很快速的方法来恢复表到一个指定的时间。不用让数据库offline。闪回表恢复表的时候自动维护相应的属性,比如索引,触发器和约束。不需要dba的参与。闪回表会将一个或多个表的内容反转会过去scn或时间上。

闪回表适用undo表空间的信息来恢复表。不需要在备份中恢复任何数据。

闪回表一定要有flashbackup any table系统权限和flashback对象的权限。

在表上要有select,insert,delete,alter权限。

存放在undo表空间中的undo信息一定要足够长来返回到指定时间点或scn。

表上一定要启用row movement.使用alter table table enable row movement;

下面的是闪回的命令

FLASHBACK TABLE EMP TO TIMESTAMP
      TO_TIMESTAMP('2005-04-04 09:30:00', 'YYYY-MM-DD HH:MI:SS')

FLASHBACK TABLE EMP TO SCN 123456;

FLASHBACK TABLE table_name
        TO TIMESTAMP timestamp ENABLE TRIGGERS;

闪回drop

FLASHBACK TABLE "BIN$gk3lsj/3akk5hg3j2lkl5j3d==$0" TO BEFORE DROP;

FLASHBACK TABLE "BIN$KSD8DB9L345KLA==$0" TO BEFORE DROP
     RENAME TO hr.int2_admin_emp;

有相同对象名的对象的多次删除

You can create, and then drop, several objects with the same original name, and they will all be stored in the recycle bin. For example, consider these SQL statements:

CREATE TABLE EMP ( ...columns ); # EMP version 1
DROP TABLE EMP;
CREATE TABLE EMP ( ...columns ); # EMP version 2
DROP TABLE EMP;
CREATE TABLE EMP ( ...columns ); # EMP version 3
DROP TABLE EMP;

In such a case, each table EMP is assigned a unique name in the recycle bin when it is dropped. You can use a FLASHBACK TABLE... TO BEFORE DROP statement with the original name of the table, as shown in this example:

FLASHBACK TABLE EMP TO BEFORE DROP;

The most recently dropped table with that original name is retrieved from the recycle bin, with its original name. You can retrieve it and assign it a new name using a RENAME TO clause. The following example shows the retrieval from the recycle bin of all three dropped EMP tables from the previous example, with each assigned a new name:

FLASHBACK TABLE EMP TO BEFORE DROP RENAME TO EMP_VERSION_3;
FLASHBACK TABLE EMP TO BEFORE DROP RENAME TO EMP_VERSION_2;
FLASHBACK TABLE EMP TO BEFORE DROP RENAME TO EMP_VERSION_1;
PURGE TABLESPACE hr;
PURGE TABLESPACE hr USER scott;
 
 

For example, consider the following series of CREATE TABLE and DROP TABLE statements:

CREATE TABLE EMP;   # version 1 of the table
DROP TABLE EMP;     # version 1 dropped
CREATE TABLE EMP;   # version 2 of the table
DROP TABLE EMP;     # version 2 dropped
CREATE TABLE EMP;   # version 3 of the table
DROP TABLE EMP;     # version 3 dropped

There are now three EMP tables in the recycle bin. If you execute PURGE TABLE EMP several times, the effect is as described here:

PURGE TABLE EMP;    # version 1 of the table is purged
PURGE TABLE EMP;    # version 2 of the table is purged
PURGE TABLE EMP;    # version 3 of the table is purged
PURGE RECYCLEBIN;
PURGE DBA_RECYCLEBIN;
闪回数据库
如果你的数据库配置了闪回日志可以使用flashback database命令。FLASHBACK DATABASE TO RESTORE POINT 'BEFORE_CHANGES';
FLASHBACK DATABASE TO BEFORE RESETLOGS;
恢复到一个特定的生命周期

Verify that the flashback logs contain enough information to flash back to that SCN:

sql> select oldest_flashback_scn from v$flashback_database_log;

  • Determine the target incarnation number for the flashback, that is, the incarnation key for the parent incarnation:

    SQL> select prior_incarnation# from v$database_incarnation where status = 'CURRENT';
    
    
  • In RMAN, shut down the database, then mount it:

    RMAN> SHUTDOWN IMMEDIATE;
    RMAN> STARTUP MOUNT;
    
    
  • Set the database incarnation to the parent incarnation:

    RMAN> RESET DATABASE TO INCARNATION 1;
    
    
  • Run the FLASHBACK DATABASE command:

    RMAN> FLASHBACK DATABASE TO SCN 1500;
    
  • 

    你可能感兴趣的:(flashback2)