Overview of Flashback Technology
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的更多相关文章
- Oracle Flashback Technology【闪回技术】
-------------------------与其他数据库相比,Oracle的闪回让开发者多了一条选择的路. Flashback的目的 先看下Oracle官方文档中的解释: Oracle Flas ...
- Oracle 六闪回技术,flashback
Flashback 技术基于Undo segment基于内容的, 因此,限制UNDO_RETENTON参数. 要使用flashback 特征,您必须启用自己主动撤销管理表空间. 在Oracle 11g ...
- Oracle Flashback Database
Oracle Flashback Database Ensure that the prerequisites described in Prerequisites of Flashback Data ...
- Oracle闪回flashback
参考资料:Using Oracle Flashback Technology Oracle 11g的新特性闪回操作 闪回查询 闪回查询 闪回版本查询 闪回事务查询 闪回数据 闪回表 闪回删除 闪回数据 ...
- Backup and Recovery Basics1
一.Backup and Recovery Overview 1.Backup and Recovery Overview 1.1 What is Backup and Recovery? 一般,备份 ...
- OCP学习基本知识点总结
下面是我总结的OCP教程的知识点.以备參考之用. 1, What's Oracle Server? · It's a database management system that ...
- FLASH BACK
overview of different flashback technologies flashback query(including flashback query, flashback ve ...
- PayPal高级工程总监:读完这100篇论文 就能成大数据高手(附论文下载)
100 open source Big Data architecture papers for data professionals. 读完这100篇论文 就能成大数据高手 作者 白宁超 2016年 ...
- 1Z0-053 争议题目解析
1Z0-053 争议题目解析 Summary 题目NO. 题目解析链接地址 题库答案 参考答案 考查知识点 24 http://www.cnblogs.com/jyzhao/p/5319220.ht ...
随机推荐
- window.open被浏览器拦截的解决方案
现象 最近在做项目的时候碰到了使用window.open被浏览器拦截的情况,搞得人无比郁闷啊,虽然在自己的环境可以对页面进行放行,但是对用户来说,不能要求用户都来通过拦截.何况当出现拦截时,很多小白根 ...
- IntelliJ IDEA 的 Java 热部署插件 JRebel 安装及使用
JRebel 介绍 JRebel for Intellij JRebel 在 Java Web 开发中, 一般更新了 Java 文件后要手动重启 Tomcat 服务器, 才能生效, 自从有了 JRe ...
- C读取文件
C读取文件,这种写法不会多一行. #include "stdafx.h" #include <vector> using namespace std; struct P ...
- UIButton属性
1.UIButton状态: UIControlStateNormal // 正常状态 UIControlStateHighlighted // 高亮状态 UICo ...
- 统计哪些程序占用了swap
命令如下 : for i in `cd /proc;ls |grep "^[0-9]"|awk ' $0 >100'` ;do awk '/Swap:/{a=a+$2}END ...
- Excessive AWR Growth From Partitioned Objects Such as SYS.WRH$_EVENT_HISTOGRAM Causing Sysaux to Grow
AWR数据增长较快,导致sysaux表空间使用较高 SQL> select f.tablespace_name, 2 a.total, 3 f.free, 4 round((f.free / a ...
- Redis Sets
Sets Sets 就是一个集合,集合的概念就是一堆不重复值的组合.利用Redis提供的Sets数据结构,可以存储一些集合性的数据,比如在微博应用中,可以将一个用户所有的关注人存在一个集合中,将其所有 ...
- JavaScript内的类型转换
JavaScript内的类型转换 1.分为自动转换和强制转换,我们一般用强制转换.其他类型转换为整数是parseInt();其他类型转化为小数parseFloat(); 2.判断是不是一个合法数字 ...
- USACO: Combination Lock
长久不写算法题,这种简单题折腾了一下午... /* ID: yingzho2 LANG: C++ TASK: combo */ #include <iostream> #include & ...
- c++必读
下面的是学c++时要注意的.绝对经典.!! 1.把c++当成一门新的语言学习(和c没啥关系!真的.): 2.看<thinking in c++>,不要看<c++变成死相>: ...