Purpose
You can use this statement to transfer a partition to the specified log stream.
Required privileges
You must have the ALTER SYSTEM privilege to execute the ALTER SYSTEM TRANSFER PARTITION statement. For more information about privileges in OceanBase Database, see Privilege types in MySQL mode and Privilege types in Oracle mode.
Syntax
ALTER SYSTEM TRANSFER PARTITION TABLE_ID [=] $table_id, OBJECT_ID [=] $object_id TO LS $ls_id [tenant = '$tenant_name']
Limitations and considerations
You can perform the TRANSFER PARTITION operation only in the primary tenant to transfer only a partition of a user tenant.
After you set the
enable_transferparameter tofalseto disable the transfer feature for a tenant, an error will be returned if you execute theTRANSFER PARTITIONstatement for this tenant, and a partition transfer task initiated by a successfully executedTRANSFER PARTITIONstatement may be canceled.You cannot perform partition transfer for a system table.
You cannot perform partition transfer for a user table in the sys tenant.
You cannot transfer a normal table to a broadcast log stream or transfer a replicated table to a normal log stream.
You cannot transfer a non-independent partition, such as a partition of a local index table or large object (LOB) table.
If a transfer operation is in progress for a partition, you cannot initiate another transfer operation for this partition before the current transfer operation is completed.
If a load balancing job (BALANCE_JOB) is in progress in the current cluster, a manually initiated partition transfer task will not be immediately scheduled.
Parameters
| Parameter | Description |
|---|---|
| $table_id | The ID of the partitioned table to which the partition to be transferred belongs. |
| $object_id | The unique ID of the partition to be transferred. The value can be an integer. |
| $ls_id | The ID of the destination log stream to which the partition is to be transferred. |
| $tenant_name | The name of the tenant. This parameter is required when you execute this statement in the sys tenant. |
Examples
Log on to the
systenant of the cluster as therootuser.Note that you must specify the corresponding parameters in the following sample code based on your actual database configurations.
obclient -h10.xx.xx.xx -P2883 -uroot@sys#obdemo -p***** -AQuery the
DBA_OB_TENANTSview for the ID of the target tenant.obclient [oceanbase]> SELECT TENANT_ID FROM oceanbase.DBA_OB_TENANTS WHERE TENANT_NAME = 'oracle_tenant';The query result is as follows:
+-----------+ | TENANT_ID | +-----------+ | 1006 | +-----------+ 1 row in setConfirm the partition information.
You can query the
CDB_OB_TABLE_LOCATIONSview forTABLET_ID,OBJECT_ID, andLS_IDvalues of the specified partition.Query
TABLET_ID,OBJECT_ID, andLS_IDvalues of a non-partitioned tableAssume that non-partitioned table
T1exists in theoracle_tenanttenant. A sample query is as follows:obclient [oceanbase]> SELECT TABLE_ID AS TABLE_ID, OBJECT_ID, TABLET_ID, LS_ID FROM oceanbase.CDB_OB_TABLE_LOCATIONS WHERE TENANT_ID = 1006 AND DATABASE_NAME = 'SYS' AND TABLE_NAME= 'T1' LIMIT 1;The query result is as follows:
+----------+-----------+-----------+-------+ | TABLE_ID | OBJECT_ID | TABLET_ID | LS_ID | +----------+-----------+-----------+-------+ | 500002 | 500002 | 200001 | 1001 | +----------+-----------+-----------+-------+ 1 row in setQuery
TABLET_ID,OBJECT_ID, andLS_IDvalues of a partitioned tableYou need to specify only the partition name for the query.
Assume that partitioned table
TBL1_LOG_Rexists in theoracle_tenanttenant. A sample query is as follows:obclient [SYS]> CREATE TABLE tbl1_log_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) );The following sample code queries related information about the
M202005partition in the partitioned table.obclient [oceanbase]> SELECT TABLE_ID AS TABLE_ID, OBJECT_ID, TABLET_ID, LS_ID FROM oceanbase.CDB_OB_TABLE_LOCATIONS WHERE TENANT_ID = 1006 AND DATABASE_NAME = 'SYS' AND TABLE_NAME= 'TBL1_LOG_R' AND PARTITION_NAME = 'M202005' LIMIT 1;The query result is as follows:
+----------+-----------+-----------+-------+ | TABLE_ID | OBJECT_ID | TABLET_ID | LS_ID | +----------+-----------+-----------+-------+ | 500003 | 500009 | 200006 | 1002 | +----------+-----------+-----------+-------+ 1 row in setQuery
TABLET_ID,OBJECT_ID, andLS_IDvalues of a subpartitioned tableYou need to specify both the partition and subpartition names for the query.
Assume that subpartitioned table
T2_F_RLexists in theoracle_tenanttenant. A sample query is as follows:obclient [SYS]> 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') ) );The following sample code queries related information about the
SP2subpartition in the subpartitioned table.obclient [oceanbase]> SELECT TABLE_ID AS TABLE_ID, OBJECT_ID, TABLET_ID, LS_ID FROM oceanbase.CDB_OB_TABLE_LOCATIONS WHERE TENANT_ID = 1006 AND DATABASE_NAME = 'SYS' AND TABLE_NAME= 'T2_F_RL' AND PARTITION_NAME = 'P1' AND SUBPARTITION_NAME = 'SP2' LIMIT 1;The query result is as follows:
+----------+-----------+-----------+-------+ | TABLE_ID | OBJECT_ID | TABLET_ID | LS_ID | +----------+-----------+-----------+-------+ | 500018 | 500023 | 200017 | 1003 | +----------+-----------+-----------+-------+ 1 row in set
Select the transfer destination.
Query the
CDB_OB_LSview for the log stream status and information of the tenant.obclient [oceanbase]> SELECT * FROM oceanbase.CDB_OB_LS WHERE TENANT_ID = 1006;The query result is as follows:
+-----------+-------+--------+--------------+---------------+-------------+---------------------+----------+---------------------+---------------------+------+ | TENANT_ID | LS_ID | STATUS | PRIMARY_ZONE | UNIT_GROUP_ID | LS_GROUP_ID | CREATE_SCN | DROP_SCN | SYNC_SCN | READABLE_SCN | FLAG | +-----------+-------+--------+--------------+---------------+-------------+---------------------+----------+---------------------+---------------------+------+ | 1006 | 1 | NORMAL | zone1 | 0 | 0 | NULL | NULL | 1701244663685197789 | 1701244663685197789 | | | 1006 | 1001 | NORMAL | zone1 | 1006 | 1001 | 1701239786827662637 | NULL | 1701244663685197789 | 1701244663685197789 | | | 1006 | 1002 | NORMAL | zone1 | 1007 | 1002 | 1701239786831568305 | NULL | 1701244664066906860 | 1701244664066906859 | | | 1006 | 1003 | NORMAL | zone1 | 1008 | 1003 | 1701239786834300282 | NULL | 1701244664175263949 | 1701244664175263948 | | +-----------+-------+--------+--------------+---------------+-------------+---------------------+----------+---------------------+---------------------+------+ 4 rows in setQuery the
CDB_OB_TABLET_TO_LSview for the distribution of tablets on the log streams.obclient [oceanbase]> SELECT LS_ID, COUNT(*) AS C FROM oceanbase.CDB_OB_TABLET_TO_LS WHERE TENANT_ID = 1006 GROUP BY LS_ID;The query result is as follows:
+-------+------+ | LS_ID | C | +-------+------+ | 1 | 578 | | 1001 | 7 | | 1002 | 5 | | 1003 | 7 | +-------+------+ 4 rows in setSelect an appropriate log stream as the transfer destination based on the preceding information.
Execute the following statement to perform partition transfer:
ALTER SYSTEM TRANSFER PARTITION TABLE_ID [=] table_id, OBJECT_ID [=] object_id TO LS ls_id TENANT = 'tenant_name';The parameters are described as follows:
table_id: the ID of the table.object_id: the unique ID of the partition.ls_id: the ID of the log stream to which the partition is to be transferred.tenant_name: the tenant to which the partition to be transferred belongs.
The following sample code transfers the
M202005partition of theTBL1_LOG_Rtable in theSYSdatabase from log stream1002to log stream1003in theoracle_tenanttenant.obclient [oceanbase]> ALTER SYSTEM TRANSFER PARTITION TABLE_ID = 500003, OBJECT_ID = 500009 TO LS 1003 TENANT = 'oracle_tenant';After the statement is executed, query the status of the partition transfer task.
Query the
CDB_OB_TRANSFER_PARTITION_TASKSview for theTASK_ID,TRANSFER_TASK_ID, andBALANCE_JOB_IDvalues of the task.The
CDB_OB_TRANSFER_PARTITION_TASKSview displays the ongoing partition transfer tasks of all tenants. A sample query is as follows:obclient [oceanbase]> SELECT TASK_ID, BALANCE_JOB_ID, TRANSFER_TASK_ID, STATUS FROM oceanbase.CDB_OB_TRANSFER_PARTITION_TASKS WHERE TENANT_ID = 1006 AND TABLE_ID = 500003 AND OBJECT_ID = 500009;A sample query result is as follows:
+---------+----------------+------------------+--------+ | TASK_ID | BALANCE_JOB_ID | TRANSFER_TASK_ID | STATUS | +---------+----------------+------------------+--------+ | 1 | 17304 | 1 | DOING | +---------+----------------+------------------+--------+ 1 row in setThe value of the
STATUSfield indicates the status of the task. Valid values:WAITING: The task is waiting to be scheduled.INIT:BALANCE_JOB_IDhas been generated for the task. You can query the execution progress of the associated load balancing job based onBALANCE_JOB_ID.DOING: The task is in progress. You can view the task based onTRANSFER_TASK_ID, which will change several times. A partition transfer task involves multiple transfers.
If the query on the
CDB_OB_TRANSFER_PARTITION_TASKSview returns an empty result set, you can query theCDB_OB_TRANSFER_PARTITION_TASK_HISTORYview for the task execution result.Query the
CDB_OB_BALANCE_JOBSorCDB_OB_BALANCE_JOB_HISTORYview based on the obtainedBALANCE_JOB_IDvalue to confirm the execution status of the associated load balancing job.The
CDB_OB_BALANCE_JOBSview displays the ongoing load balancing jobs of all tenants. Each tenant can have only one running load balancing job (BALANCE_JOB) at a time. A load balancing job generates multiple transfer tasks (TRANSFER_TASK). TheCDB_OB_BALANCE_JOB_HISTORYview displays the historical load balancing jobs of all tenants. Sample queries are as follows:obclient [oceanbase]> SELECT * FROM oceanbase.CDB_OB_BALANCE_JOBS WHERE JOB_ID = 17304;obclient [oceanbase]> SELECT * FROM oceanbase.CDB_OB_BALANCE_JOB_HISTORY WHERE JOB_ID = 17304;You must replace
17304with theBALANCE_JOB_IDvalue obtained in previous steps.The
STATUScolumn in the query result indicates the execution status of the load balancing job. Valid values:DOING: The load balancing job is in progress.COMPLETED: The load balancing job was successfully executed.CANCELING: The load balancing job is being canceled.CANCELED: The load balancing job has been canceled.
Query the
CDB_OB_TRANSFER_TASKSorCDB_OB_TRANSFER_TASK_HISTORYview based on the obtainedTRANSFER_TASK_IDvalue for the execution status of the transfer task.The
CDB_OB_TRANSFER_TASKSview displays the ongoing transfer tasks of all tenants. Multiple ongoing transfer tasks (TRANSFER_TASK) that belong to the same load balancing job (BALANCE_JOB) can exist concurrently in a tenant. TheCDB_OB_TRANSFER_TASK_HISTORYview displays the historical transfer tasks of all tenants. Sample queries are as follows:obclient [oceanbase]> SELECT * FROM oceanbase.CDB_OB_TRANSFER_TASKS WHERE TASK_ID = 1;obclient [oceanbase]> SELECT * FROM oceanbase.CDB_OB_TRANSFER_TASK_HISTORY WHERE TASK_ID = 1;You must replace
1with theTRANSFER_TASK_IDvalue obtained in previous steps.The
STATUScolumn in the query result indicates the execution status of the transfer task. Valid values:INIT: The task is being created.START: The task starts to be executed.DOING: The task is in progress.ABORTED: The task was aborted.COMPLETED: The task was successfully executed.FAILED: The task failed.CANCELED: The task has been canceled.
Query the
CDB_OB_TRANSFER_PARTITION_TASK_HISTORYview based on the obtainedTASK_IDvalue for the execution result of the partition transfer task.The
CDB_OB_TRANSFER_PARTITION_TASK_HISTORYview displays the historical partition transfer tasks of all tenants.obclient [oceanbase]> SELECT * FROM oceanbase.CDB_OB_TRANSFER_PARTITION_TASK_HISTORY WHERE TASK_ID = 1;You must replace
1with theTASK_IDvalue obtained in previous steps.The
STATUScolumn in the query result indicates the execution result of the partition transfer task. Valid values:COMPLETED: The task was successfully executed.FAILED: The task failed. You can view the cause of the failure in theCOMMENTcolumn.
After successful execution of the partition transfer task, query the information about the partition again.
obclient [oceanbase]> SELECT TABLE_ID AS TABLE_ID, OBJECT_ID, TABLET_ID, LS_ID FROM oceanbase.CDB_OB_TABLE_LOCATIONS WHERE TENANT_ID = 1006 AND DATABASE_NAME = 'SYS' AND TABLE_NAME= 'TBL1_LOG_R' AND PARTITION_NAME = 'M202005' LIMIT 1;The query result is as follows:
+----------+-----------+-----------+-------+ | TABLE_ID | OBJECT_ID | TABLET_ID | LS_ID | +----------+-----------+-----------+-------+ | 500003 | 500009 | 200006 | 1003 | +----------+-----------+-----------+-------+ 1 row in setThe result shows that the
M202005partition of theTBL1_LOG_Rtable in theSYSdatabase has been transferred from log stream1002to log stream1003.