OceanBase logo

OceanBase

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

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

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

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 Best Practices

All Versions

  • Deploy
    • Configuration guide for read-write splitting in AP scenarios
    • Best practices for read-write splitting
  • Migrate
    • Data transfer solutions in OceanBase Database
    • Overview on data migration
    • Best practices for importing data files to OceanBase Database
    • Best practice for migrating data from other databases to OceanBase Database
    • Massive data migration strategy
    • Best practices for migrating data from MyCat to OceanBase Database
    • Best practices for migrating PostgreSQL to OceanBase MySQL-compatible mode
  • Route
    • ODP routing best practices
  • Table Design
    • Best practices for table design and index optimization
    • Best practices for creating indexes on large tables
    • Best practices for database development
  • Develop
    • Best practices for connecting Java applications to OceanBase Database
    • Best practices for integrating Spark Catalog with OceanBase Database
    • Best practices for achieving optimal performance in batch DML using JDBC and OBServer
    • Best practices for bulk data cleanup in OceanBase Database
    • Best practices for PDML processing in OceanBase Database
    • Best practices for hot tables in OceanBase Database
    • Best practices for auto-increment columns and sequences in OceanBase Database
  • Manage
    • Best practices for resource throttling
    • Best practices for data load balancing
    • Best practices for security certification
    • Best practices for access control
    • Best practices for data encryption
  • Diagnose
    • Best practices for log interpretation in common scenarios
    • Best practices for end-to-end tracing
    • Best practices for using obdiag to collect performance information
    • Best practices for using obdiag to collect diagnostic information of parallel and slow SQL statements
    • Best practices for troubleshooting OceanBase Database performance issues
  • Performance Tuning
    • Best practices for handling slow queries
    • Best practices for collecting statistics to generate an efficient execution plan
    • Best practices for updating hotspot rows
    • Best practices for large object storage performance
    • Best practices for semi-structured storage performance
    • Best practices for OceanBase materialized views
  • Cloud Database
    • Best practices for achieving high availability through cross-cloud active-active deployment
    • High availability through primary and standby databases across clouds
    • High host CPU usage
    • Best practices for read/write splitting in OceanBase Cloud

Download PDF

Configuration guide for read-write splitting in AP scenarios Best practices for read-write splitting Data transfer solutions in OceanBase Database Overview on data migration Best practices for importing data files to OceanBase Database Best practice for migrating data from other databases to OceanBase Database Massive data migration strategy Best practices for migrating data from MyCat to OceanBase Database Best practices for migrating PostgreSQL to OceanBase MySQL-compatible mode ODP routing best practices Best practices for table design and index optimization Best practices for creating indexes on large tables Best practices for database development Best practices for connecting Java applications to OceanBase Database Best practices for integrating Spark Catalog with OceanBase Database Best practices for achieving optimal performance in batch DML using JDBC and OBServer Best practices for bulk data cleanup in OceanBase Database Best practices for PDML processing in OceanBase Database Best practices for hot tables in OceanBase Database Best practices for auto-increment columns and sequences in OceanBase Database Best practices for resource throttling Best practices for data load balancing Best practices for security certification Best practices for access control Best practices for data encryption Best practices for log interpretation in common scenarios Best practices for end-to-end tracing Best practices for using obdiag to collect performance information Best practices for using obdiag to collect diagnostic information of parallel and slow SQL statements Best practices for troubleshooting OceanBase Database performance issues Best practices for handling slow queries Best practices for collecting statistics to generate an efficient execution plan Best practices for updating hotspot rows Best practices for large object storage performance Best practices for semi-structured storage performance Best practices for OceanBase materialized views Best practices for achieving high availability through cross-cloud active-active deployment High availability through primary and standby databases across clouds High host CPU usage Best practices for read/write splitting in OceanBase Cloud
OceanBase logo

The Unified Distributed Database for the AI Era.

