zoukankan      html  css  js  c++  java
  • Flashback Drop实例操作

    1、Flashback Drop
    Flashback Drop 是从Oracle 10g 开始出现的,用于恢复用户误删除的对象(包括表,索引等), 这个技术依赖于Tablespace Recycle Bin(表空间回收站)
    ,这个功能和windows的回收站非常类似。
    Flashback 不支持sys用户. system表空间下的对象,也不能从回收站里拿到。故使用SYS 或者SYSTEM用户登陆时, show recyclebin 为空。
    Flashback Drop 是基于Tablespace RecycleBin 来实现恢复的。 它只支持闪回与table 相关连的对象,比如表,索引,约束,触发器等。 如果是函数或
    者存储过程等,就需要使用Flashback Query来实现。

    2、Tablespace Recycle Bin
    从Oracle 10g 开始, 每个表空间都会有一个叫作回收站的逻辑区域,当用户执行drop命令时, 被删除的表和表的关联对象( 包括索引, 约束,触发器
    ,LOB段,LOB index 段) 不会被物理删除, 这些对象先转移到回收站中,这就给用户提供了一个恢复的可能。
    初始化参数recyclebin 用于控制是否启用recyclebin功能,缺省是ON, 可以使用OFF关闭。

    SQL> show parameter recycle
    NAME                                            TYPE            VALUE
    ------------------------------------ ----------- ------------------------------
    buffer_pool_recycle                         string
    db_recycle_cache_size                     big                integer 0
    recyclebin                                       string             on

    禁用该功能:
    SQL> alter system set recyclebin=off;
    SQL> alter system set recyclebin=on;

    SQL> alter session set recyclebin=off;
    SQL> alter session set recyclebin=on;
    禁用后删除的对象将直接删除,不会写到Recycle中,当然在删除时,指定purge 参数,表也将直接删除,不会写到recyclebin中。
    SQL> drop table emp2;
    表已删除。

    查看recyclebin内容:

    SQL> show recyclebin;
    ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
    ---------------- ------------------------------ ------------ -------------------
    EMP2 BIN$yBCF53QgQw+A//Sf3M4i9g==$0 TABLE 2014-10-16:14:16:07

    查看recyclebin中已删除表的内容:

    SQL> select * from "BIN$yBCF53QgQw+A//Sf3M4i9g==$0";
    
    EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    ---------- ---------- --------- ---------- -------------- ---------- ---------- ----------
    7369 SMITH CLERK 7902 17-12月-80 800 20
    7499 ALLEN SALESMAN 7698 20-2月 -81 1600 300 30
    7521 WARD SALESMAN 7698 22-2月 -81 1250 500 30

    表空间的Recycle Bin 区域只是一个逻辑区域,而不是从表空间上物理的划出一块区域固定用于回收站,因此Recycle Bin是和普通对象共用表空间的存储
    区域,或者说是Recycle Bin的对象要和普通对象抢夺存储空间。
    当发生空间不够时,Oracle会按照先入先出的顺序覆盖Recycle Bin中的对象。

    也可以手动的删除Recycle Bin占用的空间:
    1). Purge tablespace tablespace_name : 用于清空表空间的Recycle Bin
    2). Purge tablespace tablespace_name user user_name: 清空指定表空间的Recycle Bin中指定用户的对象
    3). Purge recyclebin: 删除当前用户的Recycle Bin中的对象
    4). Purge dba_recyclebin: 删除所有用户的Recycle Bin中的对象,该命令要sysdba权限
    5). Drop table table_name purge: 删除对象并且不放在Recycle Bin中,即永久的删除,不能用Flashback恢复。
    6). Purge index recycle_bin_object_name: 当想释放Recycle bin的空间,又想能恢复表时,可以通过释放该对象的index所占用的空间来缓解空间压
    力。 因为索引是可以重建的。

    3、Flashback Drop实例操作

    SQL> create table emp2 as select * from emp;
    
    表已创建。
    
    SQL> drop table emp2;
    
    表已删除。
    
    SQL> create table emp2 as select * from emp;
    
    表已创建。
    
    SQL> show recyclebin;
    ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
    ---------------- ------------------------------ ------------ -------------------
    EMP2 BIN$I9JlfLrTQY6cwRe8z23JRA==$0 TABLE 2014-10-16:14:27:26
    SQL> flashback table emp2 to before drop;
    flashback table emp2 to before drop
    *1 行出现错误:
    ORA-38312: 原始名称已被现有对象使用
    
    SQL> flashback table emp2 to before drop rename to emp2_old;
    
    闪回完成。
    
    SQL> select * from emp2_old;
    
    EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    ---------- ---------- --------- ---------- -------------- ---------- ---------- ----------
    7369 SMITH CLERK 7902 17-12月-80 800 20
    7499 ALLEN SALESMAN 7698 20-2月 -81 1600 300 30
    7521 WARD SALESMAN 7698 22-2月 -81 1250 500 30
    ……
    ==============================
    SQL> show recyclebin;
    ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
    ---------------- ------------------------------ ------------ -------------------
    EMP2 BIN$AeRr13dlQI+5c9f9+0ducA==$0 TABLE 2014-10-16:14:32:02
    EMP2 BIN$Zj6I4NMMSwWhib3C/jYx1g==$0 TABLE 2014-10-16:14:31:21
    删除emp2,再新建em2,再删除...此时Recycle Bin中就会有多个相同的表名,恢复时必须指定object_name才行。
    flashback table emp2 to before drop;-----------没有指定object_name,则恢复最近时间删除的表。
    SQL> flashback table emp2 to before drop;
    
    闪回完成。
    或flashback table "BIN$Zj6I4NMMSwWhib3C/jYx1g==$0" to before drop;---指定object_time;
    SQL> flashback table "BIN$Zj6I4NMMSwWhib3C/jYx1g==$0" to before drop rename to emp3;
    
    闪回完成。

    ==============================
    一旦完成闪回恢复,Recycle Bin中的对象就消失了。
    如果表上索引或者约束等信息,这些信息也会被恢复,但是这些对象会使用Oracle 自动的命名。 我们需要查看这些对象,然后对这些对象重新命名。

    Flashback Drop 需要注意的地方:
    1). 只能用于非系统表空间和本地管理的表空间
    2). 对象的参考约束不会被恢复,指向该对象的外键约束需要重建。
    3). 对象能否恢复成功,取决与对象空间是否被覆盖重用。
    4). 当删除表时,信赖于该表的物化视图也会同时删除,但是由于物化视图并不会被放入recycle bin,因此当你执行flashback table to before drop
    时,也不能恢复依赖其的物化视图,需要dba 手工介入重新创建。
    5). 对于Recycle Bin中的对象,只支持查询。

    6).不支持truncate之后的操作,对于truncate,唯一恢复方法是flashback database。

    《FROM:http://blog.csdn.net/tianlesoftware/article/details/4677378

    During an Oracle Flashback Table operation, Oracle Database acquires exclusive DML locks on all the tables specified in the Flashback list. These locks prevent any operations on the tables while they are revertingto their earlier state.
    Restrictions on Flashing Back Tables
    This statement is subject to the following restrictions:
    Flashback Table operations are not valid for the following type objects: tables that are part of a cluster, materialized views, Advanced Queuing (AQ) tables, static data dictionary tables, system tables, remote tables, object tables, nested tables, or individual table partitions or subpartitions.
    The following DDL operations change the structure of a table, so that you cannot subsequently use the TO SCN or TO TIMESTAMP clause to flash the table back to a time preceding the operation: upgrading, moving, or truncating a table; adding a constraint to a table, adding a table to a cluster; modifying  or dropping a column; changing a column encryption key; adding, dropping, merging, splitting, coalescing, or truncating a partition or subpartition (with the  exception of adding a range partition).

  • 相关阅读:
    Node.js理解
    PayPal为什么从Java迁移到Node.js
    移动开发技巧总结
    Flex性能调优相关的一些总结
    Flex组件的生命周期
    Adobe Flash Builder 4.7 新功能详解
    【Django】Cookie
    【Django】路由系统
    【Django】视图系统
    【Django】ORM操作#2
  • 原文地址:https://www.cnblogs.com/rusking/p/4028813.html
Copyright © 2011-2022 走看看