189 8069 5689

数据库中分区表如何删除分区、分区对应的tablespace、datafile

这篇文章给大家分享的是有关数据库中分区表如何删除分区、分区对应的tablespace、datafile的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

创新互联致力于互联网品牌建设与网络营销,包括成都做网站、网站设计、SEO优化、网络推广、整站优化营销策划推广、电子商务、移动互联网营销等。创新互联为不同类型的客户提供良好的互联网应用定制及解决方案,创新互联核心团队10余年专注互联网开发,积累了丰富的网站经验,为广大企业客户提供一站式企业网站建设服务,在网站建设行业内树立了良好口碑。

Truncate分区的SQL
ALTER TABLE table_name TRUNCATE PARTITION p1 DROP STORAGE UPDATE GLOBAL INDEXES;
Drop分区的SQL
ALTER TABLE table_name DROP PARTITION p1 UPDATE GLOBAL INDEXES;


实战的一个案例,需要删除6个月以前的分区,并删除分区对应的表空间和数据文件
ALTER TABLE ESB_MSG_LOG DROP PARTITION ESBLOG201607 UPDATE GLOBAL INDEXES;
select * from dba_segments where tablespace_name like 'ESBLOG201607%';(没结果说明表空间可以删除)
删除分区对应的表空间和数据文件的两种方法
1、这种方式比较安全,一旦表空间非空,drop就会报错,drop成功后再在OS上rm
Drop tablespace ESBLOG201607;
rm -f /u01/app/oracle/oradata/payroll/ESBLOG201607.dbf
2、如果有DATAGUARD,建议主库使用这种方式
Drop tablespace ESBLOG201607 INCLUDING CONTENTS and DATAFILES;

INCLUDING CONTENTS
Specify INCLUDING CONTENTS to drop all the contents of the tablespace. You must specify this clause to drop a tablespace that contains any database objects. If you omit this clause, and the tablespace is not empty, then the database returns an error and does not drop the tablespace.
指定INCLUDING CONTENTS以删除表空间的所有内容。 您必须指定此子句来删除包含任何数据库对象的表空间。
如果省略此子句,并且表空间不为空,则数据库返回错误,并且不会删除表空间。

AND DATAFILES
When you specify INCLUDING CONTENTS, the AND DATAFILES clause lets you instruct the database to delete the associated operating system files as well. Oracle Database writes a message to the alert log for each operating system file deleted. This clause is not needed for Oracle Managed Files, because they are removed from the system even if you do not specify AND DATAFILES.
当指定INCLUDING CONTENTS时,AND DATAFILES子句允许您指示数据库删除关联的操作系统文件。 每个操作系统文件被删除时,Oracle数据库将向警报日志写入一条消息。 OMF不需要此子句,因为即使没有指定AND DATAFILES也会从系统中删除该文件。

You can issue the SQL DROP TABLESPACE INCLUDING CONTENTS AND DATAFILES statement on the primary database to delete the datafiles on both the primary and standby databases.





truncate_partition_subpart
Specify TRUNCATE PARTITION to remove all rows from the partition identified by partition_extended_name or, if the table is composite partitioned, all rows from the subpartitions of that partition. Specify TRUNCATE SUBPARTITION to remove all rows from an individual subpartition. If table is index organized, then Oracle Database also truncates any corresponding mapping table partitions and overflow area partitions.

If the partition or subpartition to be truncated contains data, then you must first disable any referential integrity constraints on the table. Alternatively, you can delete the rows and then truncate the partition.

If table contains any LOB columns, then the LOB data and LOB index segments for this partition are also truncated. If table is composite partitioned, then the LOB data and LOB index segments for the subpartitions of the partition are truncated.

If table contains any equipartitioned nested tables, then you cannot truncate the parent partition unless its corresponding nested table partition is empty.

If a domain index is defined on table, then the index must not be marked IN_PROGRESS or FAILED, and the index partition corresponding to the table partition being truncated must not be marked IN_PROGRESS.

For each partition or subpartition truncated, Oracle Database also truncates corresponding local index partitions and subpartitions. If those index partitions or subpartitions are marked UNUSABLE, then the database truncates them and resets the UNUSABLE marker to VALID.

You can update global indexes on table during this operation using the update_global_index_clause or the update_all_indexes_clause. If you specify the parallel_clause with one of these clauses, then the database parallelizes the index update, not the truncate operation.

