无法删除最旧的表分区
我在我的一张表中使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,错误消息有点误导,但它指的是最后一个静态创建的分区(在 Oracle 开始自动创建分区之前的原始表 DDL 中)。我认为避免这种情况的唯一方法是创建一个人工“MINVAL”分区你确定永远不会被使用,然后删除上面的真实分区
[交换意见后编辑]
我假设这个测试用例重现了你的问题:
当我这样做时,我可以删除分区p0、p1和p2,但得到你的分区。尝试删除 p3 时出错,即使存在系统生成的分区,
我能找到的唯一解决方法是暂时重新定义表分区:
然后删除分区 p3。经过:
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:
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:
and then drop partition p3. Then you can redefine the partitioning as per the original specification by:
dpbradley 的回答全部正确。但如果您要删除最旧的分区,则可以采取更安全的方式:
事实上,只需像这样重置间隔就足够了:
然后删除分区最旧的分区。
否则,如果删除分区失败,则存在表将没有间隔的风险。因此需要捕获所有异常并进行处理。
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 :
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.