7

I'm using the 11g interval partitioning feature in one of my tables. I set it up to create 1 day partitions on a timestamp field and created a job to delete data 3 months old. When I try to delete the oldest partition I get the following error:

ORA-14758: Last partition in the range section cannot be dropped

I would have thought that "Last" refers to the newest partition and not the oldest. How should I interpret this error? Is there something wrong with my partitions or should I in fact keep the oldest partition there at all time?

4

2 回答 2

5

是的,错误消息有点误导,但它指的是最后一个静态创建的分区(在 Oracle 开始自动创建分区之前的原始表 DDL 中。我认为避免这种情况的唯一方法是创建一个人工的“MINVAL”分区)您确定将永远不会被使用,然后将真实分区放在此之上。

[交换意见后编辑]

我假设这个测试用例重现了你的问题:

CREATE TABLE test 
    ( t_time        DATE
    )
  PARTITION BY RANGE (t_time)
  INTERVAL(NUMTODSINTERVAL(1, 'DAY'))
    ( PARTITION p0 VALUES LESS THAN (TO_DATE('09-1-2009', 'MM-DD-YYYY')),
      PARTITION p1 VALUES LESS THAN (TO_DATE('09-2-2009', 'MM-DD-YYYY')),
      PARTITION p2 VALUES LESS THAN (TO_DATE('09-3-2009', 'MM-DD-YYYY')),
      PARTITION p3 VALUES LESS THAN (TO_DATE('09-4-2009', 'MM-DD-YYYY')) 
);
insert into test values(TO_DATE('08-29-2009', 'MM-DD-YYYY'));
insert into test values(TO_DATE('09-1-2009', 'MM-DD-YYYY'));
insert into test values(TO_DATE('09-3-2009', 'MM-DD-YYYY'));
insert into test values(TO_DATE('09-10-2009', 'MM-DD-YYYY'));

当我这样做时,我可以删除分区 p0、p1 和 p2,但在尝试删除 p3 时会出现错误,即使除此之外还有系统生成的分区。

我能找到的唯一解决方法是通过以下方式临时重新定义表分区:

alter table test set interval ();

然后删除分区 p3。然后,您可以通过以下方式根据原始规范重新定义分区:

alter table test set INTERVAL(NUMTODSINTERVAL(1, 'DAY'));
于 2009-09-08T19:21:37.040 回答
2

dpbradley 的回答全部正确。但是,如果您要删除最旧的分区,则可以采取更安全的方式:

事实上,只需像这样重置间隔就足够了:

alter table test set interval ();
alter table test set INTERVAL(NUMTODSINTERVAL(1, 'DAY'));

然后删除分区最旧的分区。

否则,如果删除分区失败,则表将没有间隔。所以需要捕获所有异常并处理它。

于 2013-12-11T16:12:08.223 回答