OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Database

SQL - V4.6.0

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive DemosTraining & CertificationTicket
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Database
    3. SQL
    4. V4.6.0
    iconOceanBase Database
    SQL - V 4.6.0
    Databases
    • OceanBase Database
    • OceanBase Cloud
    • OceanBase Tugraph
    • Interactive Tutorials
    • OceanBase Best Practices
    Tools
    • OceanBase Cloud Platform
    • OceanBase Migration Service
    • OceanBase Developer Center
    • OceanBase Migration Assessment
    • OceanBase Admin Tool
    • OceanBase Loader and Dumper
    • OceanBase Deployer
    • Kubernetes operator for OceanBase
    • OceanBase Diagnostic Tool
    • OceanBase Binlog Service
    Connectors and Middleware
    • OceanBase Database Proxy
    • Embedded SQL in C for OceanBase
    • OceanBase Call Interface
    • OceanBase Connector/C
    • OceanBase Connector/J
    • OceanBase Connector/ODBC
    • OceanBase Connector/NET
    SQL
    KV
    • V 4.6.0
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    Truncate a partition

    Last Updated:2026-05-07 11:26:25  Updated
    Share
    What is on this page
    Supported operations for truncating a partition
    Considerations
    Impact of truncate partition on global indexes
    Impact of truncate partition on concurrent DDL/DML/Queries
    Truncate a partition in a partitioned table
    Syntax
    Examples
    Truncate a subpartition
    Syntax
    Examples

    folded

    Share

    You can truncate a partition in a partitioned table to clear the data in the partition, while retaining the partition structure.

    Supported operations for truncating a partition

    In OceanBase Database in Oracle mode:

    • For a partitioned table, you can truncate a RANGE partition or a LIST partition, but you cannot truncate a HASH partition.

    • For a subpartitioned table, you can truncate a RANGE or LIST subpartition.

    The following table describes the support for truncating a partition in a partitioned table or subpartitioned table in OceanBase Database in Oracle mode.

    Partitioned table
    Partition type
    Truncate a partition
    Truncate a subpartition
    Partitioned table RANGE / LIST Supported -
    Partitioned table HASH Not supported -
    Subpartitioned table RANGE + RANGE / RANGE + LIST Supported Supported
    Subpartitioned table RANGE + HASH Supported Not supported
    Subpartitioned table LIST + RANGE / LIST + LIST Supported Supported
    Subpartitioned table LIST + HASH Supported Not supported
    Subpartitioned table HASH + RANGE / HASH + LIST Not supported Supported
    Subpartitioned table HASH + HASH Not supported Not supported

    Considerations

    When you truncate a partition, make sure that there are no active transactions or queries on the partition. Otherwise, an error may occur or unexpected behavior may be observed. You can query the oceanbase.GV$OB_TRANSACTION_PARTICIPANTS view in the sys tenant to obtain the context of transactions that have not been completed.

    Impact of truncate partition on global indexes

    In Oracle mode, when you truncate a partition in a partitioned table or subpartitioned table that has a global index, you must add the UPDATE GLOBAL INDEXES keyword to the ALTER TABLE statement to update the global index information. If you do not add the UPDATE GLOBAL INDEXES keyword, the global index on the partitioned table will be unavailable after the partition is truncated.

    For a table that is partitioned by RANGE, INTERVAL, or LIST (including partitioned and subpartitioned tables) and supports the TRUNCATE operation, when you specify UPDATE GLOBAL INDEXES, the system does not rebuild the global index. Instead, it uses a lazy maintenance strategy to delete data in the background and keep the index valid. This prevents query interruptions or performance degradation caused by an invalid index. Note that this optimization is only applicable to regular global indexes. The following scenarios cannot trigger this optimization:

    • The partitioned table is partitioned by HASH (even if the subpartitions are RANGE or LIST), and you truncate a subpartition.
    • The partitioning key is an expression, not a regular column.

    Note

    Starting from V4.6.0, the INTERVAL partitioned table in V4.6.x supports the UPDATE GLOBAL INDEXES syntax.

    Hidden configuration items for controlling global index behavior during partition DDL operations

    Starting from V4.3.5 BP2, OceanBase Database introduces a tenant-level hidden configuration item _ob_enable_truncate_partition_preserve_global_index for V4.3.5. This configuration item controls whether to allow global indexes to remain valid during TRUNCATE/DROP operations on the main table's partitions (referred to as partition DDL operations). For upgraded tenants, the default value of this hidden configuration item is False, while for newly created tenants, the default value is True. The behavior of these values is as follows:

    Configuration Item Value
    Behavior During Partition DDL Execution
    Result After Partition DDL Execution
    True Only the TRUNCATE/DROP partitions are not allowed to execute DML operations, while other partitions of the main table can execute DML operations normally. Global indexes remain valid: DML operations can be executed on the main table and all index tables, and the global indexes related to the main table remain valid.
    False Only the TRUNCATE/DROP partitions are not allowed to execute DML operations, while other partitions of the main table can execute DML operations normally. Global indexes become invalid: DML operations can be executed on the main table and all index tables, but the global indexes related to the main table become invalid or are rebuilt.

    Here are some examples:

    • Index remains valid.

      obclient> ALTER SYSTEM SET "_ob_enable_truncate_partition_preserve_global_index" = True;
      
    • Index becomes invalid.

      obclient> ALTER SYSTEM SET "_ob_enable_truncate_partition_preserve_global_index" = False;
      

    Impact of truncate partition on concurrent DDL/DML/Queries

    Truncate partition is an offline DDL operation. During the truncation of a partition, OceanBase Database adds an exclusive lock at the partition level on the target partition.

    Operation Type
    Impact During Truncate Partition Execution
    Concurrent DDL Prohibited or blocked. Any other DDL operations on the same table cannot be executed concurrently.
    Concurrent DML
    • On the target partition: Completely blocked.
    • On other partitions: Generally allowed to execute concurrently, provided that the statements can clearly access other partitions.
    Concurrent Query (SELECT) Not affected and can be executed normally.

    Truncate a partition in a partitioned table

    You can truncate a partition in a partitioned table or subpartitioned table as needed.

    Syntax

    ALTER TABLE table_name TRUNCATE PARTITION partition_name_list [UPDATE GLOBAL INDEXES];
    
    partition_name_list:
      partition_name [, partition_name ...]
    

    Note

    • You can truncate one or more partitions in a partitioned table.

    • When you truncate a partition in a subpartitioned table, the data in the partition and its corresponding subpartitions will be cleared.

    Examples

    • Truncate the M202001 and M202002 partitions in the tbl1_r partitioned table and update the global index information.

      obclient> CREATE TABLE tbl1_r(log_id INT,log_date DATE NOT NULL DEFAULT SYSDATE)
             PARTITION BY RANGE(log_date) 
              (PARTITION M202001 VALUES LESS THAN(TO_DATE('2020/02/01','YYYY/MM/DD'))
               , PARTITION M202002 VALUES LESS THAN(TO_DATE('2020/03/01','YYYY/MM/DD'))
               , PARTITION M202003 VALUES LESS THAN(TO_DATE('2020/04/01','YYYY/MM/DD'))
               , PARTITION M202004 VALUES LESS THAN(TO_DATE('2020/05/01','YYYY/MM/DD'))
               , PARTITION M202005 VALUES LESS THAN(TO_DATE('2020/06/01','YYYY/MM/DD'))
               , PARTITION M202006 VALUES LESS THAN(TO_DATE('2020/07/01','YYYY/MM/DD'))
               , PARTITION M202007 VALUES LESS THAN(TO_DATE('2020/08/01','YYYY/MM/DD'))
               , PARTITION M202008 VALUES LESS THAN(TO_DATE('2020/09/01','YYYY/MM/DD'))
               , PARTITION M202009 VALUES LESS THAN(TO_DATE('2020/10/01','YYYY/MM/DD'))
               , PARTITION M202010 VALUES LESS THAN(TO_DATE('2020/11/01','YYYY/MM/DD'))
               , PARTITION M202011 VALUES LESS THAN(TO_DATE('2020/12/01','YYYY/MM/DD'))
               , PARTITION M202012 VALUES LESS THAN(TO_DATE('2021/01/01','YYYY/MM/DD'))
               , PARTITION MMAX VALUES LESS THAN (MAXVALUE)
               );
      Query OK, 0 rows affected
      
      obclient> ALTER TABLE tbl1_r TRUNCATE PARTITION M202001,M202002 UPDATE GLOBAL INDEXES;
      Query OK, 0 rows affected
      
    • Truncate the p0 and p1 partitions in the t2_f_rl subpartitioned table, which is partitioned by RANGE and subpartitioned by LIST.

      obclient> ALTER TABLE t2_f_rl TRUNCATE PARTITION p0,p1;
      

    Truncate a subpartition

    You can truncate a subpartition in a subpartitioned table as needed.

    Syntax

    ALTER TABLE table_name TRUNCATE SUBPARTITION subpartition_name_list[ UPDATE GLOBAL INDEXES ];
    
    subpartition_name_list:
      subpartition_name[, subpartition_name ...]
    

    Note

    You can truncate one or more subpartitions in a subpartitioned table.

    Examples

    Truncate the sp3 and sp4 subpartitions in the p1 partition of the t2_f_lr subpartitioned table and update the global index information.

    obclient> CREATE TABLE t2_f_rl(col1 INT,col2 VARCHAR2(50))
           PARTITION BY RANGE(col1)
           SUBPARTITION BY LIST(col2)
           (PARTITION p0 VALUES LESS THAN(100)
             (SUBPARTITION sp0 VALUES('01'),
              SUBPARTITION sp1 VALUES('02')
              ),
            PARTITION p1 VALUES LESS THAN(200)
             (SUBPARTITION sp2 VALUES('01'),
              SUBPARTITION sp3 VALUES('02'),
              SUBPARTITION sp4 VALUES('03')
             )
            );
    Query OK, 0 rows affected
    
    obclient> ALTER TABLE t2_f_rl TRUNCATE SUBPARTITION sp3,sp4 UPDATE GLOBAL INDEXES;
    Query OK, 0 rows affected
    

    Previous topic

    Drop partitions
    Last

    Next topic

    Partition pruning
    Next
    What is on this page
    Supported operations for truncating a partition
    Considerations
    Impact of truncate partition on global indexes
    Impact of truncate partition on concurrent DDL/DML/Queries
    Truncate a partition in a partitioned table
    Syntax
    Examples
    Truncate a subpartition
    Syntax
    Examples