DROP STORAGE
Specify DROP STORAGE to deallocate all space from the deleted rows, except the space allocated by the MINEXTENTS parameter. This space can subsequently be used by other objects in the tablespace.

DROP ALL STORAGE
Specify DROP ALL STORAGE to deallocate all space from the deleted rows, including the space allocated by the MINEXTENTS parameter. All segments for the partition or subpartition, as well as all segments for its dependent objects, will be deallocated.

指定TRUNCATE PARTITION以从partition_extended_name标识的分区中删除所有行,如果表是复合分区,则该分区子分区中的所有行。 指定TRUNCATE SUBPARTITION以从单个子分区中删除所有行。 如果表是索引组织的,则Oracle数据库还会截断任何相应的映射表分区和溢出区分区。

如果要截断的分区或子分区包含数据,则必须首先禁用表上的任何引用完整性约束。 或者,您可以删除行,然后截断分区。

如果表包含任何LOB列,则此分区的LOB数据和LOB索引段也将被截断。 如果表是复合分区的,则分区的子分区的LOB数据和LOB索引段将被截断。

如果表包含任何均分的嵌套表,那么除非相应的嵌套表分区为空,否则不能截断父分区。

如果域索引在表上定义,则索引不能被标记为IN_PROGRESS或FAILED,并且与表分区相对应的索引分区被截断不能被标记为IN_PROGRESS。

对于截断的每个分区或子分区,Oracle数据库还会截断相应的local索引分区和子分区。 如果这些索引分区或子分区标记为UNUSABLE,则数据库将截断它们,并将UNUSABLE标记重置为VALID。

您可以使用update_global_index_clause或update_all_indexes_clause在此操作期间更新表上的全局索引。 如果您使用这些子句之一指定parallel_clause,则数据库会并行化索引更新,而不是截断操作。

DROP存储
指定DROP STORAGE可以从删除的行中释放所有空间,除了由MINEXTENTS参数分配的空间。 该空间随后可以被表空间中的其他对象使用。

DROP所有存储
指定DROP ALL STORAGE以从已删除的行中释放所有空间,包括由MINEXTENTS参数分配的空间。 分区或子分区的所有段以及其依赖对象的所有段将被释放。



drop_table_partition
The drop_table_partition clause removes the partition identified by partition_extended_name, and the data in that partition, from a partitioned table. If you want to drop a partition but keep its data in the table, then you must merge the partition into one of the adjacent partitions.

If table has LOB columns, then Oracle Database also drops the LOB data and LOB index partitions and any subpartitions corresponding to partition.

If table has equipartitioned nested table columns, then Oracle Database also drops the nested table partitions corresponding to the table partition being dropped.

If table is index organized and has a mapping table defined on it, then the database drops the corresponding mapping table partition as well.

Oracle Database drops local index partitions and subpartitions corresponding to the dropped partition, even if they are marked UNUSABLE.

You can update indexes on table during this operation using the update_index_clauses. If you specify the parallel_clause with the update_index_clauses, then the database parallelizes the index update, not the drop operation.

If you drop a range partition and later insert a row that would have belonged to the dropped partition, then the database stores the row in the next higher partition. However, if that partition is the highest partition, then the insert will fail, because the range of values represented by the dropped partition is no longer valid for the table.

Restrictions on Dropping Table Partitions 
Dropping table partitions is subject to the following restrictions:
You cannot drop a partition of a hash-partitioned table. Instead, use the coalesce_table_partition clause.
If table contains only one partition, then you cannot drop that partition. Instead, drop the table.
If you update global indexes using the update_index_clauses, then you can specify only the UPDATE INDEXES keywords but not the subclause.

drop_table_partition子句从分区表中删除由partition_extended_name标识的分区以及该分区中的数据。 如果要删除分区但将其数据保留在表中,则必须将分区合并到相邻分区之一中。

如果表具有LOB列,则Oracle数据库还会丢弃与分区对应的LOB数据和LOB索引分区以及任何子分区。

如果表具有等分嵌套表列,则Oracle数据库还会删除与要删除的表分区相对应的嵌套表分区。

如果表是索引组织的,并在其上定义了一个映射表,那么数据库也会丢弃相应的映射表分区。

