OceanBase Database is a native distributed database management system that supports multiple instances running concurrently in a single database. To get started, the first step typically involves creating a tenant, or a new instance of a database. Once created, tenants can be used as conventional standalone databases. This topic aims to guide you through the process of creating a tenant in OceanBase Database.
Procedure
In OceanBase Database, you can create only user tenants. The sys tenant is automatically created when you create a cluster. The creation of a user tenant involves a series of operations. First, create a unit config, then create a resource pool based on the unit config, and finally create a tenant and specify the resource pool for it. The creation sequence is: unit config -> resource pool -> tenant.
Create a unit config: When you create a unit config, you only define the specification and do not allocate resources. You can query the
DBA_OB_UNIT_CONFIGSview for all unit configs. A unit config can be reused. We recommend that you define different unit configs such as small specification, medium specification, and large specification to simplify O&M. When an urgent scale-up is required due to insufficient tenant resources, you cannot directly adjust the original unit config. Instead, you must create a new unit config or replace the original unit config with a higher-level one.Create a resource pool: When you create a resource pool, resource units are created. Resources are allocated to the resource units based on the unit config. If the resources reserved for a node are insufficient, the creation will fail. You can query the
GV$OB_SERVERSview for the resource allocation information about all nodes. After a resource pool is created, you can query theDBA_OB_RESOURCE_POOLSandDBA_OB_UNITSviews for the resource pool and its resource units. A resource pool cannot be reused. After a tenant is created, the specified resource pool will be allocated to the tenant.Create a tenant: When you create a tenant, you can specify
RESOURCE_POOL_LISTto allocate a resource pool to the tenant. You can query theDBA_OB_TENANTSview for all tenants. Each zone can use a resource pool with a different unit config. Alternatively, all zones can use the same resource pool with the same unit config. Besides the resource pool list, you must also set other important attributes and system variables such as the compatibility mode, primary zone, locality, and connection allowlist. The resource pool list attribute is required when you create a tenant. The password of the root user for a newly created tenant is empty. We recommend that you set a password before you use the root user.
Resource planning
Before you create a tenant, you must perform resource planning. After the tenant is created, resource adjustment is complex. You must deeply understand business scenarios when you participate in the design of the database architecture.
Take note of the following resource planning rules:
Resources must be reserved on each node for emergency scale-up of a tenant.
If the business system involves a large number of writes, set a large memory size and log disk size. Businesses that consume a large amount of CPU resources must be distributed to different nodes to avoid causing a load imbalance among nodes or hotspot nodes, which affects services.
The cluster parameter
resource_hard_limit, also referred to as the over-allocation parameter, specifies the over-allocation percentage of CPU resources. OceanBase Database supports the over-allocation of only CPU resources. CPU resources can be over-allocated in off-peak hours between different tenants in the same cluster to improve overall resource utilization. If the tenants reach a peak at the same time, the over-allocation of CPU resources may cause the tenants to contend for CPU resources.The unit config of a resource unit cannot exceed the total available resources of a single node. For a tenant with a single resource unit, namely,
UNIT_NUMis set to 1 for the resource pool of the tenant, when a capacity bottleneck occurs, you can replace the existing server with one of a larger specification, or add a resource unit for the tenant to use the resources on multiple nodes. For a tenant with multiple resource units, you must carefully design the distribution of business data among the resource units to prevent distributed transactions from compromising the performance. If you estimate that the business volume will exceed the capacity limit of a single server, you must design data sharding in advance and avoid distributed transactions.For a business system migrated from a conventional database to OceanBase Database, the original architecture where a tenant uses a single resource unit is used to ensure smooth migration. This ensures that the business system only needs to access a single node to access the database. When the business volume reaches the maximum capacity of a single node, you can add resource units and split the business data into multiple groups based on business scenarios. Place each group of business data into one resource unit to avoid cross-server access to the business data. This implements horizontal scaling without performance loss. This is also one of the architectural benefits of OceanBase Database against conventional databases. The horizontal scalability can easily break the limit on the capacity of a single server.
Considerations
OceanBase Database supports two tenant modes: MySQL tenant and Oracle tenant. When you create a tenant, you must specify the tenant type. The tenant type cannot be modified after a tenant is created. Therefore, properly plan the tenant type before you create a tenant.
Step 1: Create a unit config
A unit config defines the resource items such as the CPU, memory, disk space, and input/output operations per second (IOPS).
Note
OcenBase Database V4.0 significantly improves the resource management feature based on extensive practices and experience in OceanBase Database V3.x.
- You can manage resource items such as the CPU, memory, log disk space, and IOPS based on resource units. Other resource items such as the data disk space and session quantity cannot be managed based on resource units. To ensure compatibility with the O&M tools and test cases of OceanBase Database V3.x, the
CREATE RESOURCE UNITstatement allows you to specify theMAX_DISK_SIZEandMAX_SESSION_NUMparameters, which do not take effect or return errors. - Over-allocation of CPU resources is supported and controlled by using the
resource_hard_limitparameter. In theGV$OB_SERVERSview, theCPU_CAPACITYandCPU_CAPACITY_MAXfields respectively indicate the total CPU capacity of nodes and the maximum CPU capacity that supports over-allocation. The value ofCPU_CAPACITY_MAXis calculated as follows: CPU_CAPACITY × resource_hard_limit. - Memory over-allocation is no longer supported because it will cause a tenant to become unstable.
- Log disk space isolation is supported between tenants. The system reserves specific log disk space for each tenant. This prevents the log disk from being exhausted by a large number of writes in a single tenant and thereby affects other tenants, which occurs in OceanBase Database V3.x.
- IOPS isolation is supported between tenants. The system introduces three IOPS parameters:
MIN_IOPS,MAX_IOPS, andIOPS_WEIGHT. These parameters do not need to be specified and are automatically calculated by the system based on the CPU specifications. If the sum of theMIN_IOPSvalues of all resource units on a node exceeds the maximum IOPS of the disk, IOPS resources are allocated based on the weight specified byIOPS_WEIGHT. - A meta tenant has no independent resource unit. By default, the system reserves resources for the corresponding meta tenant when a user tenant is created. The resources required by the meta tenant are deducted from those of the user tenant. The default resource settings are used for the meta tenant and cannot be modified.
- When you create a unit config, the CPU specifications and memory size are required. Values of other parameters can be automatically calculated. The log disk space is calculated based on the memory size, and the IOPS size is calculated based on the CPU specifications.
Procedure
Log on to the
systenant of the cluster as therootuser.obclient -h172.30.xx.xx -P2883 -uroot@sys#cluster -p**** -AAccess the database named
oceanbase.USE oceanbase;Query the
DBA_OB_UNIT_CONFIGSview for information about existing unit configs.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-12-20 17:50:17.035504 | 2022-12-20 17:50:17.035504 | 1 | 1 | 14495514624 | 14495514624 | 10000 | 10000 | 1 | | 1001 | config_mysql001_zone1_S1_okz | 2022-12-20 18:04:31.547715 | 2022-12-20 18:04:31.547715 | 1.5 | 1.5 | 6442450944 | 19327352832 | 15000 | 15000 | 1 | | 1002 | config_mysql001_zone2_S1_pme | 2022-12-20 18:04:31.561335 | 2022-12-20 18:04:31.561335 | 1.5 | 1.5 | 6442450944 | 19327352832 | 15000 | 15000 | 1 | | 1003 | config_mysql001_zone3_S1_jsu | 2022-12-20 18:04:31.564510 | 2022-12-20 18:04:31.564510 | 1.5 | 1.5 | 6442450944 | 19327352832 | 15000 | 15000 | 1 | | 1013 | config_oracle001_zone3_S1_exu | 2022-12-26 18:28:37.969047 | 2022-12-26 18:28:37.969047 | 1.5 | 1.5 | 6442450944 | 19327352832 | 15000 | 15000 | 1 | | 1014 | config_oracle001_zone2_S1_hli | 2022-12-26 18:28:37.972194 | 2022-12-26 18:28:37.972194 | 1.5 | 1.5 | 6442450944 | 19327352832 | 15000 | 15000 | 1 | | 1015 | config_oracle001_zone1_S1_owy | 2022-12-26 18:28:37.976446 | 2022-12-26 18:28:37.976446 | 1.5 | 1.5 | 6442450944 | 19327352832 | 15000 | 15000 | 1 | +----------------+-------------------------------+----------------------------+----------------------------+---------+---------+-------------+---------------+----------+----------+-------------+ 7 rows in setFor more information about the
DBA_OB_UNIT_CONFIGSview, see DBA_OB_UNIT_CONFIGS.Execute the
CREATE RESOURCE UNITstatement to create a unit config.The syntax is as follows:
CREATE RESOURCE UNIT unit_name MEMORY_SIZE [=] 'size_value', MAX_CPU [=] cpu_num, [LOG_DISK_SIZE [=] 'size_value',] [MAX_IOPS [=] iops_num,] [MIN_CPU [=] cpu_num,] [MIN_IOPS [=] iops_num];The parameters are described as follows:
When you create a unit config, the
MAX_CPUandMEMORY_SIZEparameters are required.unit_name: the name of the unit config.MEMORY_SIZE: the memory size. The minimum value is 1 GB. OceanBase Database does not support memory over-allocation in V4.0 and later.MAX_CPU: the maximum number of CPU cores.MIN_CPUspecifies the minimum number of CPU cores. The value is the number of CPU cores. IfMIN_CPUis not specified, its value is equal to that ofMAX_CPUby default.MIN_CPU: the minimum number of CPU cores. The sum of theMIN_CPUvalues of all tenants cannot exceed the total CPU capacity of the node, which is specified byCPU_CAPACITY.MAX_IOPSandMIN_IOPS: The minimum values ofMAX_IOPSandMIN_IOPSare1024, and the value ofMAX_IOPSmust be greater than or equal to that ofMIN_IOPS. If you do not specify these parameters, the system automatically calculates the values based on the CPU specifications.The system automatically calculates the values for the IOPS parameters based on the following rules:
If both
MIN_IOPSandMAX_IOPSare not specified, the system automatically calculates their values based on the value ofMIN_CPUby using this rule: One CPU core corresponds to 10,000 IOPS, which meansMAX_IOPS = MIN_IOPS = MIN_CPU * 10000.If
IOPS_WEIGHTis not specified,IOPS_WEIGHT = MIN_CPU.If
IOPS_WEIGHTis specified, the specified value takes precedence.
If only
MAX_IOPSis specified,MIN_IOPSuses the value ofMAX_IOPS. Similarly, if onlyMIN_IOPSis specified,MAX_IOPSuses the value ofMIN_IOPS.- If
IOPS_WEIGHTis not specified, the value is0by default.
- If
LOG_DISK_SIZE: the log disk size. OceanBase Database V4.0 manages the log disk based on tenants. The system reserves specific log disk space for each tenant to implement log disk space isolation between tenants. IfLOG_DISK_SIZEis not specified, its default value is three times that of the memory size. The minimum value is 2 GB.OceanBase Database V4.0 supports IOPS isolation between tenants. The IOPS resources are determined by the
MAX_IOPS,MIN_IOPS, andIOPS_WEIGHTparameters. By default, you do not need to specify the IOPS parameters. The system automatically calculates the parameter values based on the CPU specification.
For more information about the
CREATE RESOURCE UNITstatement, see CREATE RESOURCE UNIT.Here is an example:
Create a unit config named
S1_unit_configthat consists of one CPU core, 2 GB of memory, and 6 GB of log disk space.obclient [oceanbase]> CREATE RESOURCE UNIT S1_unit_config MEMORY_SIZE = '2G', MAX_CPU = 1, MIN_CPU = 1, LOG_DISK_SIZE = '6G', MAX_IOPS = 10000, MIN_IOPS = 10000, IOPS_WEIGHT=1;Query the
DBA_OB_UNIT_CONFIGSview to verify whether the unit config is successfully created.obclient [oceanbase]> SELECT * FROM oceanbase.DBA_OB_UNIT_CONFIGS WHERE NAME = 'S1_unit_config'; +----------------+----------------+----------------------------+----------------------------+---------+---------+-------------+---------------+----------+----------+-------------+ | UNIT_CONFIG_ID | NAME | CREATE_TIME | MODIFY_TIME | MAX_CPU | MIN_CPU | MEMORY_SIZE | LOG_DISK_SIZE | MAX_IOPS | MIN_IOPS | IOPS_WEIGHT | +----------------+----------------+----------------------------+----------------------------+---------+---------+-------------+---------------+----------+----------+-------------+ | 1020 | S1_unit_config | 2023-01-10 22:31:38.805862 | 2023-01-10 22:31:38.805862 | 1 | 1 | 2147483648 | 6442450944 | 10000 | 10000 | 1 | +----------------+----------------+----------------------------+----------------------------+---------+---------+-------------+---------------+----------+----------+-------------+ 1 row in set
Step 2: Create a resource pool
After you create a unit config, you can specify this unit config when you create a resource pool. The unit config defines the sizes of resource items in the resource units, which are finally allocated to corresponding tenants.
Prerequisites
- Sufficient resources are available in the cluster to create a resource pool. For more information, see View tenant and resource information.
- A unit config is available. When you create a resource pool, you must specify its unit config. For more information about how to create a unit config, see Step 1: Create a unit config.
Procedure
Log on to the sys tenant of the cluster as the root user.
obclient -h172.30.xx.xx -P2883 -uroot@sys#cluster -p**** -AAccess the database named
oceanbase.obclient [(none)]> USE oceanbase;Query the
DBA_OB_RESOURCE_POOLSview for the configuration information about resource pools.obclient [oceanbase]> SELECT * FROM oceanbase.DBA_OB_RESOURCE_POOLS; +------------------+--------------------------+-----------+----------------------------+----------------------------+------------+----------------+-------------------+--------------+ | RESOURCE_POOL_ID | NAME | TENANT_ID | CREATE_TIME | MODIFY_TIME | UNIT_COUNT | UNIT_CONFIG_ID | ZONE_LIST | REPLICA_TYPE | +------------------+--------------------------+-----------+----------------------------+----------------------------+------------+----------------+-------------------+--------------+ | 1 | sys_pool | 1 | 2022-12-20 17:50:17.038641 | 2022-12-20 17:50:17.045453 | 1 | 1 | zone1;zone2;zone3 | FULL | | 1001 | pool_mysql001_zone3_jsu | 1002 | 2022-12-20 18:04:31.607227 | 2022-12-20 18:04:31.692836 | 1 | 1003 | zone3 | FULL | | 1002 | pool_mysql001_zone1_okz | 1002 | 2022-12-20 18:04:31.617087 | 2022-12-20 18:04:31.691827 | 1 | 1001 | zone1 | FULL | | 1003 | pool_mysql001_zone2_pme | 1002 | 2022-12-20 18:04:31.621327 | 2022-12-20 18:04:31.692836 | 1 | 1002 | zone2 | FULL | | 1013 | pool_oracle001_zone3_exu | 1010 | 2022-12-26 18:28:37.979539 | 2022-12-26 18:28:38.059505 | 1 | 1013 | zone3 | FULL | | 1014 | pool_oracle001_zone1_owy | 1010 | 2022-12-26 18:28:37.988964 | 2022-12-26 18:28:38.058440 | 1 |