You can manually initiate a major compaction. Manual major compactions include tenant-level and partition-level major compactions.
Adaptive major compactions are partition-level major compactions that are adaptively initiated by the system for partitions as needed. Like adaptive major compactions, partition-level major compactions are mainly used for data import and export, frequent DML operations, and scenarios with low query efficiency. For more information about adaptive major compactions, see Adaptive major compactions. If queries become slow after you disable adaptive major compactions based on your business needs, you can manually initiate partition-level major compactions to solve the problem.
Considerations
One partition corresponds to one tablet. When you initiate a partition-level major compaction, take note of the following considerations:
You cannot initiate a partition-level major compaction for a partition that is undergoing a tenant-level major compaction.
You cannot initiate a partition-level major compaction for a partition that is undergoing an adaptively scheduled major compaction.
You cannot initiate a partition-level major compaction for a partition if multiple replicas of the partition are inconsistent.
You cannot initiate a partition-level major compaction for a partition in the restoring or transfer state.
You cannot initiate a partition-level major compaction when the major compaction task is suspended.
A partition-level major compaction is essentially a major compaction on multiple replicas of a partition. It consumes CPU and disk I/O resources. Before you initiate a partition-level major compaction, check the resource usage of the tenant. After the partition-level major compaction is completed, the CPU and I/O usage will increase.
Prerequisites
Before a major compaction is triggered, make sure that global major compaction is enabled. Global major compaction is controlled by the cluster-level parameter enable_major_freeze. The default value is True, which specifies to enable global major compaction.
If global major compaction is disabled for the current cluster, perform the following steps to enable this feature:
Log on to the
systenant of the cluster as therootuser.Verify that global major compaction is enabled.
obclient> SHOW PARAMETERS LIKE 'enable_major_freeze';If global major compaction is not enabled, execute the following statement to enable the feature.
obclient> ALTER SYSTEM SET enable_major_freeze='True';For more information about the
enable_major_freezeparameter, see enable_major_freeze.
Manually initiate a major compaction from the sys tenant
You can initiate a major compaction for the current tenant, all tenants, or specified tenants from the sys tenant.
To do so, perform the following steps:
Log on to the
systenant of the cluster as therootuser.Initiate a major compaction.
Initiate a tenant-level major compaction
The SQL syntax is as follows:
ALTER SYSTEM MAJOR FREEZE TENANT [=] all_user | all | all_meta | tenant_name [, tenant_name ...];Here,
[=]indicates that the equal sign (=) is optional.Here are some examples:
Initiate a major compaction for the
systenantobclient> ALTER SYSTEM MAJOR FREEZE TENANT;Initiate a major compaction for all user tenants from the
systenantobclient> ALTER SYSTEM MAJOR FREEZE TENANT = all_user;or
obclient> ALTER SYSTEM MAJOR FREEZE TENANT = all;Note
In OceanBase Database V4.2.1 and later,
TENANT = all_userandTENANT = allexpress the same semantics. If you want an operation to take effect on all user tenants, we recommend that you useTENANT = all_user.TENANT = allwill be deprecated.Initiate a major compaction for all meta tenants from the
systenantobclient> ALTER SYSTEM MAJOR FREEZE TENANT = all_meta;Initiate a major compaction for specified tenants from the
systenantobclient> ALTER SYSTEM MAJOR FREEZE TENANT = tenant1,tenant2;
Initiate a partition-level major compaction
The syntax for initiating a partition-level major compaction for a specified tenant is as follows:
ALTER SYSTEM MAJOR FREEZE TENANT [=] tenant_name TABLET_ID = tablet_id;In the syntax,
tablet_idcan be queried from theCDB_OB_TABLE_LOCATIONSview. For more information about columns in theCDB_OB_TABLE_LOCATIONSview, see oceanbase.CDB_OB_TABLE_LOCATIONS.The following example shows how to initiate a partition-level major compaction for
tenant1in thesystenant:obclient> ALTER SYSTEM MAJOR FREEZE TENANT = tenant1 TABLET_ID = 200001;Notice
The statement for initiating a partition-level major compaction is exclusive with that for initiating a tenant-level or adaptive major compaction. Successful execution of the statement does not mean that the partition-level major compaction is successfully initiated. You can check whether a partition-level major compaction is successfully initiated by querying the
GV$OB_MERGE_INFOview for compaction information corresponding toACTION='MEDIUM_MERGE'of the specified partition, or querying theGV$OB_TABLET_COMPACTION_HISTORYview for compaction information corresponding toTYPE='MEDIUM_MERGE'of the specified partition. For more information, see View the major compaction process.
Manually initiate a major compaction from a user tenant
If you are logged on to a user tenant, you can initiate only tenant-level and partition-level major compactions for the current tenant.
Log on to the database as an administrator of a user tenant.
Initiate a major compaction for the current tenant.
Initiate a tenant-level major compaction
obclient> ALTER SYSTEM MAJOR FREEZE;Initiate a partition-level major compaction
The SQL syntax is as follows:
ALTER SYSTEM MAJOR FREEZE TABLET_ID = tablet_id;In the syntax,
tablet_idcan be queried from theDBA_OB_TABLE_LOCATIONSview. For more information about columns in theDBA_OB_TABLE_LOCATIONSview, see DBA_OB_TABLE_LOCATIONS.Here is an example:
obclient> ALTER SYSTEM MAJOR FREEZE TABLET_ID = 200001;Notice
The statement for initiating a partition-level major compaction is exclusive with that for initiating a tenant-level or adaptive major compaction. Successful execution of the statement does not mean that the partition-level major compaction is successfully initiated. You can check whether a partition-level major compaction is successfully initiated by querying the
GV$OB_TABLET_COMPACTION_HISTORYview for compaction information corresponding toTYPE='MEDIUM_MERGE'of the specified partition. For more information, see View the major compaction process.