即使Oracle数据库标记为UNUSABLE,Oracle数据库也会删除对应于已删除分区的本地索引分区和子分区。

您可以使用update_index_clauses在此操作期间更新表上的索引。 如果使用update_index_clauses指定parallel_clause,则数据库会并行化索引更新,而不是删除操作。

如果删除范围分区,然后插入属于删除分区的行,则数据库将该行存储在下一个较高分区中。 但是,如果该分区是最高分区,则插入将失败,因为由删除的分区表示的值的范围对于表不再有效。

删除表分区的限制
删除表分区受以下限制:
您不能删除散列分区表的分区。 而是使用coalesce_table_partition子句。
如果表仅包含一个分区,则不能删除该分区。 而是删除表。
如果您使用update_index_clauses更新全局索引,则可以仅指定UPDATE INDEXES关键字,但不能指定子条款。



drop_table_subpartition
Use this clause to drop a range or list subpartition from a range, list, or hash composite-partitioned table. Oracle Database deletes any rows in the dropped subpartition.

Oracle Database drops the corresponding subpartition of any local index. Other index subpartitions are not affected. Any global indexes are marked UNUSABLE unless you specify the update_global_index_clause or update_all_indexes_clause.

Restrictions on Dropping Table Subpartitions 
Dropping table subpartitions is subject to the following restrictions:
You cannot drop a hash subpartition. Instead use the MODIFY PARTITION ... COALESCE SUBPARTITION syntax.
If a partition contains only one subpartition, then you cannot drop that subpartition. Instead, use the drop_table_partition clause.
If you update the global indexes, then you cannot specify the optional subclause of the update_all_indexes_clause.

使用此子句从范围,列表或哈希复合分区表中删除范围或列表子分区。 Oracle数据库删除丢弃的子分区中的任何行。

Oracle数据库删除任何local索引的相应子分区。 其他索引子分区不受影响。 任何全局索引都标记为UNUSABLE,除非您指定update_global_index_clause或update_all_indexes_clause。

删除表子分区的限制
删除表子分区受以下限制:
您不能删除哈希子分区。 而是使用MODIFY PARTITION ... COALESCE SUBPARTITION语法。
如果一个分区只包含一个子分区,则不能删除该子分区。 而是使用drop_table_partition子句
如果更新全局索引,则不能指定update_all_indexes_clause的可选子条款。



update_all_indexes_clause
Use this clause to update all indexes on table.



update_global_index_clause
Use this clause to update only global indexes on table. Oracle Database marks UNUSABLE all local indexes on table.

UPDATE GLOBAL INDEXES 
Specify UPDATE GLOBAL INDEXES to update the global indexes defined on table.

Restriction on Updating Global Indexes 
If the global index is a global domain index defined on a LOB column, then Oracle Database marks the domain index UNUSABLE instead of updating it.

INVALIDATE GLOBAL INDEXES 
Specify INVALIDATE GLOBAL INDEXES to invalidate the global indexes defined on table.

If you specify neither, then Oracle Database invalidates the global indexes.

Restrictions on Invalidating Global Indexes 
This clause is supported only for global indexes. It is not supported for index-organized tables. In addition, this clause updates only indexes that are USABLE and VALID. UNUSABLE indexes are left unusable, and INVALID global indexes are ignored.

使用此子句仅更新表上的全局索引。 Oracle数据库标记UNUSABLE表上的所有本地索引。

UPDATE GLOBAL INDEXES
指定UPDATE GLOBAL INDEXES来更新表上定义的全局索引。

UPDATE GLOBAL INDEXES 的限制
如果全局索引是在LOB列上定义的全局域索引,则Oracle数据库会标记域索引UNUSABLE而不是更新它。

INVALIDATE GLOBAL INDEXES
指定INVALIDATE GLOBAL INDEXES以使表上定义的全局索引无效。

如果既不指定INVALIDATE GLOBAL INDEXES也不指定UPDATE GLOBAL INDEXES ,则Oracle数据库会使全局索引失效。

感谢各位的阅读!关于“数据库中分区表如何删除分区、分区对应的tablespace、datafile”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!


网站名称:数据库中分区表如何删除分区、分区对应的tablespace、datafile
文章网址:http://cdxtjz.cn/article/ijjgpj.html

其他资讯