Oracle Study Notes: drop table and purge

Operation Oracle, often drop a table, when you delete the wrong, hoping to restore the table, sometimes want to delete the table after table space can be released immediately.

You can delete the table in Oracle by using the purge and restore the table and release the space.

drop table

When you delete in Oracle (drop) a table, database table space is not immediately released, but rename the table and put it in the trash, you can check in the following ways:

select object_name,
       original_name
from user_recyclebin
where original_name = 'TEMP'

OBJECT_NAME                     ORIGINAL_NAME
-------------------------------------------------------
BIN$C1LT5U0DaV7gVAAhKENZ5A==$0  TEMP
  • object_name: name of the object in the recycle bin;
  • original_name: the original name of the object.

After the table into the recycle bin, Oracle will not use this space to other objects using the table, the space occupied by the table still occupied, unless the user manually Purge or because the storage space is not enough to be cleared away the database. If you find an error deleting the table, the table can be restored by flashback table.

flashback table

You can use flashback table to recover deleted tables.

flashback table temp to before drop;

to before drop indicates that the recovery of this table and all its dependent objects. If the table name of the other tables have been used, is executed flashback table when the table will be given: ORA-38312:original name is used by an existing objectIn this case, the table may be renamed when executed flashback table:

flashback table temp to before drop rename to temp_old;

rename to indicate the recovery table after renaming. If the table has been removed several times, then use the flashback table to restore the table to restore the default, a previous version if you want to restore the last deleted, you need to query the table in the recycle bin:

select object_name,original_name,droptime from user_recyclebin where original_name = 'TEMP';
OBJECT_NAME                     ORIGINAL_NAME   DROPTIME
------------------------------------------------------------------------
BIN$C1LT5U0FaV7gVAAhKENZ5A==$0  TEMP            2014-12-29:10:59:41
BIN$C1LT5U0HaV7gVAAhKENZ5A==$0  TEMP            2014-12-29:10:59:54
BIN$C1LT5U0GaV7gVAAhKENZ5A==$0  TEMP            2014-12-29:10:59:47

You can then use that to restore and rename every way to restore order.

Note the use of flashback table:

  1. Recycle Bin database will restore all indexes of the table, pay attention bitmap join Index can not be restored because the index in the table after the deletion will not be placed in the recycle bin, it can not be restored;
  2. Constraint database will be recovered and the trigger table, in addition to other tables point to integrity constraints;
  3. When you delete a table, define all materialized view logs on the table is also deleted, but not in the Recycle Bin, therefore, materialized view logs can not be restored with the form;
  4. When you delete a table, all indexes associated with this table will be placed in the recycle bin, if the database is insufficient space, the database will first clear the space out of the index, therefore, in this case, the recovery will not be able to recover all of the table index;
  5. If the table has been deleted purge, then it can not recover.

If a user deletes a table will not restore it, you can consider using purge it completely removed.

purge

purge table can be completely removed, and free up space occupied by the table.

purge table temp;
drop table table_name purge;

Note that a purge operation can not be rolled back once performed purge operation on a table, the table will not be recovered.

If the table is dropped several times, purge will clear the oldest deleted that table, you can clear the entire contents of the Recycle Bin:

purge recyclebin;

drop table ... purge

You can also delete tables and free space in one step, for example:

drop table table_name purge;

In this way the same as deleting the table table_name, and then perform the purge operation on the table.

Note that, in this case, the purge can not roll back a tape drop table operation, the table can not be restored using a purge deleted.

test

If the stored procedure, or other code using the drop statement to delete a large table, prone to garbage in the recycle bin, DBA would complain.

If it is determined to drop the table, it is best to add purge, but should be used with caution, because they can not be rolled back.

In the command window to the next:

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




SQL> purge recyclebin;
 
Done -- 清空回收站


SQL> show recyclebin;
-- 查询




SQL> drop table dt;
-- 删除表  
SQL> show recyclebin;
ORIGINAL NAME    RECYCLEBIN NAME                OBJECT TYPE  DROP TIME
---------------- ------------------------------ ------------ -------------------
dt              BIN$2cOZCZj0Ry27btpd7ymTHg==$0 TABLE        2019-04-10:10:56:58


SQL> flashback table dt to before drop;
-- 回滚数据表

SQL> drop table dt purge;
-- 删除表并清空回收站
SQL> show recyclebin; -- 为空

Reference Link 1: the Oracle Tips: drop the Table and purge

Reference Links 2: purge Usage [ORACLE] Delete table

Guess you like

Origin www.cnblogs.com/hider/p/12194675.html