Follow Us
Products
OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
Resources
DocsBlogLive DemosTraining & Certification
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 Best Practices
  3. master
iconOceanBase Best Practices
master
  • master

Best practices for bulk data cleanup in OceanBase Database

Last Updated:2025-06-30 02:37:51  Updated
share
What is on this page
Characteristics of business scenarios
Pain points
Limitations of the traditional TRUNCATE TABLE method
Business impact
Solutions
Performance testing
Test environment
Test results
Conclusion
References

folded

share

In OceanBase Database, cleaning up data from a large number of small tables at once is a common maintenance task. The ability to execute the TRUNCATE TABLE statement in parallel varies by OceanBase version, directly affecting the efficiency of batch table cleanup and the choice of best practices.

  • OceanBase V3.x and earlier: The TRUNCATE TABLE statement executes serially within a tenant, resulting in low efficiency when cleaning up many small tables. In this case, use concurrent DELETE operations with batch commits to improve cleanup performance.
  • OceanBase V4.x and later: The TRUNCATE TABLE statement supports parallel execution, significantly increasing the efficiency of batch table cleanup. Use parallel TRUNCATE TABLE for these versions.

This topic explains how to use different data cleanup methods in various scenarios, analyzes the performance of each approach in specific environments based on test results, and provides best practice recommendations for different versions. Test results are for reference only. Evaluate actual performance based on your business environment and system configuration.

Note

Starting from OceanBase Database V4.x, the TRUNCATE TABLE statement supports parallel execution, significantly improving the efficiency of batch table cleanup. For versions earlier than V4.x, use concurrent DELETE operations with batch commits.

Characteristics of business scenarios

  • Large number of small tables: A typical system contains hundreds or even thousands of tables.
  • Small data volume: Each table usually contains a few hundred to several thousand rows.
  • Frequent table cleanup: Data often needs to be batch cleaned at specific times, such as at the end of the day or month.
  • Strict time window requirements: Business processing windows are tight, and the efficiency of data cleanup directly affects subsequent business operations.

Pain points

Limitations of the traditional TRUNCATE TABLE method

  • Serial execution limitation: In OceanBase Database V3.X, TRUNCATE TABLE operations cannot be executed in parallel within a tenant.
  • Resource contention: Running a large number of TRUNCATE TABLE operations can lead to competition for DDL resources.
  • Low execution efficiency: When cleaning up hundreds of tables, serial execution causes total cleanup time to increase linearly.

Note

Only DDL operations that support parallel execution can run in parallel. If a serial DDL operation is included, the entire DDL execution switches to serial mode. For best results, include only DDL operations that support parallel execution during TRUNCATE TABLE operations. If other DDL operations are present, check whether they support parallel execution.

Business impact

  • Truncate operations become a bottleneck for system performance.
  • The batch processing window is extended, affecting subsequent business processing.
  • System resource utilization becomes uneven.

Solutions

  1. Batch processing design

    • Create a temporary table to store the names of tables to be processed.
    • Dynamically generate and execute DELETE statements.
    -- Create a table to store the names of tables to be processed.
    CREATE TABLE tables_to_clean (table_name VARCHAR(100));
    INSERT INTO tables_to_clean VALUES ('fund_daily_position'), ('fund_transaction'), ...;
    
    -- Dynamically generate and execute DELETE statements.
    BEGIN
      FOR r IN (SELECT table_name FROM tables_to_clean) LOOP
        EXECUTE IMMEDIATE 'DELETE FROM ' || r.table_name;
      END LOOP;
    END;
    
  2. Parallelism adjustment

    • Set the session-level degree of parallelism.
    • Increase the workspace memory.
    • Set an appropriate degree of parallelism.
    -- Set the session-level degree of parallelism.
    SET ob_sql_work_area_percentage = 30;  -- Increase the workspace memory.
    SET parallel_servers_target = 16;         -- Set the degree of parallelism.
    
  3. Session parallelism

    • Use multiple sessions to concurrently execute DELETE operations.
    • Dynamically allocate session groups based on the number of tables.
  4. Transaction management

    • Submit transactions in batches to avoid a single large transaction.
    • Process a subset of tables in each batch.
    • Perform staged commits.
    -- Submit transactions in batches to avoid a single large transaction.
    BEGIN
    FOR i IN 1..10 LOOP
       -- Process a portion of tables in each batch.
       DELETE FROM table_group_1;
       DELETE FROM table_group_2;
       COMMIT;  -- Perform a staged commit.
    END LOOP;
    END;
    

