Purpose
You can use this statement in the sys tenant to initiate a compaction in the storage layer. You can initiate a major compaction at the tenant or partition level. You can initiate a minor compaction at the tenant, zone, OBServer node, log stream, or partition level.
Syntax
ALTER SYSTEM merge_action;
merge_action:
MAJOR FREEZE [tenant_list]
| MAJOR FREEZE tenant_list TABLET_ID = tablet_id
| MINOR FREEZE [tenant_list | TABLET_ID = tablet_id] [server_list] [zone_list] [LS [=] ls_id];
| {SUSPEND | RESUME} MERGE [tenant_list]
| CLEAR MERGE ERROR [tenant_list]
tenant_list:
TENANT [=] { all | all_user | all_meta } | tenant_name [, tenant_name ...]
server_list:
SERVER [=] ('ip:port' [, 'ip:port'...])
zone_list:
ZONE [=] ('zone_name' [, 'zone_name' ...]);
Parameters
| Parameter | Description |
|---|---|
| MAJOR FREEZE | Initiates a major compaction. You can use TENANT=all or TENANT=all_user to initiate a major compaction for all user tenants. We recommend that you use all_user, because all will be deprecated in future versions. You can use TENANT=all_meta to initiate a major compaction for all meta tenants. You can also use TENANT=tenant_name [, tenant_name ...] to initiate a major compaction only for specified tenants. |
| MINOR FREEZE | Initiates a minor compaction. |
| {SUSPEND | RESUME} MERGE | Suspends or resumes a major compaction. You can use TENANT=all or TENANT=all_user to suspend or resume a major compaction for all user tenants. We recommend that you use all_user, because all will be deprecated in future versions. You can use TENANT=all_meta to suspend or resume a major compaction for all meta tenants. You can also use TENANT=tenant_name [, tenant_name ...] to suspend or resume a major compaction only for specified tenants. |
| CLEAR MERGE ERROR | Removes major compaction error tags. You can use TENANT=all or TENANT=all_user to remove major compaction error tags for all user tenants. We recommend that you use all_user, because all will be deprecated in future versions. You can use TENANT=all_meta to remove major compaction error tags for all meta tenants. You can also use TENANT=tenant_name [, tenant_name ...] to remove major compaction error tags only for specified tenants. |
| MAJOR FREEZE TENANT [=] tenant_name TABLET_ID = tablet_id | Initiates a partition-level major compaction for a specified tablet ID.
NoteYou can execute this statement only in the |
| tenant_name | The name of the tenant for which a major or minor compaction is to be initiated. |
| TABLET_ID | The ID of the partition for which a major or minor compaction is to be initiated. |
| SERVER | The OBServer node for which a minor compaction is to be initiated. |
| ZONE | The zone for which a minor compaction is to be initiated. |
| LS | The log stream for which a minor compaction is to be initiated. |
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.
Examples
Major compaction in the storage layer
Initiate a major compaction in the
systenant for the tenant itself.obclient> ALTER SYSTEM MAJOR FREEZE; Query OK, 0 rows affectedInitiate a major compaction in the
systenant for all user tenants.obclient> ALTER SYSTEM MAJOR FREEZE TENANT = all_user; Query OK, 0 rows affectedInitiate a major compaction in the
systenant for all meta tenants.obclient> ALTER SYSTEM MAJOR FREEZE TENANT = all_meta; Query OK, 0 rows affectedInitiate a major compaction in the
systenant fortenant1andtenant2.obclient> ALTER SYSTEM MAJOR FREEZE TENANT = tenant1,tenant2; Query OK, 0 rows affected
Minor compaction in the storage layer
Initiate a minor compaction in the
systenant for the tenant itself.obclient> ALTER SYSTEM MINOR FREEZE; Query OK, 0 rows affectedInitiate a minor compaction in the
systenant for all user tenants.obclient> ALTER SYSTEM MINOR FREEZE TENANT = all_user; Query OK, 0 rows affectedInitiate a minor compaction in the
systenant for all meta tenants.obclient> ALTER SYSTEM MINOR FREEZE TENANT = all_meta; Query OK, 0 rows affectedInitiate a minor compaction in the
systenant fortenant1andtenant2.obclient> ALTER SYSTEM MINOR FREEZE TENANT = tenant1,tenant2; Query OK, 0 rows affectedInitiate a minor compaction in the
systenant for a specified partition oftenant1.obclient> ALTER SYSTEM MINOR FREEZE tenant = tenant1 tablet_id = 1100611139453887; Query OK, 0 rows affectedInitiate a minor compaction in the
systenant for a specified OBServer node.obclient> ALTER SYSTEM MINOR FREEZE SERVER = ('10.XXX.XXX.XXX:2882'); Query OK, 0 rows affectedInitiate a minor compaction in the
systenant for a specified log stream in a specified tenant.obclient> ALTER SYSTEM MINOR FREEZE tenant = t1 LS 1; Query OK, 0 rows affectedInitiate a minor compaction in the
systenant for a specified log stream and partition in a specified tenant.obclient> ALTER SYSTEM MINOR FREEZE tenant = t1 ls 1 tablet_id = 60000; Query OK, 0 rows affected
Suspend or resume a major compaction
Suspend a major compaction in the
systenant for all user tenants.obclient> ALTER SYSTEM SUSPEND MERGE TENANT = all_user; Query OK, 0 rows affectedSuspend a major compaction in the
systenant fortenant1andtenant2.obclient> ALTER SYSTEM SUSPEND MERGE TENANT = tenant1,tenant2; Query OK, 0 rows affectedSuspend a major compaction in the
systenant for all meta tenants.obclient> ALTER SYSTEM SUSPEND MERGE TENANT = all_meta; Query OK, 0 rows affectedResume a major compaction in the
systenant for all user tenants.obclient> ALTER SYSTEM RESUME MERGE TENANT = all_user; Query OK, 0 rows affectedResume a major compaction in the
systenant fortenant1andtenant2.obclient> ALTER SYSTEM RESUME MERGE TENANT = tenant1,tenant2; Query OK, 0 rows affectedResume a major compaction in the
systenant for all meta tenants.obclient> ALTER SYSTEM RESUME MERGE TENANT = all_meta; Query OK, 0 rows affected
Remove major compaction error tags
Remove major compaction error tags in the
systenant for all user tenants.obclient> ALTER SYSTEM CLEAR MERGE ERROR TENANT = all_user; Query OK, 0 rows affectedRemove major compaction error tags in the
systenant fortenant1andtenant2.obclient> ALTER SYSTEM CLEAR MERGE ERROR TENANT = tenant1,tenant2; Query OK, 0 rows affectedRemove major compaction error tags in the
systenant for all meta tenants.obclient> ALTER SYSTEM CLEAR MERGE ERROR TENANT = all_meta; Query OK, 0 rows affected
Initiate a partition-level major compaction
Query the tablet IDs of a table.
Here is an example:
SELECT t1.tenant_id, t2.tenant_name, t1.database_name, t1.table_id, t1.table_name, t1.tablet_id, t1.PARTITION_NAME, t1.SUBPARTITION_NAME FROM oceanbase.CDB_OB_TABLE_LOCATIONS t1, oceanbase.DBA_OB_TENANTS t2 WHERE t1.tenant_id=t2.tenant_id AND t1.table_name = 'test_tbl1' AND t2.tenant_name = 'oracle001';The return result is as follows:
+-----------+-------------+---------------+----------+------------+-----------+----------------+-------------------+ | tenant_id | tenant_name | database_name | table_id | table_name | tablet_id | PARTITION_NAME | SUBPARTITION_NAME | +-----------+-------------+---------------+----------+------------+-----------+----------------+-------------------+ | 1004 | oracle001 | SYS | 500011 | TEST_TBL1 | 200008 | P1 | SP0 | | 1004 | oracle001 | SYS | 500011 | TEST_TBL1 | 200009 | P1 | SP1 | | 1004 | oracle001 | SYS | 500011 | TEST_TBL1 | 200010 | P1 | SP2 | | 1004 | oracle001 | SYS | 500011 | TEST_TBL1 | 200011 | P1 | SP3 | | 1004 | oracle001 | SYS | 500011 | TEST_TBL1 | 200012 | P2 | SP4 | | 1004 | oracle001 | SYS | 500011 | TEST_TBL1 | 200013 | P2 | SP5 | | 1004 | oracle001 | SYS | 500011 | TEST_TBL1 | 200014 | P2 | SP6 | | 1004 | oracle001 | SYS | 500011 | TEST_TBL1 | 200015 | P2 | SP7 | +-----------+-------------+---------------+----------+------------+-----------+----------------+-------------------+ 8 rows in setFor more information about columns in the view, see oceanbase.CDB_OB_TABLE_LOCATIONS.
Initiate a major compaction.
Here is an example:
ALTER SYSTEM MAJOR FREEZE TENANT = oracle001 TABLET_ID = 200008;The return result is as follows:
Query OK, 0 rows affected
Initiate a partition-level minor compaction
Query the tablet IDs of a table.
Here is an example:
SELECT t1.tenant_id, t2.tenant_name, t1.database_name, t1.table_id, t1.table_name, t1.tablet_id, t1.PARTITION_NAME, t1.SUBPARTITION_NAME FROM oceanbase.CDB_OB_TABLE_LOCATIONS t1, oceanbase.DBA_OB_TENANTS t2 WHERE t1.tenant_id=t2.tenant_id AND t1.table_name = 'test_tbl1' AND t2.tenant_name = 'oracle001';The return result is as follows:
+-----------+-------------+---------------+----------+------------+-----------+----------------+-------------------+ | tenant_id | tenant_name | database_name | table_id | table_name | tablet_id | PARTITION_NAME | SUBPARTITION_NAME | +-----------+-------------+---------------+----------+------------+-----------+----------------+-------------------+ | 1004 | oracle001 | SYS | 500011 | TEST_TBL1 | 200008 | P1 | SP0 | | 1004 | oracle001 | SYS | 500011 | TEST_TBL1 | 200009 | P1 | SP1 | | 1004 | oracle001 | SYS | 500011 | TEST_TBL1 | 200010 | P1 | SP2 | | 1004 | oracle001 | SYS | 500011 | TEST_TBL1 | 200011 | P1 | SP3 | | 1004 | oracle001 | SYS | 500011 | TEST_TBL1 | 200012 | P2 | SP4 | | 1004 | oracle001 | SYS | 500011 | TEST_TBL1 | 200013 | P2 | SP5 | | 1004 | oracle001 | SYS | 500011 | TEST_TBL1 | 200014 | P2 | SP6 | | 1004 | oracle001 | SYS | 500011 | TEST_TBL1 | 200015 | P2 | SP7 | +-----------+-------------+---------------+----------+------------+-----------+----------------+-------------------+ 8 rows in setFor more information about columns in the view, see oceanbase.CDB_OB_TABLE_LOCATIONS.
Initiate a minor compaction.
Here is an example:
ALTER SYSTEM MINOR FREEZE TENANT = oracle001 TABLET_ID = 200008;The return result is as follows:
Query OK, 0 rows affected