This topic describes how to perform a major compaction.
Background information
The storage engine of OceanBase Database is based on the LSM-tree architecture. Data is divided into static baseline data (stored in SSTables) and dynamic incremental data (stored in MemTables). SSTables are read-only and stored on disk; they are not modified after generation. MemTables support both read and write operations and are stored in memory. DML operations such as INSERT, UPDATE, and DELETE are first written to a MemTable. When a MemTable reaches a certain size, it is flushed to disk as an SSTable. For more information, see Storage architecture overview.
When the size of a MemTable exceeds a certain threshold, the data in the MemTable is flushed to an SSTable to free up memory. This process is called a minor compaction. For more information about minor compactions, see Minor compaction.
A minor compaction generates a new SSTable. When the number of minor compactions exceeds a certain threshold, or during daily off-peak business hours, the system merges the baseline SSTable with the incremental SSTables generated by subsequent minor compactions into a single SSTable. This process is called a major compaction. For more information about major compactions, see Major compaction.
Scenarios
Scheduled major compaction: No manual scheduling is required. You can configure the system to automatically initiate major compactions during off-peak hours based on your actual business workload.
Manual major compaction: You can manually initiate a major compaction at any time based on your actual business needs.
Note
A major compaction may degrade business performance. To ensure stable business operations, we recommend that you perform this operation during off-peak hours.
Procedure
For cluster instances of version 4.x, OceanBase Cloud supports initiating major compactions at the cluster level and the tenant level. You can initiate a major compaction for all target tenants under a cluster on the cluster dashboard, or for the current tenant on the tenant dashboard.
Prerequisites
Before initiating a major compaction, ensure that the status of all tenants in the cluster is "Running". A major compaction can only be initiated when the tenant status is "Running".
Initiate a cluster-level major compaction
Log in to the OceanBase Cloud console.
In the left-side navigation pane, click Instances.
In the instance list, find the target cluster instance and click its name to go to the cluster instance dashboard.
On the cluster instance dashboard page, click Actions and select Initiate Major Compaction.
Note
- For cluster instances of version 4.x, OceanBase Cloud supports initiating major compactions at the cluster level and the tenant level.
- You can initiate a major compaction for all target tenants under a cluster on the cluster dashboard, or for the current tenant on the tenant dashboard.
In the dialog box that appears, click Compact Data again to initiate the major compaction for the target instance.
Note
- If there are any ongoing backup tasks, data compaction will cause delays.
- Data compaction may impact database performance. It is recommended to perform this operation during off-peak hours.
- This operation will perform data compaction simultaneously for all tenants under this cluster instance.
After initiating a major compaction, if you have temporary business needs, you can pause or resume the compaction task on the tenant console.
Initiate tenant data compaction
Log in to the OceanBase Cloud console.
In the left-side navigation pane, click Instances.
In the instance list, find the target cluster instance and click its name to go to the cluster instance console.
In the left-side navigation pane, click Tenants.
In the tenant list, find the target tenant and click its name to go to the tenant console.
On the tenant console page, click Actions and select Initiate Major Compaction.
In the dialog box that appears, click Compact Data again to initiate the major compaction for the target tenant.
After initiating a major compaction, if you have temporary business needs, you can pause or resume the compaction task.
Pause compaction: After initiating a major compaction, click Suspend and confirm the pause in the dialog box to stop the compaction task.
Resume compaction: After pausing a compaction, click Resume and confirm the resume in the dialog box to restart the compaction task.