Oracle Flashback Query : SELECT AS OF
Oracle Flashback Version Query :
DBMS_FLASHBACK Package
Oracle Flashback Table:
Oracle Flashback Drop:
Oracle Flashback Database:
http://docs.oracle.com/cd/B28359_01/backup.111/b28270/rcmflash.htm#i1018669

Oracle Flashback Query : SELECT AS OF
Oracle Flashback Version Query :
  SELECT versions_startscn, versions_starttime,
       versions_endscn, versions_endtime,
       versions_xid, versions_operation,
       name, salary
  FROM employees
  VERSIONS BETWEEN TIMESTAMP
      TO_TIMESTAMP('2003-07-18 14:00:00', 'YYYY-MM-DD HH24:MI:SS')
  AND TO_TIMESTAMP('2003-07-18 17:00:00', 'YYYY-MM-DD HH24:MI:SS')
  WHERE name = 'JOE';
 
Flashback Transaction Query (与Flashback Version Query联合查询)
  SELECT xid, logon_user
  FROM flashback_transaction_query
    WHERE xid IN (
      SELECT versions_xid FROM employees VERSIONS BETWEEN TIMESTAMP
        TO_TIMESTAMP('2003-07-18 14:00:00', 'YYYY-MM-DD HH24:MI:SS') AND
          TO_TIMESTAMP('2003-07-18 17:00:00', 'YYYY-MM-DD HH24:MI:SS')
    );

DBMS_FLASHBACK Package

Flashback Transaction :Flashback Transaction is part of DBMS_FLASHBACK package

Flashback Data Archive (Oracle Total Recall):
   
    Create table employee and store the historical data in the default Flashback Data Archive:

CREATE TABLE employee (EMPNO NUMBER(4) NOT NULL, ENAME VARCHAR2(10),
      JOB VARCHAR2(9), MGR NUMBER(4)) FLASHBACK ARCHIVE;

Create table employee and store the historical data in the Flashback Data Archive fla1:

CREATE TABLE employee (EMPNO NUMBER(4) NOT NULL, ENAME VARCHAR2(10),
      JOB VARCHAR2(9), MGR NUMBER(4)) FLASHBACK ARCHIVE fla1;

Enable flashback archiving for the table employee and store the historical data in the default Flashback Data Archive:

ALTER TABLE employee FLASHBACK ARCHIVE;

Enable flashback archiving for the table employee and store the historical data in the Flashback Data Archive fla1:

ALTER TABLE employee FLASHBACK ARCHIVE fla1;

Disable flashback archiving for the table employee:

ALTER TABLE employee NO FLASHBACK ARCHIVE;

Oracle Flashback Table:

Connect SQL*Plus to the target database and identify the current SCN.

You cannot roll back a FLASHBACK TABLE statement, but you can issue another FLASHBACK TABLE statement and specify a time just prior to the current time. Therefore, it is advisable to record the current SCN. You can obtain it by querying V$DATABASE as follows:

SELECT CURRENT_SCN
    FROM   V$DATABASE;

Identify the time, SCN, or restore point to which you want to return the table.

If you have created restore points, then you can list available restore points by executing the following query:

SELECT NAME, SCN, TIME
    FROM   V$RESTORE_POINT;

Ensure that enough undo data exists to rewind the table to the specified target.

If the UNDO_RETENTION intialization parameter is set, and the undo retention guarantee is on, then you can use the following query to determine how long undo data is being retained:

SELECT NAME, VALUE/60 MINUTES_RETAINED
    FROM   V$PARAMETER
    WHERE  NAME = 'undo_retention';

Ensure that row movement is enabled for all objects that you are rewinding with Flashback Table.

You can enable row movement for a table with the following SQL statement, where table is the name of the table that you are rewinding:

ALTER TABLE table ENABLE ROW MOVEMENT;

Determine whether the table that you intend to flash back has dependencies on other tables. If dependencies exist, then decide whether to flash back these tables as well.

You can issue the following SQL query to determine the dependencies, where schema_name is the schema for the table to be flashed back and table_name is the name of the table:

SELECT other.owner, other.table_name
    FROM   sys.all_constraints this, sys.all_constraints other
    WHERE  this.owner = schema_name
    AND    this.table_name = table_name
    AND    this.r_owner = other.owner
    AND    this.r_constraint_name = other.constraint_name
    AND    this.constraint_type='R';

Execute a FLASHBACK TABLE statement for the objects that you want to flash back.

The following SQL statement returns the hr.temp_employees table to the restore point named temp_employees_update:

FLASHBACK TABLE hr.temp_employees
      TO RESTORE POINT temp_employees_update;

The following SQL statement rewinds the hr.temp_employees table to its state when the database was at the time specified by the SCN:

FLASHBACK TABLE hr.temp_employees
      TO SCN 123456;

As shown in the following example, you can also specify the target point in time with TO_TIMESTAMP:

FLASHBACK TABLE hr.temp_employees
      TO TIMESTAMP TO_TIMESTAMP('2007-10-17 09:30:00', 'YYYY-MM-DD HH:MI:SS');

