Multi-tenancy is a core capability that distinguishes OceanBase Database from traditional single-instance databases. OceanBase adopts a single-cluster, multi-tenant architecture, which pools instance resources at the cluster level. Each tenant is an instance (analogous to a MySQL instance). Data, permissions, and resources are completely isolated between tenants. Each tenant has its own user system and dedicated resources such as CPU and memory. Through the multi-tenancy mechanism, a single cluster can host multiple businesses simultaneously, efficiently utilize resources while ensuring availability and performance, and enable on-demand elastic scaling.
This topic covers the following experiences:
- Understand the multi-tenant architecture: Master the basic relationships between unit config, resource pool, unit, and tenant.
- Create different business tenants: Create mutually isolated tenants for different businesses and configure different resource specifications such as CPU, memory, and storage.
- Verify tenant isolation: Execute queries in different tenants to observe the boundaries of data and permissions.
- Adjust resource specifications online: Experience online scaling of tenant resources, which is transparent to the business during the change process.
- Stress test and observe tenant performance: Execute a standard stress test in a business tenant to verify that the tenant can handle business traffic normally and understand the isolation logic of resource quotas.
Note
This topic is based on OceanBase Database V5.0.1 (Community Edition). The commands and feature descriptions in this topic apply to V5.0.1. This topic uses a single-node environment deployed with the All-in-One package in Deploy OceanBase as an example. This topic focuses on resource isolation between tenants, which sets the resource ceiling of each tenant through resource specifications. To experience resource isolation (resource groups) between different workloads within the same tenant, see Experience HTAP mixed-workload scenarios.
Prerequisites
Before you proceed, ensure the following conditions are met:
Project |
Description |
|---|---|
| OceanBase Database | OceanBase Database has been deployed and started successfully. For more information, see Deploy OceanBase Database. |
| Server resources | We recommend that you have at least four CPU cores and 16 GB of memory. The more machine resources you have, the larger the specifications you can allocate to a tenant. |
| Access to the sys tenant | You can log in to the sys tenant of the cluster as the root user to perform management operations. The password for the root user of the sys tenant is randomly generated during deployment and is printed in the deployment output; you can also run obd cluster display demo to view it. |
| obclient | obclient is installed and can connect to OceanBase Database normally. It is installed automatically when you deploy with the All-in-One package. |
| ob-sysbench (optional) | To experience stress testing and observe tenant performance, you must have installed ob-sysbench as described in Experience high-concurrency OLTP scenarios. |
Overview of the multi-tenant architecture
OceanBase Database achieves resource isolation through tenants, ensuring that each instance of a database service is unaware of the existence of others. It also ensures tenant data security through permission control. A tenant is a logical concept that serves as both a container for various database objects and a container for resources (such as CPU, memory, and I/O). To some extent, it is equivalent to the "instance" concept in traditional databases.
OceanBase uses the following three concepts to manage the available resources for each tenant:
Concept |
Description |
|---|---|
| Unit config | Describes the configuration of a resource unit, such as its available CPU, memory, storage space, and IOPS. Modifying the resource configuration allows you to dynamically adjust the specifications of a resource unit. |
| Resource unit | A unit is the smallest logical unit for a tenant's use of CPU and memory, and it is also the basic unit for cluster scaling and load balancing. A unit must be placed on a physical server that has sufficient resources to host it, and at most one unit from the same resource pool can be placed on a single physical server. |
| Resource pool | A resource pool consists of multiple resource units. By specifying resource configurations for a resource pool, you can determine the physical resources for each resource unit within the pool. A resource pool belongs to only one tenant, and a tenant can have one or more resource pools. |
Due to its distributed architecture, an OceanBase tenant can be flexibly defined across dimensions such as resource specifications, resource pools, replica types, and replica distribution. Therefore, when creating a tenant, you must follow the sequence of resource configuration → resource pool → tenant:
Unit config ─────────────> Resource pool ─────────────> Tenant
Define the specifications Combine resource units Allocate to businesses
Note
Resource configuration specifies the service capability that the corresponding resource unit can provide, not its real-time load. For more information, see Tenant resource management.
Create tenants for different businesses
The following example simulates a scenario where a cluster hosts two businesses simultaneously: create a smaller-specification tenant tenant1 for Business A and a larger-specification tenant tenant2 for Business B. Both share cluster resources but are isolated from each other.
Procedure
Log in to the sys tenant of the cluster as the root user (the password is randomly generated during deployment; see the prerequisites above for retrieval):
obclient -h127.0.0.1 -uroot@sys -P2881 -p -A oceanbaseCreate two resource configurations with unit specifications of 1C2G and 2C4G, respectively. Adjust them based on your actual machine configuration:
obclient [oceanbase]> CREATE RESOURCE UNIT unit1 MAX_CPU=1, MIN_CPU=1, MEMORY_SIZE='2G'; obclient [oceanbase]> CREATE RESOURCE UNIT unit2 MAX_CPU=2, MIN_CPU=2, MEMORY_SIZE='4G';Key parameters:
ParameterDescriptionMAX_CPUThe upper limit of CPU that the resource unit can provide. Required. MIN_CPUThe lower limit of CPU that the resource unit can provide. Default equals MAX_CPU.MEMORY_SIZEThe memory specification that the resource unit can provide. Required. LOG_DISK_SIZELog disk space. Defaults to 3 times the memory size, with a minimum of 2 GB. MAX_IOPS/MIN_IOPSThe upper and lower limits of IOPS that the resource unit can provide. The minimum value is 1024 for both. If not specified, the default is INT64_MAX.Create a resource pool and associate it with the resource configuration. For a single-node cluster, the
ZONE_LISTis('zone1'):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');Key parameters:
ParameterDescriptionUNITSpecifies the resource configuration for the resource pool. Each resource unit in the pool uses this specification. UNIT_NUMThe number of resource units created by the resource pool on each zone in ZONE_LIST.ZONE_LISTThe scope of use for the resource pool, specifying on which zones to create resource units. Create tenants
tenant1andtenant2respectively, and associate them with the corresponding resource pools:obclient [oceanbase]> CREATE TENANT IF NOT EXISTS tenant1 CHARSET='utf8mb4', PRIMARY_ZONE='zone1', RESOURCE_POOL_LIST=('pool1') SET ob_tcp_invited_nodes='%'; obclient [oceanbase]> CREATE TENANT IF NOT EXISTS tenant2 CHARSET='utf8mb4', PRIMARY_ZONE='zone1', RESOURCE_POOL_LIST=('pool2') SET ob_tcp_invited_nodes='%';Key parameters:
ParameterDescriptionCHARSETThe character set for the tenant. In this example, it is set to utf8mb4.PRIMARY_ZONEThe zone where leader replicas are preferentially distributed. RESOURCE_POOL_LISTThe list of resource pools associated with the tenant. ob_tcp_invited_nodesThe access allowlist for the tenant. '%'indicates any IP can access. This can be modified later.Confirm that the tenants are created successfully:
obclient [oceanbase]> SELECT TENANT_ID, TENANT_NAME, TENANT_TYPE, STATUS, TENANT_ROLE FROM DBA_OB_TENANTS WHERE TENANT_TYPE = 'USER';A sample return result is as follows. The
STATUSfor bothtenant1andtenant2isNORMAL, indicating successful creation:+-----------+-------------+-------------+--------+-------------+ | TENANT_ID | TENANT_NAME | TENANT_TYPE | STATUS | TENANT_ROLE | +-----------+-------------+-------------+--------+-------------+ | 1 | sys | SYS | NORMAL | PRIMARY | | 1002 | tenant1 | USER | NORMAL | PRIMARY | | 1004 | tenant2 | USER | NORMAL | PRIMARY | +-----------+-------------+-------------+--------+-------------+ 3 rows in setThe
TENANT_IDand other numbers are automatically assigned by the system and may vary by environment. When a user tenant is created, the system also automatically creates an internal tenant starting withMETA$(TENANT_TYPEisMETA), used to manage tenant metadata. You can query full information usingSELECT * FROM DBA_OB_TENANTS;, but you do not need to focus on this.Log in to
tenant1as the root user. The default password for the newly created tenant root user is empty. When prompted to enter a password, just press Enter:obclient -h127.0.0.1 -uroot@tenant1 -P2881 -p -A testAfter logging in, execute
SHOW DATABASES;to see that the new tenant has its own independent database list:+--------------------+ | Database | +--------------------+ | information_schema | | mysql | | oceanbase | | test | +--------------------+ 4 rows in setSimilar to the
systenant,tenant1also contains three system databases:information_schema,mysql, andoceanbase, which store database system information and metadata. Do not store business data in these databases.
Notice
- When creating a resource pool, ensure there are sufficient resources available. If resources are insufficient, you can reduce the resource specifications of existing tenants (see Online adjustment of tenant resource specifications), or delete unused tenants to free up resources. Delete tenants using the
DROP TENANTstatement, and the databases and tables under the tenant will be deleted simultaneously. For details, see DROP TENANT. - The system reserves resources for the Meta tenant by default when creating a tenant. These resources are deducted from the user tenant's resources. Therefore, the actual available resources for a tenant are slightly less than the configured value. It is normal for the actual effective quota queried through views to be lower than the
MEMORY_SIZEconfiguration value. - The examples in this topic are for a single-node cluster, which can only create single-replica tenants. If your cluster has three nodes, the value of
ZONE_LISTshould be('zone1','zone2','zone3'), andPRIMARY_ZONEcan be set to'zone1;zone2;zone3'.
Experience tenant isolation
In a multi-tenant architecture, data and permissions are completely isolated between tenants: OceanBase does not allow cross-tenant data access, and each tenant has its own independent user system. This section verifies isolation through two sets of operations.
Data isolation
Create a test table in
tenant1and insert data:obclient -h127.0.0.1 -uroot@tenant1 -P2881 -p -A testobclient [test]> CREATE TABLE business_a_order (id INT PRIMARY KEY, item VARCHAR(50), amount DECIMAL(10,2)); Query OK, 0 rows affected obclient [test]> INSERT INTO business_a_order VALUES (1, 'keyboard', 149.00); Query OK, 1 row affected obclient [test]> SHOW TABLES; +------------------+ | Tables_in_test | +------------------+ | business_a_order | +------------------+ 1 row in setLog in to
tenant2as the root user and check the tables in thetestdatabase:obclient -h127.0.0.1 -uroot@tenant2 -P2881 -p -A testobclient [test]> SHOW TABLES; Empty setNo tables created in
tenant1are visible intenant2. The two tenants have their own independenttestdatabases, with data being completely isolated.
Permission isolation
Each tenant has its own independent user system. Users created in one tenant cannot log in to another tenant.
Create a business user in
tenant1:obclient [test]> CREATE USER app_user IDENTIFIED BY '******'; Query OK, 0 rows affectedTry to connect to
tenant2usingapp_user(enter the password forapp_userwhen prompted):obclient -h127.0.0.1 -uapp_user@tenant2 -P2881 -p -A test Enter password: ERROR 1045 (42000): Access denied for user 'app_user'@'xxx.xxx.xxx.xxx' (using password: NO)The connection fails with the error
ERROR 1045 Access deniedbecauseapp_useronly exists in the user system oftenant1, andtenant2cannot recognize this user. Theusing password: NOat the end of the error indicates that this user does not exist intenant2, not that you did not enter a password. Similarly, the root user oftenant1and the root user oftenant2are also two completely independent accounts.
Note
In terms of data security, OceanBase Database does not allow cross-tenant data access to ensure that users' data assets are not at risk of being stolen by other tenants. In terms of resource usage, OceanBase behaves as if each tenant "exclusively" holds its resource quota. For more information, see Overview of Multi-Tenancy Architecture.
Online adjustment of tenant resource specifications
OceanBase Database allows you to flexibly adjust the CPU and memory resources of a tenant, and the adjustments take effect online and are transparent to the business. To change the CPU and memory allocated to a tenant, you only need to modify the resource configuration that the tenant uses; the resource pool and the tenant itself do not need to be changed.
Procedure
View the current resource configuration in the sys tenant:
obclient [oceanbase]> SELECT UNIT_CONFIG_ID, NAME, MAX_CPU, MIN_CPU, MEMORY_SIZE, LOG_DISK_SIZE FROM oceanbase.DBA_OB_UNIT_CONFIGS WHERE NAME IN ('unit1', 'unit2');An example of the return result is as follows:
+----------------+-------+---------+---------+-------------+---------------+ | UNIT_CONFIG_ID | NAME | MAX_CPU | MIN_CPU | MEMORY_SIZE | LOG_DISK_SIZE | +----------------+-------+---------+---------+-------------+---------------+ | 1006 | unit1 | 1 | 1 | 2147483648 | 6442450944 | | 1007 | unit2 | 2 | 2 | 4294967296 | 12884901888 | +----------------+-------+---------+---------+-------------+---------------+ 2 rows in setThe result shows that the
unit1resource unit provides 1C of CPU and 2G of memory, and that its log disk space is 6G (by default, three times the memory size).UNIT_CONFIG_IDis assigned automatically by the system and varies by environment.MEMORY_SIZEandLOG_DISK_SIZEare expressed in bytes, and 1G equals 1073741824 bytes.Adjust the specification of
unit1to 2C4G online to simulate a resource expansion for Business A:obclient [oceanbase]> ALTER RESOURCE UNIT unit1 MAX_CPU=2, MIN_CPU=2, MEMORY_SIZE='4G'; Query OK, 0 rows affectedQuery the resource configuration again to confirm the adjustment has taken effect (repeat the query statement from step 1):
obclient [oceanbase]> SELECT UNIT_CONFIG_ID, NAME, MAX_CPU, MIN_CPU, MEMORY_SIZE, LOG_DISK_SIZE FROM oceanbase.DBA_OB_UNIT_CONFIGS WHERE NAME IN ('unit1', 'unit2');In the returned result,
unit1'sMAX_CPUandMIN_CPUhave changed to2, andMEMORY_SIZEhas changed to4294967296(i.e., 4G).LOG_DISK_SIZEremains unchanged. TheALTERstatement only adjusts explicitly specified options. If you need to adjust the log disk specification at the same time, you can specifyLOG_DISK_SIZEin the statement:+----------------+-------+---------+---------+-------------+---------------+ | UNIT_CONFIG_ID | NAME | MAX_CPU | MIN_CPU | MEMORY_SIZE | LOG_DISK_SIZE | +----------------+-------+---------+---------+-------------+---------------+ | 1006 | unit1 | 2 | 2 | 4294967296 | 6442450944 | | 1007 | unit2 | 2 | 2 | 4294967296 | 12884901888 | +----------------+-------+---------+---------+-------------+---------------+ 2 rows in setView the distribution of resource units on nodes and their actual effective status through the
GV$OB_UNITSview:obclient [oceanbase]> SELECT SVR_IP, UNIT_ID, TENANT_ID, ZONE, MAX_CPU, MIN_CPU, MEMORY_SIZE, STATUS FROM oceanbase.GV$OB_UNITS;A sample return result is as follows (
10.10.10.1is an example IP address; in your environment it is the IP address of your own host.UNIT_IDandTENANT_IDvary by environment and can be matched with theTENANT_IDvalues queried in the "Confirm that the tenants are created successfully" step above):+------------+---------+-----------+-------+---------+---------+-------------+--------+ | SVR_IP | UNIT_ID | TENANT_ID | ZONE | MAX_CPU | MIN_CPU | MEMORY_SIZE | STATUS | +------------+---------+-----------+-------+---------+---------+-------------+--------+ | 10.10.10.1 | 1 | 1 | zone1 | 2 | 2 | 1073741824 | NORMAL | | 10.10.10.1 | 1002 | 1001 | zone1 | NULL | NULL | 1073741824 | NORMAL | | 10.10.10.1 | 1002 | 1002 | zone1 | 2 | 2 | 3221225472 | NORMAL | | 10.10.10.1 | 1003 | 1003 | zone1 | NULL | NULL | 1073741824 | NORMAL | | 10.10.10.1 | 1003 | 1004 | zone1 | 2 | 2 | 3221225472 | NORMAL | +------------+---------+-----------+-------+---------+---------+-------------+--------+ 5 rows in setIn the result, each resource unit corresponds to one row. The row whose
TENANT_IDis1is the resource unit of thesystenant; the row whoseMAX_CPUisNULLrecords the resources of the internal Meta tenant; the remaining two rows are the resource units oftenant1andtenant2, andSTATUSofNORMALmeans that the resource unit is running normally.MEMORY_SIZEin the view is the quota that actually takes effect after the system reservation is deducted, so it is less than the configured value (for example, a 4G specification is displayed as 3221225472, which is about 3G).
Note
- After the
ALTER RESOURCE UNITstatement executes successfully, the configuration values inDBA_OB_UNIT_CONFIGSare updated immediately; the actual effective process of the resource unit is completed asynchronously in the background, typically within tens of seconds. If the old values are still queried through theGV$OB_UNITSview, please try again later. - Resource adjustment is completed online, requiring no data migration or restart, and is imperceptible to the business.
- In addition to increasing the specification, you can also use the same method to decrease the specification to achieve tenant resource scaling-down. Ensure the target specification meets the business workload requirements when adjusting.
- By viewing the
DBA_OB_UNITSview, you can also obtain the correspondence between resource units, resource pools, and tenants within the cluster, as well as CPU and memory information.
Comparison of resource change methods
In addition to directly modifying resource configurations, OceanBase also supports changing tenant resources by switching resource configurations, adjusting UNIT_NUM, and modifying ZONE_LIST. These methods apply to different scaling scenarios (the last two apply only to multi-zone, multi-node clusters and cannot be demonstrated in a single-node environment):
Change method |
Statement |
Use cases |
|---|---|---|
| Modify the resource configuration | ALTER RESOURCE UNIT unit1 MAX_CPU=2; |
Adjust the specification directly; the change takes effect online. |
| Switch the resource configuration | ALTER RESOURCE POOL pool1 UNIT='unit3'; |
Switch the entire resource pool to another specification. |
| Adjust UNIT_NUM | ALTER RESOURCE POOL pool1 UNIT_NUM=2; |
Add or remove resource units in each zone. When increasing the number, make sure the target zone has available nodes. When decreasing it, you need to use DELETE UNIT to specify the resource unit to remove. |
| Change ZONE_LIST | ALTER RESOURCE POOL pool1 ZONE_LIST=('zone1','zone2'); |
Expand or narrow the usage scope along the zone dimension. |
Observe tenant performance under stress testing
After you complete the operations in the preceding two sections, the two business tenants tenant1 (1C2G) and tenant2 (2C4G) are ready. This section uses sysbench to run a standard point query stress test against the tenants, to verify that the new tenants can handle business traffic normally, and to help you understand the resource isolation logic of OceanBase from the results.
Procedure
Run a point query stress test against the smaller tenant
tenant1(if you have already adjustedunit1to 2C4G as described in the preceding section, first runALTER RESOURCE UNIT unit1 MAX_CPU=1, MIN_CPU=1, MEMORY_SIZE='2G';to revert the change):obd test sysbench demo --tenant=tenant1 --script-name=oltp_point_select.lua --table-size=100000 --threads=16 --rand-type=uniformOn the first run,
obdautomatically generates the test data, loads the data, and runs the stress test. When the run finishes, it outputs statistics such as QPS and latency; note down the QPS and the 95th percentile latency.Run a stress test with exactly the same parameters against the larger tenant
tenant2(2C4G):obd test sysbench demo --tenant=tenant2 --script-name=oltp_point_select.lua --table-size=100000 --threads=16 --rand-type=uniformCompare the results of the two rounds and focus on the following:
- Both rounds finish normally and output statistics, which shows that each tenant can handle business traffic independently.
- Test data is generated independently in each tenant; the stress test on
tenant1leaves no data intenant2.
Interpretation
The QPS values of the two rounds differ considerably depending on machine specifications, data volume, and concurrency parameters, so focus on the following phenomena rather than on the absolute values:
Observation |
Expected behavior |
Description |
|---|---|---|
| Stress test execution | Both rounds finish normally with no errors. | The new tenants can carry business traffic normally. |
| QPS comparison between the two rounds | The difference may not be significant. | MAX_CPU is an upper limit rather than a guaranteed value. When the cluster has spare CPU resources, a tenant may actually use more CPU than its quota, in which case it is normal for tenants of different specifications to report similar QPS results. |
| Concurrent load across tenants | While tenant2 is under stress test, the query response time in tenant1 remains basically unchanged. |
Resource quota isolation mainly takes effect when multiple tenants compete for resources at the same time: tenants with higher specifications get more computing power, while the services of tenants with lower specifications are not squeezed out. |
Note
obd test sysbenchautomatically completes test data generation, data loading, and stress testing execution. Stress test data is generated independently within each tenant without affecting each other. For detailed descriptions of command parameters, see Experience high-concurrency OLTP scenarios.- The example specifications in this document are relatively small. The test results are mainly used to verify tenant availability and the resource isolation mechanism, and do not represent the production-level performance of OceanBase Database. For the official performance test report, see OceanBase Sysbench performance test report (test data for V4.2.1).
- To observe the resource isolation effect between tenants, you can execute point queries in one tenant while stress testing another to see if its response time (displayed after the query result, e.g.,
1 row in set (0.00 sec)) remains stable.
Next steps
After you complete the experiences in this topic, you can explore the following:
- Experience high availability and failover: Learn about core concepts in OceanBase such as replicas, zones, Leaders/Followers, observe replica and Leader distribution, and experience service continuity under fault scenarios. See Experience high availability and failover.
- Experience horizontal scaling and elastic scaling: Explore the scalability at the compute, storage, and tenant resource levels, and observe resource changes and business capacity impacts before and after scaling. See Experience horizontal scaling and elastic scaling.
- Experience resource isolation within a tenant: Isolate TP and AP workloads within the same tenant using resource groups. See Experience HTAP hybrid workload scenarios.
References
- For basic concepts of the multi-tenant architecture, see Multi-tenant architecture overview.
- For detailed descriptions of tenant resource management (resource configuration, resource pools, and resource units), see Resource management of tenants.
- For information about how to view tenant resource configurations, see View resource specifications.
- For the syntax of dropping a tenant, see DROP TENANT.
- For information about how to configure resource isolation within a tenant (using resource groups), see Configure resource isolation within a tenant.
- For detailed parameters of OBD test commands, see Test commands.