如何在Oracle 12C中Drop/Truncate多个分区 (Doc ID 1482264.1)
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)语句删除多个分区并截断多个分区
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.
默认情况下,对DROP和TRUNCATE进行异步全局索引维护;但是,该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.
- 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 COALESCE [PARTITION] CLEANUP: This SQL statement cleans up any orphaned entries in index blocks.
REFERENCES
BUG:26332943 - ASYNCHRONOUS GLOBAL INDEX MAINTENANCE DOES NOT WORK AFTER UPGRADE
如何在Oracle 12C中Drop/Truncate多个分区 (Doc ID 1482264.1)的更多相关文章
- 如何在Oracle 12C中添加多个分区 (Doc ID 1482456.1)
How to Add Multiple Partitions in Oracle 12C (Doc ID 1482456.1) APPLIES TO: Oracle Database - Enterp ...
- 12C新功能:在线移动分区 (Doc ID 1584032.1)
12C New Feature: Online Move Partition (Doc ID 1584032.1) APPLIES TO: Oracle Database - Enterprise E ...
- oracle 12c 中asm元数据是否有所变化
详见原文博客链接地址: oracle 12c 中asm元数据是否有所变化
- Oracle 12c中新建pdb用户登录问题分析
Oracle 12c新建用户登录问题分析1 用sys用户新建用户,提示公用用户名或角色名无效.原因:Oracle 12c中,在容器中建用户(或者应该称为使用者),须在用户名前加c##.默认登录连接的就 ...
- 浅析Oracle 12c中Data Guard新特性
浅析Oracle 12c中Data Guard新特性 写在前面 无论是做Oracle运维的小伙伴还是老伙伴,想必对Oracle数据库的数据级灾备核心技术—Data Guard是再熟悉不过了!这项从 ...
- oracle 12c中种子数据库的隐藏与保护
Oracle 12c种子数据库(pdbseed)的状态是read only,这是因为Oracle对种子数据库进行了保护,避免遭到破坏.保护好种子数据库的目的,是为了以此为模板,新建pdb数据库. 新的 ...
- MySQL中drop,truncate 和delete的区别
注意:这里说的delete是指不带where子句的delete语句 相同点: truncate和不带where子句的delete, 以及drop都会删除表内的数据 不同点: truncate和 del ...
- 在Oracle 12C中使用scott账号
在Oracle11g中默认是有scott账号的,但在Oracle 12C中则不能直接使用. 我的机器环境: 操作系统:Windows Server 2008 R2 64位 Oracle版本:Oracl ...
- 如何在Oracle数据库中查看哪些用户在执行哪些SQL
对于DBA来说,这是一个非常常见的问题,DBA需要找出以下问题: 1.哪些用户在跑哪些SQL? 2.一个特定的SQL是被哪个用户在执行? 3.一个特定的用户在跑哪些SQL? 从这些问题中可以很明显的看 ...
随机推荐
- UESTC1961-咸鱼睡觉觉
咸鱼睡觉觉 Time Limit: 1000 MS Memory Limit: 64 MB Submit Status 咸鱼要睡觉觉了! 但那群咕咕有点烦. 咸鱼决定要赶走一些咕咕,使得他们不 ...
- 静态页面开发JS页面跳转加密解密URL和参数
页面跳转加密URL地址参数传递 window.location.href="foot.html?"+"good="+encodeURI(encodeURI(go ...
- html小工具——文章注释编辑器
在网上阅读文章时,读者时常会想针对某段文字写一些自己的感想,可惜大部分阅读网站并不提供这样的功能,读者往往只能将文本复制到本地或在线的编辑器中编辑注释,之后如果想在其他地方回顾这些注释也必须先本地安装 ...
- Python3 文件处理
目录 文件操作的流程 文件的三种打开模式 读取: rt read_text 针对文本内容只读 清空写入: wt write_text 针对文本内容只写 追加写入: at append_text 针对文 ...
- VMware虚拟机安装Linux(CentOS)系统
vmware workstation 虚拟机官方下载路径:https://www.vmware.com/cn/products/workstation-pro/workstation-pro-eval ...
- LNMP-Nginx配置不记录静态文件、过期时间
用户访问web网站,通常日志文件会记录很多web站点上的一些静态文件信息,如果长期不处理,日志文件会越来越大,占用的系统资源也越大,此时就需要我们配置不记录静态文件和过期时间,减少日志文件记录过多不必 ...
- irules
BIG-IP系统iRules基本概念_v11.6.1 2017年10月10日 00:35:16 ifelif 阅读数:1097 1 iRules介绍 什么是iRule iRule是BIG-IP本地 ...
- python爬虫--selenium模块.上来自己动!
selenium 基本操作 from selenium import webdriver from time import sleep #实例化一个浏览器对象 bro = webdriver.Chro ...
- 在Linux系统下制作系统启动盘(Ubuntu Linux)
在Linux系统下制作系统启动盘有两种方法: 1.用dd命令 2.用Linux自带的图形界面工具 Startup Disk Creator 本教程使用第2种方式,用Linux自带的图形界面工具制作系统 ...
- django基础之day08,ajax结合sweetalert的使用
models.py文件 from django.db import models class User(models.Model): username=models.CharField(max_len ...