<< 返回文章列表

警惕:Oracle中删除的分区不会进入回收站(Recyclebin)

2017年12月4日
盖国强
1694

最近在『云和恩墨大讲堂』的微信群讨论中,有朋友提到分区的删除和闪回问题,我注意到很多人可能忽略了这个问题。


在Oracle数据库中,单个删除的分区并不会进入回收站,全表删除的分区才可能和全表一起放入回收站。这是因为单个分区删除之后,是无法通过简单的闪回加入原分区表中,既然无法保证一致性,这个分区就不会进入回收站中。



以下这个测试展示了这个过程:

SQL> select * from v$version;


BANNER          

-------------------------------------------------------------------

Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production   

PL/SQL Release 12.2.0.1.0 - Production        

CORE 12.2.0.1.0 Production         

TNS for Linux: Version 12.2.0.1.0 - Production       

NLSRTL Version 12.2.0.1.0 - Production        


SQL> CREATE TABLE enmotech (

2 PartID  integer  not null,

3 CretTm  date  not null,

4 PartCD  varchar2(2) not null

5 ) partition by list (partcd) automatic (

6 partition pBJ values ('BJ'),

7 partition pCD values ('CD'),

8 partition pGZ values ('GZ'),

9 partition pSH values ('SH')

10 );


Table created.


SQL> insert into enmotech values (1, sysdate, 'KM');


1 row created.


SQL> select partition_name from user_tab_partitions

2 where table_name = 'ENMOTECH';


PARTITION_NAME

--------------------------------------------------------------------

PBJ

PCD

PGZ

PSH

SYS_P281


SQL> alter table enmotech drop partition SYS_P281 purge;

alter table enmotech drop partition SYS_P281 purge

*

ERROR at line 1:

ORA-14048: a partition maintenance operation may not be combined with other operations



SQL> alter table enmotech drop partition PSH;


Table altered.


SQL> select * from user_recyclebin;


no rows selected



当我们DROP 整个分区表时,分区表连带所有的分区,会进入到回收站。



很多时候,想当然的结果可能并不可信,实践操作方能出真知,多动手,是技术人的王道。

000.jpg