How to Drop/Truncate Multiple Partitions in Oracle 12C (Doc ID 1482264.1)

APPLIES TO:

Oracle Database - Enterprise Edition - Version 12.1.0.1 and later
Oracle Database Cloud Schema Service - Version N/A and later
Oracle Database Exadata Cloud Machine - Version N/A and later
Oracle Cloud Infrastructure - Database Service - Version N/A and later
Oracle Database Cloud Exadata Service - Version N/A and later
Information in this document applies to any platform.
Oracle 12C

GOAL

To be able to drop or truncate multiple partitions or subpartitions with a single statement  为了能够使用单个语句删除或截断多个分区或子分区

SOLUTION

You can use multi-partition maintenance operations which enable dropping multiple partitions and truncating multiple partitions using a single SQL data definition language (DDL) statement.

您可以使用多分区维护操作,这些操作允许使用单个SQL数据定义语言(DDL)语句删除多个分区并截断多个分区

If a domain index is defined on the table, then you can drop/truncate only one partition at a time.  如果在上定义了 domain index table,则一次只能删除/截断一个分区。
Rows inside the partition(s) being dropped are eliminated, so if you want to keep the rows you must use the MERGE PARTITIONS instead.  删除了要删除的分区内的行,因此,如果要保留行,则必须使用MERGE PARTITIONS代替。

In addition,  Global index maintenance can now be delayed and decoupled using DROP and TRUNCATE partition without making a global index unusable.

此外,现在可以使用DROP和TRUNCATE分区来延迟和处理全局索引维护,而不会使全局索引不可用。

This new feature provides faster DROP and TRUNCATE partition operations. Index maintenance can be delayed to off-peak time.

这项新功能提供了更快的DROP和TRUNCATE分区操作。索引维护可以延迟到非高峰时间。

Dropping Partitions  删除分区

You can remove multiple partitions or subpartitions from a range or list partitioned table with the DROP PARTITIONS and DROP SUBPARTITIONS clauses of the ALTER TABLE statement.  您可以使用 ALTER TABLE 语句的 DROP PARTITIONS 和 DROP SUBPARTITIONS 子句从范围或列表分区表中删除多个分区或子分区。
For example, the example below drops multiple partitions from the Range-partitioned table, XYZ.  例如,下面的示例从范围分区表XYZ中删除多个分区。

CREATE TABLE XYZ
( prod_id NUMBER(6)
, cust_id NUMBER
, time_id DATE
, quantity_sold NUMBER(3)
, amount_sold NUMBER(10,2)
)
PARTITION BY RANGE (time_id)
(PARTITION SALES_Q2_2011 VALUES LESS THAN (TO_DATE('01-APR-2011','DD-MON-YYYY')),
PARTITION SALES_Q3_2011 VALUES LESS THAN (TO_DATE('01-OCT-2011','DD-MON-YYYY')),
PARTITION SALES_Q4_2011 VALUES LESS THAN (TO_DATE('01-JAN-2012','DD-MON-YYYY')),
PARTITION SALES_Q1_2012 VALUES LESS THAN (TO_DATE('01-APR-2012','DD-MON-YYYY')),
PARTITION SALES_Q2_2012 VALUES LESS THAN (TO_DATE('01-JUL-2012','DD-MON-YYYY')),
PARTITION SALES_Q3_2012 VALUES LESS THAN (TO_DATE('01-OCT-2012','DD-MON-YYYY')),
PARTITION SALES_Q4_2012 VALUES LESS THAN (MAXVALUE)); ALTER TABLE XYZ DROP PARTITIONS SALES_Q2_2011, SALES_Q3_2011, SALES_Q4_2011;

Note: You cannot drop all the partitions of a table. If table contains only one partition, then you cannot drop the partition. You must drop the table.  注意:您不能删除表的所有分区。如果表仅包含一个分区,则无法删除该分区。您必须drop table。
When you drop multiple partitions, local and global index operations are the same as when you drop a single partition.  That is the corresponding partitions of local indexes are also dropped in the operation, and the Global indexes must be rebuilt unless the UPDATE INDEXES or UPDATE GLOBAL INDEXES clause is specified.
删除多个分区时,本地索引和全局索引操作与删除单个分区时相同。 也就是说,在操作中也将删除本地索引的相应分区,并且除非指定了UPDATE INDEXES或UPDATE GLOBAL INDEXES子句,否则必须重建全局索引。

