OceanBase logo

OceanBase

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

Product Overview
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

OceanBase

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

Product Overview
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 Database

SQL - V4.4.2

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogWhite PaperLive DemosTraining & CertificationTicket
    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 Database
    3. SQL
    4. V4.4.2
    iconOceanBase Database
    SQL - V 4.4.2
    Databases
    • OceanBase Database
    • OceanBase Cloud
    • OceanBase Tugraph
    • Interactive Tutorials
    • OceanBase Best Practices
    Tools
    • OceanBase Cloud Platform
    • OceanBase Migration Service
    • OceanBase Developer Center
    • OceanBase Migration Assessment
    • OceanBase Admin Tool
    • OceanBase Loader and Dumper
    • OceanBase Deployer
    • Kubernetes operator for OceanBase
    • OceanBase Diagnostic Tool
    • OceanBase Binlog Service
    Connectors and Middleware
    • OceanBase Database Proxy
    • Embedded SQL in C for OceanBase
    • OceanBase Call Interface
    • OceanBase Connector/C
    • OceanBase Connector/J
    • OceanBase Connector/ODBC
    • OceanBase Connector/NET
    SQL
    KV
    • V 4.6.0
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    Modify the number of primary zones for a tenant

    Last Updated:2026-04-02 06:23:56  Updated
    Share
    What is on this page
    Prerequisites
    Add a primary zone
    Remove a primary zone

    folded

    Share

    Scaling out or in a tenant involves increasing or decreasing the tenant's service capabilities, including computing power and storage capacity. This can be achieved by upgrading or downgrading the service capabilities of a single node or by adding or removing nodes to adjust the tenant's overall service capacity. This topic explains how to scale up or down a tenant by modifying the primary zone to add or remove computing nodes.

    Prerequisites

    Before you perform a scale-in or scale-out operation on a tenant, you must perform the following steps:

    • Enable load balancing for the tenant.

      The load balancing strategy for a tenant is jointly controlled by the tenant-level parameters enable_rebalance and enable_transfer.

      You can specify the enable_rebalance parameter in the sys tenant to control whether to enable load balancing among tenants, and specify this parameter in a user tenant to control whether to enable load balancing for the current tenant. The default value is true. The setting takes effect immediately without the need to restart the OBServer node.

      You can specify the enable_transfer parameter to control whether to enable the transfer feature for a tenant. The default value is true. The setting takes effect immediately without the need to restart the OBServer node. The enable_transfer parameter depends on the value of the enable_rebalance parameter.

      • If enable_rebalance is set to false, the system does not perform automatic load balancing regardless of whether the value of enable_transfer is true or false.

      • If both enable_rebalance and enable_transfer are set to true, the system automatically adjusts partition distribution during tenant scaling to achieve load balancing.

      • If enable_rebalance is set to true and enable_transfer is set to false, the system cannot initiate transfer operations during tenant scaling, but can implement limited load balancing through log stream migration.

      You can enable load balancing for a tenant in the following ways:

      • Enable load balancing for a specified tenant from the sys tenant

      • Enable load balancing and the transfer feature for a specified tenant from the sys tenant

        ALTER SYSTEM SET enable_rebalance = true TENANT = 'tenant_name';
        
        ALTER SYSTEM SET enable_transfer = true TENANT = 'tenant_name';
        

        These statements only set the values of the enable_rebalance and enable_transfer parameters to true for the specified user tenant.

      • Enable intra-tenant load balancing and the transfer feature for all user tenants from the sys tenant

        ALTER SYSTEM SET enable_rebalance = true TENANT = all_user;
        
        ALTER SYSTEM SET enable_transfer = true TENANT = all_user;
        

        or

        ALTER SYSTEM SET enable_rebalance = true TENANT = all;
        
        ALTER SYSTEM SET enable_transfer = true TENANT = all;
        

        These statements set the values of the enable_rebalance and enable_transfer parameters to true for all user tenants.

        Note

        Starting from OceanBase Database V4.2.1, TENANT = all_user and TENANT = all express the same semantics. If you want an operation to take effect on all user tenants, we recommend that you use TENANT = all_user. TENANT = all will be deprecated.

      • Enable load balancing for a user tenant from the current tenant

        MySQL-compatible mode
        Oracle-compatible mode

        You can execute the following statements to enable load balancing and the transfer feature for a MySQL-compatible tenant:

        ALTER SYSTEM SET enable_rebalance = true;
        
        ALTER SYSTEM SET enable_transfer = true;
        

        You can execute the following statements to enable load balancing and the transfer feature for an Oracle-compatible tenant:

        ALTER SYSTEM SET enable_rebalance = 'true';
        
        ALTER SYSTEM SET enable_transfer = 'true';
        

      For more information about the enable_rebalance and enable_transfer parameters, see enable_rebalance and enable_transfer, respectively.

    • Before you perform a scale-in or scale-out operation on a tenant, we recommend that you plan resources for the tenant to achieve better results.

      For more information, see Resource planning for tenant scaling in and scaling out.

    Add a primary zone

    1. Log in to the sys tenant of the cluster as the root user.

      obclient -h172.30.xxx.xxx -P2883 -uroot@sys#obdemo -pxxxx -A
      
    2. Access the database named oceanbase.

      use oceanbase;
      
    3. Query the basic information about the mysql001 tenant, such as the TENANT_ID and PRIMARY_ZONE attributes.

      obclient> SELECT TENANT_ID, TENANT_NAME, PRIMARY_ZONE FROM oceanbase.DBA_OB_TENANTS WHERE TENANT_NAME = 'mysql001';
      

      The query result is as follows:

      +-----------+-------------+--------------+
      | TENANT_ID | TENANT_NAME | PRIMARY_ZONE |
      +-----------+-------------+--------------+
      |      1004 | mysql001    | zone1;zone2  |
      +-----------+-------------+--------------+
      1 row in set
      

      As shown in the query result, the TENANT_ID of tenant mysql001 is 1004, and the top priority of PRIMARY_ZONE is zone1.

    4. Query the distribution information of the current log stream leader replica locations for tenant mysql001.

      obclient> SELECT TENANT_ID, LS_ID, SVR_IP, SVR_PORT, ZONE, ROLE, REPLICA_TYPE FROM oceanbase.CDB_OB_LS_LOCATIONS WHERE TENANT_ID = 1004 AND LS_ID != 1 AND ROLE = 'LEADER';
      

      The query result is as follows:

      +-----------+-------+---------------+----------+--------+--------+--------------+
      | TENANT_ID | LS_ID | SVR_IP        | SVR_PORT | ZONE   | ROLE   | REPLICA_TYPE |
      +-----------+-------+---------------+----------+--------+--------+--------------+
      |      1004 |  1001 | 172.xx.xxx.xx |    2882  |  zone1 | LEADER | FULL         |
      |      1004 |  1012 | 172.xx.xxx.xx |    2882  |  zone1 | LEADER | FULL         |
      +-----------+-------+---------------+----------+--------+--------+--------------+
      2 rows in set
      

      As shown in the query result, the mysql001 tenant has two leader replicas that are evenly distributed on the two servers in zone1.

    5. Modify the PRIMARY_ZONE attribute of the mysql001 tenant to change the number of zones with top priority from 1 to 2.

      obclient> ALTER TENANT mysql001 PRIMARY_ZONE='zone1,zone2'; 
      
    6. View the execution status of the job for adding a primary zone.

      obclient> SELECT * FROM oceanbase.DBA_OB_TENANT_JOBS WHERE JOB_TYPE='ALTER_TENANT_PRIMARY_ZONE' AND TENANT_ID = 1004;
      

      The query result is as follows:

      +--------+---------------------------+------------+-------------+----------+----------------------------+----------------------------+-----------+--------------------------------------------------+-------------+----------------+-------------+
      | JOB_ID | JOB_TYPE                  | JOB_STATUS | RESULT_CODE | PROGRESS | START_TIME                 | MODIFY_TIME                | TENANT_ID | SQL_TEXT                                         | EXTRA_INFO  | RS_SVR_IP      | RS_SVR_PORT |
      +--------+---------------------------+------------+-------------+----------+----------------------------+----------------------------+-----------+--------------------------------------------------+-------------+----------------+-------------+
      |      4 | ALTER_TENANT_PRIMARY_ZONE | SUCCESS    |           0 |      100 | 2024-12-18 17:26:00.069089 | 2024-12-18 17:26:20.919021 |      1004 | ALTER TENANT mysql001 PRIMARY_ZONE='zone1,zone2' | zone1;zone2 | 172.xx.xxx.xx  |       2882  |
      +--------+---------------------------+------------+-------------+----------+----------------------------+----------------------------+-----------+--------------------------------------------------+-------------+----------------+-------------+
      1 row in set
      

      In the query result, find the corresponding job record based on the following fields:

      • START_TIME: the time when the job was initiated.
      • SQL_TEXT: the SQL statement corresponding to the job.
      • EXTRA_INFO: the primary zone information before and after the modification.

      If the value of JOB_STATUS is SUCCESS in the corresponding job record, the job for adding the primary zone is successfully executed.

      For more information about the fields in the DBA_OB_TENANT_JOBS view, see DBA_OB_TENANT_JOBS.

    7. Query the basic information of the mysql001 tenant to confirm that the PRIMARY_ZONE attribute is successfully modified and the first priority has changed from zone1 to zone1,zone2.

      obclient> SELECT PRIMARY_ZONE FROM oceanbase.DBA_OB_TENANTS WHERE TENANT_ID = 1004;
      

      The query result is as follows:

      +--------------+
      | PRIMARY_ZONE |
      +--------------+
      | zone1,zone2  |
      +--------------+
      1 row in set
      
    8. Query the distribution information of the mysql001 tenant's log stream leader replica locations again.

      obclient> SELECT TENANT_ID, LS_ID, SVR_IP, SVR_PORT, ZONE, ROLE, REPLICA_TYPE FROM oceanbase.CDB_OB_LS_LOCATIONS WHERE TENANT_ID = 1004 AND LS_ID != 1 AND ROLE = 'LEADER';
      

      The query result is as follows:

      +-----------+-------+---------------+----------+-------+--------+--------------+
      | TENANT_ID | LS_ID | SVR_IP        | SVR_PORT | ZONE  | ROLE   | REPLICA_TYPE |
      +-----------+-------+---------------+----------+-------+--------+--------------+
      |      1004 |  1001 | 172.xx.xxx.xx |    2882  | zone1 | LEADER | FULL         |
      |      1004 |  1012 | 172.xx.xxx.xx |    2882  | zone1 | LEADER | FULL         |
      |      1004 |  1013 | 172.xx.xxx.xx |    2882  | zone2 | LEADER | FULL         |
      |      1004 |  1014 | 172.xx.xxx.xx |    2882  | zone2 | LEADER | FULL         |
      +-----------+-------+---------------+----------+-------+--------+--------------+
      4 rows in set
      

      As shown in the query results, tenant mysql001 has two leader replicas in zone1 and two leader replicas in zone2, meaning a total of four leader replicas provide services.

    The preceding example shows that before the change, the PRIMARY_ZONE of tenant mysql001 had one top-priority zone with two leader replicas providing services. After the change, the number of top-priority zones in PRIMARY_ZONE increased from one to two, and the number of leader replicas providing services grew from two to four. This added computing nodes, enabling the tenant to scale out.

    Remove a primary zone

    1. Log in to the sys tenant of the cluster as the root user.

      obclient -h172.30.xxx.xxx -P2883 -uroot@sys#obdemo -pxxxx -A
      
    2. Access the database named oceanbase.

      use oceanbase;
      
    3. Query the basic information about the mysql001 tenant, such as the TENANT_ID and PRIMARY_ZONE attributes.

      obclient> SELECT TENANT_ID, TENANT_NAME, PRIMARY_ZONE FROM oceanbase.DBA_OB_TENANTS WHERE TENANT_NAME = 'mysql001';
      

      The query result is as follows:

      +-----------+-------------+--------------+
      | TENANT_ID | TENANT_NAME | PRIMARY_ZONE |
      +-----------+-------------+--------------+
      |      1004 | mysql001    | zone1,zone2  |
      +-----------+-------------+--------------+
      1 row in set
      

      As shown in the query result, the TENANT_ID of tenant mysql001 is 1004, and the top priority of PRIMARY_ZONE is zone1 and zone2.

    4. Query the distribution of leader replicas of log streams of the mysql001 tenant.

      obclient> SELECT TENANT_ID, LS_ID, SVR_IP, SVR_PORT, ZONE, ROLE, REPLICA_TYPE FROM oceanbase.CDB_OB_LS_LOCATIONS WHERE TENANT_ID = 1004 AND LS_ID != 1 AND ROLE = 'LEADER';
      

      The query result is as follows:

      +-----------+-------+---------------+----------+-------+--------+--------------+
      | TENANT_ID | LS_ID | SVR_IP        | SVR_PORT | ZONE  | ROLE   | REPLICA_TYPE |
      +-----------+-------+---------------+----------+-------+--------+--------------+
      |      1004 |  1001 | 172.xx.xxx.xx |    2882  | zone1 | LEADER | FULL         |
      |      1004 |  1012 | 172.xx.xxx.xx |    2882  | zone1 | LEADER | FULL         |
      |      1004 |  1013 | 172.xx.xxx.xx |    2882  | zone2 | LEADER | FULL         |
      |      1004 |  1014 | 172.xx.xxx.xx |    2882  | zone2 | LEADER | FULL         |
      +-----------+-------+---------------+----------+-------+--------+--------------+
      4 rows in set
      

      As shown in the query result, the mysql001 tenant has four leader replicas providing services, which are evenly distributed on two servers in zone1 and two servers in zone2.

    5. Modify the PRIMARY_ZONE attribute of the mysql001 tenant to change the number of zones with top priority from 2 to 1.

      obclient> ALTER TENANT mysql001 PRIMARY_ZONE='zone1;zone2'; 
      
    6. View the execution status of the job for reducing primary zones.

      obclient> SELECT * FROM oceanbase.DBA_OB_TENANT_JOBS WHERE JOB_TYPE='ALTER_TENANT_PRIMARY_ZONE' AND TENANT_ID = 1004;
      

      The query result is as follows:

      +--------+---------------------------+------------+-------------+----------+----------------------------+----------------------------+-----------+--------------------------------------------------+---------------+----------------+-------------+
      | JOB_ID | JOB_TYPE                  | JOB_STATUS | RESULT_CODE | PROGRESS | START_TIME                 | MODIFY_TIME                | TENANT_ID | SQL_TEXT                                         | EXTRA_INFO    | RS_SVR_IP      | RS_SVR_PORT |
      +--------+---------------------------+------------+-------------+----------+----------------------------+----------------------------+-----------+--------------------------------------------------+---------------+----------------+-------------+
      |      4 | ALTER_TENANT_PRIMARY_ZONE | SUCCESS    |           0 |      100 | 2024-12-18 17:26:00.069089 | 2024-12-18 17:26:20.919021 |      1004 | ALTER TENANT mysql001 PRIMARY_ZONE='zone1,zone2' | zone1;zone2   |  172.xx.xxx.xx |        2882 |
      |      5 | ALTER_TENANT_PRIMARY_ZONE | SUCCESS    |           0 |      100 | 2024-12-18 17:41:44.412459 | 2024-12-18 17:41:54.965873 |      1004 | ALTER TENANT mysql001 PRIMARY_ZONE='zone1;zone2' | zone1,zone2   |  172.xx.xxx.xx |        2882 |
      +--------+---------------------------+------------+-------------+----------+----------------------------+----------------------------+-----------+--------------------------------------------------+---------------+----------------+-------------+
      2 rows in set
      

      In the query result, find the corresponding job record based on the following fields:

      • START_TIME: the time when the job was initiated.
      • SQL_TEXT: the SQL statement corresponding to the job.
      • EXTRA_INFO: the primary zone information before and after the modification.

      If the value of JOB_STATUS is SUCCESS in the corresponding job record, the job for reducing primary zones is successfully executed.

      For more information about the fields in the DBA_OB_TENANT_JOBS view, see DBA_OB_TENANT_JOBS.

    7. Query the basic information of the mysql001 tenant and confirm that the value of the PRIMARY_ZONE attribute is changed from zone1,zone2 to zone1;zone2.

      obclient> SELECT PRIMARY_ZONE FROM oceanbase.DBA_OB_TENANTS WHERE TENANT_ID = 1004;
      

      The query result is as follows:

      +--------------+
      | PRIMARY_ZONE |
      +--------------+
      |  zone1;zone2 |
      +--------------+
      1 row in set
      
    8. Query the distribution of leader replicas of log streams of the mysql001 tenant again.

      obclient> SELECT TENANT_ID, LS_ID, SVR_IP, SVR_PORT, ZONE, ROLE, REPLICA_TYPE FROM oceanbase.CDB_OB_LS_LOCATIONS WHERE TENANT_ID = 1004 AND LS_ID != 1 AND ROLE = 'LEADER';
      

      The query result is as follows:

      +-----------+-------+---------------+----------+--------+--------+--------------+
      | TENANT_ID | LS_ID | SVR_IP        | SVR_PORT | ZONE   | ROLE   | REPLICA_TYPE |
      +-----------+-------+---------------+----------+--------+--------+--------------+
      |      1004 |  1001 | 172.xx.xxx.xx |    2882  |  zone1 | LEADER | FULL         |
      |      1004 |  1012 | 172.xx.xxx.xx |    2882  |  zone1 | LEADER | FULL         |
      +-----------+-------+---------------+----------+--------+--------+--------------+
      2 rows in set
      

      As shown in the query result, the mysql001 tenant has two leader replicas providing services on servers in zone1.

    The preceding example shows that before the change, the PRIMARY_ZONE of tenant mysql001 had two top-priority zones with four leader replicas providing services. After the change, the number of top-priority zones in PRIMARY_ZONE decreased from two to one, and the number of leader replicas providing services was reduced from four to two. This reduced the number of computing nodes, thereby achieving tenant scaling in.

    Previous topic

    Adjust the unit number for tenant scaling in and out
    Last

    Next topic

    Example of smooth scaling in and out
    Next
    What is on this page
    Prerequisites
    Add a primary zone
    Remove a primary zone