Oracle Flashback Drop:
   Use the FLASHBACK TABLE ... TO BEFORE DROP statement to recover objects from the recycle bin. You can specify either the name of the table in the recycle bin or the original table name.

This section assumes a scenario in which you drop the wrong table. Many times you have been asked to drop tables in the test databases, but in this case you accidentally connect to the production database instead and drop hr.employee_demo. You decide to use FLASHBACK TABLE to retrieve the dropped object.

To retrieve a dropped table:

Connect SQL*Plus to the target database and obtain the name of the dropped table in the recycle bin.

You can use the SQL*Plus command SHOW RECYCLEBIN as follows:

SHOW RECYCLEBIN;

ORIGINAL NAME    RECYCLEBIN NAME                   TYPE         DROP TIME
    ---------------- --------------------------------- ------------ -------------
    EMPLOYEE_DEMO    BIN$gk3lsj/3akk5hg3j2lkl5j3d==$0  TABLE    2005-04-11:17:08:54

The ORIGINAL NAME column shows the original name of the object, while the RECYCLEBIN NAME column shows the name of the object as it exists in the bin.

Alternatively, you can query USER_RECYCLEBIN or DBA_RECYCLEBIN to obtain the table name. The following example queries the views to determine the original names of dropped objects:

SELECT object_name AS recycle_name, original_name, type
    FROM   recyclebin;

RECYCLE_NAME                      ORIGINAL_NAME          TYPE
    --------------------------------  ---------------------  ----------
    BIN$gk3lsj/3akk5hg3j2lkl5j3d==$0  EMPLOYEE_DEMO          TABLE
    BIN$JKS983293M1dsab4gsz/I249==$0  I_EMP_DEMO             INDEX

If you plan to manually restore original names for dependent objects, then ensure that you make note of each dependent object's system-generated recycle bin name before you restore the table.

Note:
    Object views such as DBA_TABLES do not display the recycle bin objects.

Optionally, query the table in the recycle bin.

You must use the recycle bin name of the object in your query rather than the object's original name. The following example queries the table with the recycle bin name of BIN$KSD8DB9L345KLA==$0:

SELECT *
    FROM   "BIN$gk3lsj/3akk5hg3j2lkl5j3d==$0";

Quotes are required because of the special characters in the recycle bin name.

Note:
    If you have the necessary privileges, then you can also use Oracle Flashback Query on tables in the recycle bin, but only by using the recycle bin name rather than the original table name. You cannot use DML or DDL statements on objects in the recycle bin.

Retrieve the dropped table.

Use the FLASHBACK TABLE ... TO BEFORE DROP statement. The following example restores the BIN$gk3lsj/3akk5hg3j2lkl5j3d==$0 table, changes its name back to hr.employee_demo, and purges its entry from the recycle bin:

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

Note that the table name is enclosed in quotes because of the possibility of special characters appearing in the recycle bin object names.

Alternatively, you can use the original name of the table:

FLASHBACK TABLE HR.EMPLOYEE_DEMO TO BEFORE DROP;

You can also assign a new name to the restored table by specifying the RENAME TO clause. For example:

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

Optionally, verify that all dependent objects retained their system-generated recycle bin names.

The following query determines the names of the indexes of the retrieved hr.employee_demo table:

SELECT INDEX_NAME
    FROM   USER_INDEXES
    WHERE  TABLE_NAME = 'EMPLOYEE_DEMO';

INDEX_NAME
    ------------------------------
    BIN$JKS983293M1dsab4gsz/I249==$0

Optionally, rename the retrieved indexes to their original names.

The following statement renames the index to its original name of i_emp_demo:

ALTER INDEX "BIN$JKS983293M1dsab4gsz/I249==$0" RENAME TO I_EMP_DEMO;

If the retrieved table had referential constraints before it was placed in the recycle bin, then re-create them.

This step must be performed manually because the recycle bin does not preserve referential constraints on a table.

Retrieving Objects When Multiple Objects Share the Same Original Name

You can create, and then drop, several objects with the same original name. All the dropped objects will be stored in the recycle bin. For example, consider the SQL statements in the following example.

Example 16-1 Dropping Multiple Objects with the Same Name

CREATE TABLE temp_employees ( ...columns ); # temp_employees version 1
DROP TABLE temp_employees;

CREATE TABLE temp_employees ( ...columns ); # temp_employees version 2
DROP TABLE temp_employees;

CREATE TABLE temp_employees ( ...columns ); # temp_employees version 3
DROP TABLE temp_employees;

In Example 16-1, each table temp_employees 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 temp_employees TO BEFORE DROP;

The most recently dropped table with this original name is retrieved from the recycle bin, with its original name. Example 16-2 shows the retrieval from the recycle bin of all three dropped temp_employees tables from the previous example, with each assigned a new name.

Example 16-2 Renaming Dropped Tables

FLASHBACK TABLE temp_employees TO BEFORE DROP
  RENAME TO temp_employees_VERSION_3;
FLASHBACK TABLE temp_employees TO BEFORE DROP
  RENAME TO temp_employees_VERSION_2;