Truncating Partitions  截断分区

Use the ALTER TABLE ... TRUNCATE PARTITION statement to remove all rows from a table partition. The ALTER TABLE ... TRUNCATE PARTITIONS statement does this for multiple partitions.  使用 ALTER TABLE ... TRUNCATE PARTITION 语句从表分区中删除所有行。ALTER TABLE ... TRUNCATE PARTITIONS语句对多个分区执行此操作。

Truncating a partition is similar to dropping a partition, except that the partition is emptied of its data, but not physically dropped.  截断分区类似于删除分区,不同之处在于该分区清空了其数据,但并未物理删除

Using the same example as before:  使用与之前相同的示例

CREATE TABLE XYZ
( prod_id NUMBER(6)
, cust_id NUMBER
, time_id DATE
, quantity_sold NUMBER(3)
, amount_sold NUMBER(10,2)
)
PARTITION BY RANGE (time_id)
(PARTITION SALES_Q2_2011 VALUES LESS THAN (TO_DATE('01-APR-2011','DD-MON-YYYY')),
PARTITION SALES_Q3_2011 VALUES LESS THAN (TO_DATE('01-OCT-2011','DD-MON-YYYY')),
PARTITION SALES_Q4_2011 VALUES LESS THAN (TO_DATE('01-JAN-2012','DD-MON-YYYY')),
PARTITION SALES_Q1_2012 VALUES LESS THAN (TO_DATE('01-APR-2012','DD-MON-YYYY')),
PARTITION SALES_Q2_2012 VALUES LESS THAN (TO_DATE('01-JUL-2012','DD-MON-YYYY')),
PARTITION SALES_Q3_2012 VALUES LESS THAN (TO_DATE('01-OCT-2012','DD-MON-YYYY')),
PARTITION SALES_Q4_2012 VALUES LESS THAN (MAXVALUE)); ALTER TABLE XYZ TRUNCATE PARTITIONS SALES_Q2_2011, SALES_Q3_2011, SALES_Q4_2011;

The corresponding partitions of local indexes are truncated in the operation.  本地索引的相应分区在操作中被截断。
Global indexes must be rebuilt unless the UPDATE INDEXES or UPDATE GLOBAL INDEXES clause is specified.  除非指定了UPDATE INDEXES或UPDATE GLOBAL INDEXES子句,否则必须重建全局索引。

Index maintenance  索引维护

Asynchronous global index maintenance for DROP and TRUNCATE is performed by default; however, the UPDATE INDEXES clause is still required for backward compatibility.

默认情况下,对DROPTRUNCATE进行异步全局索引维护;但是,该UPDATE INDEXES子句对于向后兼容仍然是必需的。

Global index maintenance is be decoupled from the DROP and TRUNCATE partition maintenance operation without rendering a global index unusable. Index maintenance is done asynchronously and can be delayed to a later point-in-time. Delaying the global index maintenance to off-peak times without impacting the index availability makes DROP and TRUNCATE partition and subpartition maintenance operations faster and less resource intensive at the point-in-time of the partition maintenance operation.

全局索引维护与DROP和TRUNCATE分区维护操作分离,而不会导致全局索引不可用。 索引维护是异步完成的,并且可以延迟到稍后的时间点。 将全局索引维护延迟到非高峰时间而不影响索引可用性,可以在分区维护操作的时间点上更快地进行DROP和TRUNCATE分区以及子分区维护操作,并减少资源消耗。

The partition maintenance operations DROP PARTITION and TRUNCATE PARTITION that support the updating of global indexes are optimized by making the index maintenance for metadata only. This functionality enables maintenance of a list of data object numbers in metadata, where index entries corresponding to the drop and truncated objects that are invalid are ignored.

通过仅对元数据进行索引维护,可以优化支持全局索引更新的分区维护操作DROP PARTITION和TRUNCATE PARTITION。 通过此功能,可以维护元数据中的数据对象编号列表,其中将忽略与无效的丢弃对象和截断对象相对应的索引条目。

Maintenance operations on indexes can be performed with the automatic scheduler job SYS.PMO_DEFERRED_GIDX_MAINT_JOB to clean up all global indexes. This job is scheduled to run at 2:00 A.M. on a daily basis by default. You can run this job at any time using DBMS_SCHEDULER.RUN_JOB if you want to proactively clean up the indexes. You can also modify the job to run with a different schedule based on your specific requirements. However, Oracle recommends that you do not drop the job.

