如何彻底的删除Oracle表 及 闪回恢复在回收站里的数据

当一个表被删除时,它并不是真正的被删除了,而只是放在回收站里(recyclebin)了,当然只要表还在回收站里,它就可以被重新恢复,这也就是“闪回”技术的基本原理。需要说明的是,oracle并不提供100%的闪回,因为当用户在某个表空间里创建一个新表时或需要磁盘空间时,oracle首先使用空闲的磁盘空间,当没有足够的磁盘空间时,oracle会使用回收站的磁盘空间。

如何彻底的删除Oracle表 及 闪回恢复在回收站里的数据

2 删除表 test

如何彻底的删除Oracle表 及 闪回恢复在回收站里的数据

3 查看 回收站

SQL> show recyclebin
ORIGINAL NAME    RECYCLEBIN NAME                OBJECT TYPE  DROP TIME         
---------------- ------------------------------ ------------ -------------------
TEST             BIN$TsRUiy4NTICSiCNF0y9bAQ==$0 TABLE        2010-04-16:22:17:26

在回收站里有 名为test 的表,说明表并没有真正的被删除。

4 使用purge命令:

SQL> purge recyclebin;

回收站已清空。

再次查看回收站:

SQL> show recyclebin

无结果,证明表真正的被删除了。当然,此时也无法进行闪回恢复了。下面进行闪回实验;

SQL> create table t  as select * from emp;---建立实验表 T

表已创建。

SQL> drop table t;--逻辑删除表T

表已删除。

SQL> show recyclebin  --查看回收站
ORIGINAL NAME    RECYCLEBIN NAME                OBJECT TYPE  DROP TIME         
---------------- ------------------------------ ------------ -------------------
T                BIN$XSAPpdnPQ9uMJh72G0ZCIg==$0 TABLE        2010-04-16:22:40:12

SQL> select object_name,ts_name,space
  2  from user_recyclebin;

OBJECT_NAME                    TS_NAME                             SPACE       
------------------------------ ------------------------------ ----------       
BIN$XSAPpdnPQ9uMJh72G0ZCIg==$0 USERS                                   8       

SQL> --结果显示此表使用的磁盘空间为8个数据块,存放在users 表空间。
SQL> select * from t;--再次查询表T
select * from t
              *
第 1 行出现错误:
ORA-00942: 表或视图不存在

-------使用闪回技术
SQL> flashback table t to before drop;

闪回完成。

SQL> show recyclebin
SQL> --可以看出,回收站里没有T
SQL> select * from t;--再次查询表T

     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                                                                     
                                                                               

     EMPNO ENAME      JOB              MGR HIREDATE              SAL       COMM
---------- ---------- --------- ---------- -------------- ---------- ----------
    DEPTNO                                                                     
----------                                                                     
      7566 JONES      MANAGER         7839 02-4月 -81           2975           
        20                                                                     
                                                                               
      7654 MARTIN     SALESMAN        7698 28-9月 -81           1250       1400
        30                                                                     
                                                                               
      7698 BLAKE      MANAGER         7839 01-5月 -81           2850           
        30                                                                     
                                                                               

     EMPNO ENAME      JOB              MGR HIREDATE              SAL       COMM
---------- ---------- --------- ---------- -------------- ---------- ----------
    DEPTNO                                                                     
----------                                                                     
      7782 CLARK      MANAGER         7839 09-6月 -81           2450           
        10                                                                     
                                                                               
      7788 SCOTT      ANALYST         7566 19-4月 -87           3000           
        20                                                                     
                                                                               
      7839 KING       PRESIDENT            17-11月-81           5000           
        10                                                                     
                                                                               

     EMPNO ENAME      JOB              MGR HIREDATE              SAL       COMM
---------- ---------- --------- ---------- -------------- ---------- ----------
    DEPTNO                                                                     
----------                                                                     
      7844 TURNER     SALESMAN        7698 08-9月 -81           1500          0
        30                                                                     
                                                                               
      7876 ADAMS      CLERK           7788 23-5月 -87           1100           
        20                                                                     
                                                                               
      7900 JAMES      CLERK           7698 03-12月-81            950           
        30                                                                     
                                                                               

     EMPNO ENAME      JOB              MGR HIREDATE              SAL       COMM
---------- ---------- --------- ---------- -------------- ---------- ----------
    DEPTNO                                                                     
----------                                                                     
      7902 FORD       ANALYST         7566 03-12月-81           3000           
        20                                                                     
                                                                               
      7934 MILLER     CLERK           7782 23-1月 -82           1300           
        10                                                                     
                                                                               

已选择14行。

SQL> drop table t purge;---彻底删除

表已删除。

SQL> show recyclebin---无结果返回
提示:

闪回技术只能保护非系统表空间的表,而且这些表还必须存放在本地管理的表空间里。尽管在一个表被删除时,依赖该表的绝大多数对象也受到回收站的保护,但是位图连接的索引(Bitmap Jion Indexes),引用完整性约束(referential integrity constrains) 等并不受到回收站的保护,一定要记住这一点!

如何彻底的删除Oracle表 及 闪回恢复在回收站里的数据1.jpg

如何彻底的删除Oracle表 及 闪回恢复在回收站里的数据2.jpg

上一篇:Comparable与Comparator,java中的排序与比较


下一篇:【Flutter】ListView 列表高级功能 ( RefreshIndicator 下拉刷新组件 )