如何在oracle中从表中分离分区并将其附加到另一个表?
我有一个包含 5 年的海量数据(比如数百万条记录,但这只是一个案例研究!)的表,每年都有一个分区。现在我想保留最近 2 年的数据,并将其余 3 年的数据传输到一个名为存档的新表中?
停机时间最短且性能较高的理想方法是什么?
I have a table with huge data( say millions of records, its just a case study though!) of 5 years, with a partition for each year. Now i would want to retain the last 2 years data, and transfer the rest of the 3 year data to a new table called archive?
What would be the Ideal method, with minimal down time and high performance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就是答案。该命令将分区的段与表的段交换。它的速度是光速,因为它只进行一些参考交换。
所以,你需要一些临时表,因为据我所知你不能直接交换它们。
例如:
请在运行之前测试您的代码。
is the answer. This command exange the segment of a partition with the segment of a table. It is at light speed because it does only some reference interchages.
So, you need some temp tables, because AFAIK you can't exchange them directly.
Something like:
Please test test your code before run.
如果您的表按 RANGE、INTERVAL 或 HASH 分区进行分区,那么使用分区交换应该不会出现重大问题:
最后使用可选指令
WITHOUT VALIDATION
和UPDATE GLOBAL INDEXES
。但请记住,如果要移动使用 PARTITION BY REFERENCE 的表分区或在按引用分区的表中包含按引用使用的数据的父表,则必须使用 Oracle Server 版本 12.1 或更高版本。在 Oracle Server 11gR2 中,不完全支持按引用分区的表的分区交换,您将偶然发现日期/引用完整性错误
,或者如果您想要禁用或删除受影响的约束
,如果您不能/不会升级到 Oracle Server 12.1+,为您提供将数据复制到存档表的功能,并且从原始表中删除是唯一的选项。
If your table is partitioned by RANGE, INTERVAL or HASH partitioning, you shouldn't have significant problems by using partition exchange:
With optional directives
WITHOUT VALIDATION
andUPDATE GLOBAL INDEXES
at end.However keep in mind that if you want to move partitions of tables that either use PARTITION BY REFERENCE or parent tables that have data used by reference in tables partitioned by reference, you must use Oracle Server version 12.1 or later. In Oracle Server 11gR2 partition exchange for tables partitioned by reference, is not exactly supported and you will stumble upon date/reference integrity errors
or if you want to disable or remove affected constraints
Which if you can't/won't upgrade to Oracle Server 12.1+, give you the copying data to archive tables with deleting from original tables as the only option.