可以使用自动调度程序作业SYS.PMO_DEFERRED_GIDX_MAINT_JOB对索引执行维护操作,以清理所有全局索引。 该作业计划于凌晨2:00运行。 默认情况下每天。 如果要主动清理索引,可以随时使用DBMS_SCHEDULER.RUN_JOB运行此作业。 您还可以根据您的特定要求修改作业,使其以不同的时间表运行。 但是,Oracle建议您不要放弃该作业。

The DBMS_PART package provides an interface for maintenance and management operations on partitioned objects. As a consequence of prior partition maintenance operations with asynchronous global index maintenance, global indexes can contain entries pointing to data segments that no longer exist. These stale index rows will not cause any correctness issues or corruptions during any operation on the table or index, whether these are queries, DMLs, DDLs or analyze.

DBMS_PART包提供了一个接口,用于对分区对象进行维护和管理。 由于先前的分区维护操作具有异步全局索引维护,因此全局索引可以包含指向不再存在的数据段的条目。 这些陈旧的索引行在对表或索引的任何操作期间都不会引起任何正确性问题或损坏,无论它们是查询,DML,DDL还是分析。

The DBMS_PART.CLEANUP_GIDX procedure will identify and cleanup these global indexes to ensure efficiency in terms of storage and performance.

DBMS_PART.CLEANUP_GIDX过程将识别并清除这些全局索引,以确保存储和性能方面的效率。

Partial Global Index Optimization  局部全局索引优化

The column ORPHANED_ENTRIES is added to the dictionary views USER_INDEXES and USER_IND_PARTITIONS. This column specifies whether or not a global index (partition) contains stale entries due to deferred index maintenance during DROP/TRUNCATE PARTITION, or MODIFY PARTITION operations.

列ORPHANED_ENTRIES已添加到词典视图USER_INDEXES和USER_IND_PARTITIONS。 此列指定由于在DROP / TRUNCATE PARTITION或MODIFY PARTITION操作期间推迟进行索引维护,全局索引(分区)是否包含过时的条目。

The column can have one of three values:  该列可以具有以下三个值之一

• YES: The index (partition) contains orphaned entries
• NO: The index (partition) does not contain any orphaned entries
• N/A: The property is not applicable – this is the case for local indexes, or indexes
on non-partitioned tables.

You can also force a cleanup of an index needing maintenance using one of the following options:  您还可以使用以下选项之一强制清除需要维护的索引:

  • DBMS_PART.CLEANUP_GIDX: This PL/SQL package procedure gathers the list of global indexes in the system that may require cleanup and runs the operations

necessary to restore the indexes to a clean state.

exec DBMS_PART.CLEANUP_GIDX('SCHEMA','INDEXNAME');
  • ALTER INDEX REBUILD [PARTITION]: This SQL statement rebuilds the entire

index or index partition as was done prior to Oracle Database 12.1 releases; the resulting index (partition) does not contain any stale entries.

ALTER INDEX INDEXNAME REBUILD;
  • ALTER INDEX COALESCE [PARTITION] CLEANUP: This SQL statement cleans up any orphaned entries in index blocks.
ALTER INDEX  INDEXNAME COALESCE CLEANUP;

REFERENCES

BUG:26332943 - ASYNCHRONOUS GLOBAL INDEX MAINTENANCE DOES NOT WORK AFTER UPGRADE