Performance testing

Test environment

  • OceanBase Database V4.3.5
  • Cluster configuration: single-node, single-replica deployment, with 16 CPU cores and 64 GB memory per node
  • Test dataset: 100 tables, each with 1,000 rows
  • Tenant specifications: 8 CPU cores, 32 GB of memory, cpu_quota_concurrency set to 4.

Test results

Method Tables Total rows Time consumed (s) TPS
TRUNCATE TABLE (serial execution) 100 100,000 8.00 12,500
TRUNCATE TABLE (parallel execution, with a concurrency level of 10) 100 100,000 1.1 90,909
DELETE (with batch commit) 100 100,000 2.00 50,000

The test results show that:

  • The TRUNCATE TABLE (serial execution) method takes 8 seconds.
  • The TRUNCATE TABLE (parallel execution) method takes 1.2 seconds.
  • The DELETE method with batch commit takes 2 seconds.
  • The TPS of the TRUNCATE TABLE (parallel execution) method (83,333) is higher than that of the other two methods.
  • The performance of the TRUNCATE TABLE (parallel execution) method is better than that of the other two methods.

The performance in your actual environment may vary due to the following factors:

  • Actual hardware configuration and system load
  • OceanBase Database version and parameter settings
  • Table structure, number of indexes, and constraint types
  • Actual data volume and data distribution

You can monitor performance metrics by using the following statements:

-- Monitor the execution status
SELECT * FROM gv$session_longops WHERE opname LIKE '%DELETE%';

-- Monitor resource usage
SELECT * FROM gv$sysstat WHERE name LIKE '%parallel%';

We recommend that you test any optimization solution in a test environment similar to your production environment to obtain accurate performance data before implementation.

Notice

  • DDELETE operations generate undo logs. Ensure sufficient undo space is available.
  • Consider referential integrity constraints when cleaning up related tables.
  • Run ANALYZE TABLE regularly to maintain statistics.

Note

The test results mentioned above are for reference only. Actual performance will vary depending on your business environment and system configuration.

Conclusion

When cleaning up a large number of small tables in OceanBase Database, the parallel TRUNCATE TABLE strategy can significantly improve system performance and resource utilization in V4.X. In V3.X, we recommend using the DELETE command with batch commits. By properly designing batch processing logic and parallelism, you can shorten the time window for bulk table cleanup and provide more time for business operations. Specific recommendations:

  • OceanBase V4.X: We recommend that you use the parallel TRUNCATE TABLE command.
  • OceanBase V3.X: We recommend that you use the DELETE command with batch commit.
  • Choose the optimal table cleanup strategy based on your OceanBase version to improve overall system performance.

This best practice is particularly suitable for business scenarios with a large number of tables but small data volumes per table, and it effectively addresses the limitation that TRUNCATE TABLE operations cannot be performed in parallel in OceanBase Database.

References

  • GV$SYSSTAT
  • GV$SESSION_LONGOPS
  • parallel_servers_target
  • ob_sql_work_area_percentage

Previous topic

Best practices for achieving optimal performance in batch DML using JDBC and OBServer
Last

Next topic

Best practices for PDML processing in OceanBase Database
Next
What is on this page
Characteristics of business scenarios
Pain points
Limitations of the traditional TRUNCATE TABLE method
Business impact
Solutions
Performance testing
Test environment
Test results
Conclusion
References