无法删除最旧的表分区

发布于 2024-08-04 03:12:23 字数 229 浏览 5 评论 0原文

我在我的一张表中使用 11g 间隔分区功能。我将其设置为在时间戳字段上创建 1 天的分区,并创建了一个作业来删除 3 个月前的数据。当我尝试删除最旧的分区时,出现以下错误:

ORA-14758: 无法删除范围部分中的最后一个分区

我认为“最后”是指最新的分区而不是最旧的分区。我该如何解释这个错误?我的分区是否有问题,或者我实际上应该始终保留最旧的分区?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

箹锭⒈辈孓 2024-08-11 03:12:23

是的,错误消息有点误导,但它指的是最后一个静态创建的分区(在 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'));

Yes, the error message is somewhat misleading, but it refers to the last STATICALLY created partition (in your original table DDL before Oracle started creating the partitions automatically. I think the only way to avoid this is to create an artifical "MINVAL" partition that you're sure will never be used and then drop the real partitions above this.

[Edit after exchange of comments]

I assume this test case reproduces your problem:

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'));

When I do this I can drop partitions p0,p1, and p2 but get your error when attempting to drop p3 even though there is a system-generated partition beyond this.

The only workaround I could find was to temporarily redefine the table partitioning by:

alter table test set interval ();

and then drop partition p3. Then you can redefine the partitioning as per the original specification by:

alter table test set INTERVAL(NUMTODSINTERVAL(1, 'DAY'));
瑶笙 2024-08-11 03:12:23

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

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

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

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

否则,如果删除分区失败,则存在表将没有间隔的风险。因此需要捕获所有异常并进行处理。

All correct in dpbradley's answer. But it could be done more safe way if you're dropping oldest partition(s):

In fact it is enough just to reset interval like this :

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

And then drop partition oldest partition.

Otherwise there is a risk if drop partition fails then table will have no interval. So need to catch all exceptions and handle this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文