如何在Oracle 12C中Drop/Truncate多个分区 (Doc ID 1482264.1)的更多相关文章

  1. 如何在Oracle 12C中添加多个分区 (Doc ID 1482456.1)

    How to Add Multiple Partitions in Oracle 12C (Doc ID 1482456.1) APPLIES TO: Oracle Database - Enterp ...

  2. 12C新功能:在线移动分区 (Doc ID 1584032.1)

    12C New Feature: Online Move Partition (Doc ID 1584032.1) APPLIES TO: Oracle Database - Enterprise E ...

  3. oracle 12c 中asm元数据是否有所变化

    详见原文博客链接地址: oracle 12c 中asm元数据是否有所变化

  4. Oracle 12c中新建pdb用户登录问题分析

    Oracle 12c新建用户登录问题分析1 用sys用户新建用户,提示公用用户名或角色名无效.原因:Oracle 12c中,在容器中建用户(或者应该称为使用者),须在用户名前加c##.默认登录连接的就 ...

  5. 浅析Oracle 12c中Data Guard新特性

    浅析Oracle 12c中Data Guard新特性   写在前面 无论是做Oracle运维的小伙伴还是老伙伴,想必对Oracle数据库的数据级灾备核心技术—Data Guard是再熟悉不过了!这项从 ...

  6. oracle 12c中种子数据库的隐藏与保护

    Oracle 12c种子数据库(pdbseed)的状态是read only,这是因为Oracle对种子数据库进行了保护,避免遭到破坏.保护好种子数据库的目的,是为了以此为模板,新建pdb数据库. 新的 ...

  7. MySQL中drop,truncate 和delete的区别

    注意:这里说的delete是指不带where子句的delete语句 相同点: truncate和不带where子句的delete, 以及drop都会删除表内的数据 不同点: truncate和 del ...

  8. 在Oracle 12C中使用scott账号

    在Oracle11g中默认是有scott账号的,但在Oracle 12C中则不能直接使用. 我的机器环境: 操作系统:Windows Server 2008 R2 64位 Oracle版本:Oracl ...

  9. 如何在Oracle数据库中查看哪些用户在执行哪些SQL

    对于DBA来说,这是一个非常常见的问题,DBA需要找出以下问题: 1.哪些用户在跑哪些SQL? 2.一个特定的SQL是被哪个用户在执行? 3.一个特定的用户在跑哪些SQL? 从这些问题中可以很明显的看 ...

随机推荐

  1. apache mpms和php概述

    当设置一个Apache + PHP服务器来运行你的PHP应用程序时,有许多配置参数需要处理. 最重要的是php服务器Api(server api:sapi),它决定了Apache将如何运行PHP脚本. ...

  2. JavaScript2 基础

    运算符 赋值运算符  用于给变量赋值. y=5;/z=2; 算术运算符  即算数符号,是基本算数运算.+ 加 / - 减/ * 乘/ / 除/ % 取余数/ ++ 自增(y++先赋值再自增/++y先自 ...

  3. CF 1130A 1130B 1130C1129A1 1129A2 1129B(Round542A B C D1 D2 E)题解

    A : Be Positive 题目地址:https://codeforces.com/problemset/problem/1130/A 题解:让你求是否满足一个d使得数列长为n的a数组的每个数除以 ...

  4. BZOJ 1861书架

    小T有一个很大的书柜.这个书柜的构造有些独特,即书柜里的书是从上至下堆放成一列.她用1到n的正整数给每本书都编了号. 小T在看书的时候,每次取出一本书,看完后放回书柜然后再拿下一本.由于这些书太有吸引 ...

  5. HDU-6115

    我们将A省简化为由N个城市组成,某些城市之间存在双向道路,而且A省的交通有一个特点就是任意两个城市之间都能通过道路相互到达,且在不重复经过城市的情况下任意两个城市之间的到达方案都是唯一的.聪明的你一定 ...

  6. 这个Python爬虫的简单入门及实用的实例,你会吗?

    前言本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理.作者:HOT_and_COOl 利用爬虫可以进行数据挖掘,比如可以爬取别人的网 ...

  7. 视频发布 2019 中国.NET 开发者峰会

    2019 年,注定会是 .NET Core 社区发展的关键一年,诸多重大事件在这一年发生!正如大家所期待的那样,刷新中国 .NET 社区的年度盛会--2019 中国 .NET 开发者峰会(.NET C ...

  8. 支持100+业务线、累计发布17万次|宜信容器云的A点与B点(分享实录)

    宜信公司从2018年初开始建设容器云,至今,容器云的常用基本功能已经趋于完善,主要包括服务管理.应用商店.Nginx配置.存储管理.CI/CD.权限管理等,支持100+业务线.3500+的容器运行.伴 ...

  9. 谈谈redis的特性以及使用场景

    ok?先从String开始讲: String: 这是最简单的类型,就是普通的get和set,做简单的KV缓存. 但是在真实的开发环境中,很多men可能会吧很多复杂的结构也统一转成String去储存使用 ...

  10. Python爬虫入门CentOS环境安装

    前言本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理.作者:梦想橡皮擦 CentOS环境安装-简介你好,当你打开这个文档的时候,我知 ...