OceanBase logo

OceanBase

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

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

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

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.2.1

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive DemosTraining & Certification
    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.2.1
    iconOceanBase Database
    SQL - V 4.2.1
    SQL
    KV
    • 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

    Try out the multi-tenant feature

    Last Updated:2023-12-25 08:49:40  Updated
    share
    What is on this page
    Background information
    Create unit configs
    Create resource pools and associate them with the unit configs
    Create tenants based on the created resource pools
    Modify tenant configurations and adjust instance resource specifications

    folded

    share

    Each tenant in OceanBase Database is an instance, which is similar to a MySQL instance. Data, privileges, and resources of tenants are isolated. Each tenant has its own access ports and CPU and memory resources.

    Background information

    OceanBase Database allows you to flexibly adjust the CPU and memory resources allocated to a tenant, which is transparent to the upper-layer business system. With the multi-tenant feature, you can efficiently use resources, reduce costs, ensure high availability and performance, and implement on-demand scaling based on your business requirements.

    To help you better understand this feature, the following example describes how to create a tenant.

    Create unit configs

    In OceanBase Database, a resource unit is the minimum logical unit for a tenant to use CPU and memory resources. It is also the basic unit for cluster scaling and load balancing. When a cluster node goes online or offline or a cluster is scaled in or out, the distribution of resource units on the nodes is dynamically adjusted to balance the resource usage. A unit config is a configuration file that specifies the specifications of the computing and storage resources (including memory, CPU, and I/O resources) required for a resource unit.

    Based on the distributed architecture of OceanBase Database, an OceanBase Database tenant can be flexibly defined in different dimensions such as resource specifications, resource pool, replica type, and replica distribution. Therefore, if you want to create a tenant, you must create a unit config, a resource pool, and a tenant in sequence.

    You must determine a unit config before you create an OceanBase Database tenant. You must use the following SQL statement as the administrator of the sys tenant to create a tenant.

    In this example, unit1 and unit2 are created, and their CPU and memory resources, and maximum and minimum thresholds of the resources are specified.

    • unit1 is configured with 3 CPU cores and 6 GB of memory.

      obclient [oceanbase]> CREATE RESOURCE UNIT UNIT1 MAX_CPU =3,MIN_CPU =3 ,MEMORY_SIZE ='6G';
      
    • unit2 is configured with 4 CPU cores and 8 GB of memory.

      obclient [oceanbase]> CREATE RESOURCE UNIT UNIT2 MAX_CPU =4,MIN_CPU =4 ,MEMORY_SIZE ='8G';
      

    Create resource pools and associate them with the unit configs

    A unit config is a set of configuration specifications for a tenant, whereas a resource pool is a set of entity resources for a tenant. Therefore, in this step, you must create resource pools and associate them with the unit configs.

    In this example, pool1 and pool2 are created and associated with unit1 and unit2 respectively. As a result, the resource units are mapped to the resource pools. UNIT_NUM indicates the number of units specified in one zone. In the same tenant, you can allocate at most one unit to each node. ZONE_LIST specifies the zones where the tenant is deployed in the current cluster.

    In this example, the OceanBase cluster contains only one node. Therefore, only one unit and one zone list are specified. Before you create a resource pool, make sure that the available resources are sufficient. If the resources are insufficient, you can delete the existing test tenants or decrease the unit configs of the existing tenants. For more information, see Modify tenant configurations and adjust instance resource specifications below.

    obclient [oceanbase]> CREATE RESOURCE POOL pool1 UNIT='UNIT1',UNIT_NUM=1,ZONE_LIST=('zone1');
    obclient [oceanbase]> CREATE RESOURCE POOL pool2 UNIT='UNIT2',UNIT_NUM=1,ZONE_LIST=('zone1');
    

    Note

    The preceding example applies to a single-node cluster. If your cluster contains three nodes, specify ZONE_LIST in the format of ('zone1','zone2','zone3'), and customize the zone names.

    Create tenants based on the created resource pools

    After the unit configs and resource pools are created and associated, you can create a tenant.

    In this example, the OceanBase cluster contains only one node. Therefore, you can create only a single-replica tenant. If you want to create a three-replica tenant, the OceanBase cluster must contain at least three nodes.

    Define a single-replica tenant named tenant1, set the character set to utf8mb4, and set the resource pool to pool1. ob_tcp_invited_nodes specifies the allowlist for the tenant. You can set the initial value to % to allow access from all IP addresses. You can change the value as required later on.

    obclient [oceanbase]> CREATE TENANT IF NOT EXISTS tenant1 CHARSET='utf8mb4', ZONE_LIST=('zone1'), PRIMARY_ZONE='zone1', RESOURCE_POOL_LIST=('pool1') SET ob_tcp_invited_nodes='%';
    

    Note

    The preceding example applies to a single-node cluster. You can create only single-replica tenants. If your cluster contains three nodes, the value of ZONE_LIST must be in the format of ('zone1','zone2','zone3'), and that of PRIMARY_ZONE must be in the format of 'zone1;zone2;zone3', indicating that the leader replica of the tenant is preferentially located in zone1 and then zone2.

    Likewise, define a single-replica tenant named tenant2, set the character set to utf8mb4, and set the resource pool to pool2.

    obclient [oceanbase]> CREATE TENANT IF NOT EXISTS tenant2 CHARSET='utf8mb4', ZONE_LIST=('zone1'), PRIMARY_ZONE='zone1', RESOURCE_POOL_LIST=('pool2') SET ob_tcp_invited_nodes='%';
    

    After you create tenant1 and tenant2, you can query the oceanbase.DBA_OB_TENANTS view to verify whether the tenants exist in the cluster.

    obclient [oceanbase]> SELECT * FROM DBA_OB_TENANTS;
    

    If the preceding statement succeeds, you have created two tenants in the same cluster. Then, you can perform database operations in the tenants.

    Log on as the root user to the tenant1 tenant of the cluster and create a test table.

    obclient -hxxx.xxx.xxx.xxx -P2883 -uroot@tenant1#ob_test -p******
    
    obclient [(none)]> SHOW DATABASES;
    +--------------------+
    | Database           |
    +--------------------+
    | oceanbase          |
    | information_schema |
    | mysql              |
    | test               |
    +--------------------+
    4 rows in set
    
    obclient [(none)]> USE test;
    Database changed
    obclient [test]> CREATE TABLE t_f1(id DECIMAL(10,0),id2 DECIMAL(10,0),id3 DATE,id4 DATE,id5 FLOAT,id6 FLOAT,id7 VARCHAR(30),id8 VARCHAR(300));
    Query OK, 0 rows affected
    
    obclient [test]> SHOW TABLES;
    +----------------+
    | Tables_in_test |
    +----------------+
    | t_f1           |
    +----------------+
    1 row in set
    

    Log on as the root user to the tenant2 tenant of the cluster and view the test database.

    obclient -hxxx.xxx.xxx.xxx -P2883 -uroot@tenant2#ob_test -p******
    
    obclient [(none)]> SHOW DATABASES;
    +--------------------+
    | Database           |
    +--------------------+
    | oceanbase          |
    | information_schema |
    | mysql              |
    | test               |
    +--------------------+
    4 rows in set
    
    obclient [(none)]> USE test;
    Database changed
    obclient [test]> SHOW TABLES;
    Empty set
    

    The query results show that the resources, data, and permissions of the two tenants in the cluster are isolated. You can perform more tests to try out the tenant isolation feature of OceanBase Database.

    Modify tenant configurations and adjust instance resource specifications

    OceanBase Database allows you to flexibly adjust the CPU and memory resources of tenants in real time, which is transparent to the business system. To modify the CPU and memory resources of a tenant, you only need to adjust the unit config used by the tenant, without modifying the resource pool or tenant.

    You can query the oceanbase.DBA_OB_UNIT_CONFIGS system view for the resource units of a tenant.

    obclient [oceanbase]> SELECT * FROM oceanbase.DBA_OB_UNIT_CONFIGS;
    +----------------+-----------------+----------------------------+----------------------------+---------+---------+-------------+---------------+----------+----------+-------------+
    | UNIT_CONFIG_ID | NAME            | CREATE_TIME                | MODIFY_TIME                | MAX_CPU | MIN_CPU | MEMORY_SIZE | LOG_DISK_SIZE | MAX_IOPS | MIN_IOPS | IOPS_WEIGHT |
    +----------------+-----------------+----------------------------+----------------------------+---------+---------+-------------+---------------+----------+----------+-------------+
    |              1 | sys_unit_config | 2022-11-17 18:00:47.297945 | 2022-11-17 18:00:47.297945 |       1 |       1 |  8053063680 |    8053063680 |    10000 |    10000 |           1 |
    |           1010 | unit1           | 2022-12-15 11:40:17.811095 | 2022-12-15 11:40:17.811095 |       3 |       3 |  6442450944 |    2147483648 |     128  |     128  |           0 |
    |           1011 | unit2           | 2022-12-16 16:16:27.053872 | 2022-12-16 16:16:27.053872 |       4 |       4 |  8589934592 |    8589934592 |     128  |     128  |           0 |
    +----------------+-----------------+----------------------------+----------------------------+---------+---------+-------------+---------------+----------+----------+-------------+
    6 rows in set (0.003 sec)
    

    As shown in the query result, unit1 is configured with 3 CPU cores and 6 GB of memory.

    You can run the following command to adjust the CPU and memory resources of unit1 to 5 CPU cores and 10 GB of memory.

    obclient [oceanbase]>  ALTER resource unit unit1 max_cpu =5,min_cpu =5 ,memory_size ='10G';
    Query OK, 0 rows affected
    
    obclient [oceanbase]> SELECT * FROM oceanbase.DBA_OB_UNIT_CONFIGS;
    +----------------+-----------------+----------------------------+----------------------------+---------+---------+-------------+---------------+----------+----------+-------------+
    | UNIT_CONFIG_ID | NAME            | CREATE_TIME                | MODIFY_TIME                | MAX_CPU | MIN_CPU | MEMORY_SIZE | LOG_DISK_SIZE | MAX_IOPS | MIN_IOPS | IOPS_WEIGHT |
    +----------------+-----------------+----------------------------+----------------------------+---------+---------+-------------+---------------+----------+----------+-------------+
    |              1 | sys_unit_config | 2022-11-17 18:00:47.297945 | 2022-11-17 18:00:47.297945 |       1 |       1 |  8053063680 |    8053063680 |    10000 |    10000 |           1 |
    |           1010 | unit1           | 2022-12-15 11:40:17.811095 | 2023-01-05 16:24:17.287801 |       5 |       5 | 10737418240 |    2147483648 |     128  |     128  |           0 |
    |           1011 | unit2           | 2022-12-16 16:16:27.053872 | 2022-12-16 16:16:27.053872 |       4 |       4 |  8589934592 |    8589934592 |     128  |     128  |           0 |
    +----------------+-----------------+----------------------------+----------------------------+---------+---------+-------------+---------------+----------+----------+-------------+
    6 rows in set (0.037 sec)
    

    As shown in the preceding example, the adjustment of the tenant configurations takes effect immediately. After the adjustment, the CPU and memory resources of unit1 are 5 CPU cores and 10 GB of memory. Based on kernel virtualization, OceanBase Database allows the modifications on CPU and memory resources of a tenant to take effect immediately without data migration or switchover. Therefore, the modifications are transparent to your business system.

    In the DBA_OB_UNITS view, you can obtain information about resource units, resource pools, tenants in the cluster, CPUs, and memory.

    obclient [oceanbase]> SELECT * FROM DBA_OB_UNITS;
    

    Previous topic

    Try out parallel import and data compression
    Last

    Next topic

    Video tutorials
    Next
    What is on this page
    Background information
    Create unit configs
    Create resource pools and associate them with the unit configs
    Create tenants based on the created resource pools
    Modify tenant configurations and adjust instance resource specifications