FLASHBACK TABLE temp_employees TO BEFORE DROP
  RENAME TO temp_employees_VERSION_1;

Because the original name in FLASHBACK TABLE refers to the most recently dropped table with this name, the last table dropped is the first retrieved.

You can also retrieve any table from the recycle bin, regardless of any collisions among original names, by using the unique recycle bin name of the table. For example, assume that you query the recycle bin as follows (sample output included):

SELECT object_name, original_name, createtime
FROM   recyclebin;

OBJECT_NAME                    ORIGINAL_NAME   CREATETIME
------------------------------ --------------- -------------------
BIN$yrMKlZaLMhfgNAgAIMenRA==$0 TEMP_EMPLOYEES  2007-02-05:21:05:52
BIN$yrMKlZaVMhfgNAgAIMenRA==$0 TEMP_EMPLOYEES  2007-02-05:21:25:13
BIN$yrMKlZaQMhfgNAgAIMenRA==$0 TEMP_EMPLOYEES  2007-02-05:22:05:53

You can use the following command to retrieve the middle table:

FLASHBACK TABLE BIN$yrMKlZaVMhfgNAgAIMenRA==$0 TO BEFORE DROP;

Oracle Flashback Database:

Overview of Flashback Technology的更多相关文章

  1. Oracle Flashback Technology【闪回技术】

    -------------------------与其他数据库相比,Oracle的闪回让开发者多了一条选择的路. Flashback的目的 先看下Oracle官方文档中的解释: Oracle Flas ...

  2. Oracle 六闪回技术,flashback

    Flashback 技术基于Undo segment基于内容的, 因此,限制UNDO_RETENTON参数. 要使用flashback 特征,您必须启用自己主动撤销管理表空间. 在Oracle 11g ...

  3. Oracle Flashback Database

    Oracle Flashback Database Ensure that the prerequisites described in Prerequisites of Flashback Data ...

  4. Oracle闪回flashback

    参考资料:Using Oracle Flashback Technology Oracle 11g的新特性闪回操作 闪回查询 闪回查询 闪回版本查询 闪回事务查询 闪回数据 闪回表 闪回删除 闪回数据 ...

  5. Backup and Recovery Basics1

    一.Backup and Recovery Overview 1.Backup and Recovery Overview 1.1 What is Backup and Recovery? 一般,备份 ...

  6. OCP学习基本知识点总结

     下面是我总结的OCP教程的知识点.以备參考之用. 1, What's Oracle Server? ·         It's a database management system that ...

  7. FLASH BACK

    overview of different flashback technologies flashback query(including flashback query, flashback ve ...

  8. PayPal高级工程总监:读完这100篇论文 就能成大数据高手(附论文下载)

    100 open source Big Data architecture papers for data professionals. 读完这100篇论文 就能成大数据高手 作者 白宁超 2016年 ...

  9. 1Z0-053 争议题目解析

    1Z0-053 争议题目解析 Summary 题目NO. 题目解析链接地址 题库答案 参考答案 考查知识点  24 http://www.cnblogs.com/jyzhao/p/5319220.ht ...

随机推荐

  1. 十大技巧快速提升原生APP开发性能

    移动应用市场用户争夺战日益激烈,原来做APP拼想法拼创意拼是否抓住用户痛点.现在,精细化用户体验成为了一个APP能否留存用户的关键问题,一旦用户觉得体验不畅,马上就有竞品APP后补,如何开发高性能的移 ...

  2. winston 日志管理4

    配置File Transport winston.add(winston.transports.File, options) The File transport should really be t ...

  3. 解决git clone时报错:The requested URL returned error: 401 Unauthorized while accessing

    版本问题,最直接的解决办法就是重新编辑安装git吧: 1. 下载:# wget -O git.zip https://github.com/git/git/archive/master.zip 2. ...

  4. runtime获取类名,遍历变量,遍历对象,遍历方法

  5. go 语言的库文件放在哪里?如何通过nginx代理后还能正确获取远程地址

    /usr/local/Cellar/go/1.5.1/libexec/src/ 他的RemoteAddr 是从哪里获取? func (c *conn) RemoteAddr() Addr { if ! ...

  6. 这是我定位的Bug

    https://github.com/danielgindi/ios-charts/issues/406

  7. 第三方cookie与搜索引擎+网站广告原理

    cookie 摘自 : http://www.williamlong.info/archives/3125.html 关于cookie的安全知识 :http://shaoshuai.me/tech/2 ...

  8. 成员变量的隐藏,方法的覆盖,super关键字

    成员变量的隐藏:当父类和子类有相同的成员变量时,即定义了与父类相同的成员变量时,就会发生子类对父类变量的隐藏.对于子类的对象来说,父类中的同名成员变量被隐藏起来,子类就会优先使用自己的成员变量,父类成 ...

  9. Leetcode: Data Stream as Disjoint Intervals && Summary of TreeMap

    Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen ...

  10. .NET: WPF 路由事件

    (一)使用WPF内置路由事件 xaml: <Window x:Class="WpfApplication1.MainWindow" xmlns="http://sc ...