You can specify parameters to manage memory usage in OceanBase Database.
Note
For more information about the parameters mentioned in this topic, see the System parameters chapter of OceanBase Database Reference Guide.
Total memory of OBServers
The total memory of OBServers indicates the upper limit of memory for all OBServers. It is specified by the following two parameters:
memory_limit_percentage: the percentage of the physical memory of the physical machine or container.
memory_limit: an absolute value.
If the memory_limit parameter is not 0, it specifies the upper limit of total memory. Otherwise, the value calculated based on the memory_limit_percentage parameter specifies the upper limit of total memory.
High priority reserved memory
The memory space reserved for some critical underlying modules.
To set the reserved size, you can specify the memory_reserved parameter.
Memory for the SYS500 tenant
The memory space reserved for the SYS500 tenant. To set the reserved size, you can specify the system_memory parameter.
Note that the system_memory parameter does not limit the reserved memory size. In fact, the memory size available to the SYS500 tenant may exceed system_memory. However, the memory size available to other tenants does not exceed the total memory of OBServers, which is the value of system_memory.
Business tenant memory
The business tenant memory is specified by the tenant when the unit is created. The following example shows the sample commands that you can use to specify the tenant memory:
create resource unit if not exists sp_trans_test max_cpu=1, min_memory='1G',max_memory='1G',max_disk_size='1G',max_iops=1000,max_session_num=1000;
create resource pool if not exists sp_trans_test unit='sp_trans_test', unit_num=1;
create tenant if not exists sp_trans_test RESOURCE_POOL_LIST=('sp_trans_test') set ob_tcp_invited_nodes='%';
OceanBase Database supports dynamic adjustment of unit specifications. However, make sure that you proceed with caution when you reduce the unit specifications.
alter RESOURCE UNIT sp_trans_test max_memory='2G',min_memory='2G';
You can query unit specifications by using the internal tables of the SYS tenant.
MySQL [oceanbase]> select *From __all_resource_pool where tenant_id = 1;
+----------------------------+----------------------------+------------------+----------+------------+----------------+-----------+-----------+--------------+--------------------+
| gmt_create | gmt_modified | resource_pool_id | name | unit_count | unit_config_id | zone_list | tenant_id | replica_type | is_tenant_sys_pool |
+----------------------------+----------------------------+------------------+----------+------------+----------------+-----------+-----------+--------------+--------------------+
| 2021-09-09 16:38:33.503570 | 2021-09-09 16:38:33.506882 | 1 | sys_pool | 1 | 1 | z1 | 1 | 0 | 0 |
+----------------------------+----------------------------+------------------+----------+------------+----------------+-----------+-----------+--------------+--------------------+
MySQL [oceanbase]> select * From __all_unit_config where unit_config_id = 1;
+----------------------------+----------------------------+----------------+-----------------+---------+---------+-------------+-------------+----------+----------+---------------+---------------------+
| gmt_create | gmt_modified | unit_config_id | name | max_cpu | min_cpu | max_memory | min_memory | max_iops | min_iops | max_disk_size | max_session_num |
+----------------------------+----------------------------+----------------+-----------------+---------+---------+-------------+-------------+----------+----------+---------------+---------------------+
| 2021-09-09 16:41:52.803406 | 2021-09-09 16:41:52.803406 | 1 | sys_unit_config | 5 | 2.5 | 17179869184 | 12884901888 | 10000 | 5000 | 4398046511104 | 9223372036854775807 |
+----------------------------+----------------------------+----------------+-----------------+---------+---------+-------------+-------------+----------+----------+---------------+---------------------+
Tenant memory classification
Tenant memory is divided into MemStore and SQL execution memory.
MemStore
A MemStore stores the incremental data of an OceanBase database. The upper limit of the MemStore is specified by the memstore_limit_percentage parameter. This parameter indicates the maximum percentage of the total memory occupied by the MemStore. The freeze_trigger_percentage parameter indicates the percentage that triggers a minor compaction when the MemStore memory reaches the specified value. To view the MemStore usage of the tenant, you can query the gv$memstore view.
MySQL [oceanbase]> select * From gv$memstore; +-----------+----------------+-------+-----------+-----------+---------------------+---------------------+------------+ | TENANT_ID | IP | PORT | ACTIVE | TOTAL | FREEZE_TRIGGER | MEM_LIMIT | FREEZE_CNT | +-----------+----------------+-------+-----------+-----------+---------------------+---------------------+------------+ | 1 | 100.81.113.215 | 46824 | 169792200 | 171966464 | 5153960700 | 10307921440 | 0 | | 500 | 100.81.113.215 | 46824 | 0 | 0 | 3689348814741910300 | 7378697629483820640 | 0 | | 1001 | 100.81.113.215 | 46824 | 33539200 | 35651584 | 382730200 | 858993440 | 0 | | 1002 | 100.81.113.215 | 46824 | 0 | 228589568 | 34359738350 | 68719476720 | 0 | +-----------+----------------+-------+-----------+-----------+---------------------+---------------------+------------+SQL execution memory
The memory required for SQL execution and the cache allocated to improve the throughput of SQL execution plans.
The ob_sql_work_area_percentage parameter indicates the memory required by the blocking operators in the SQL statements that may consume a lot of memory.
Memory for the SYS tenant
The SYS tenant is a physical tenant. It is managed by the same mechanism as that for business tenants.
Over allocation
OceanBase Database ensures that the resource usage of an OBServer reaches the soft_limit and remains lower than the hard_limit. Relevant parameters:
resource_hard_limit=100
resource_soft_limit=50
During unit allocation, the resource_hard_limit parameter specifies whether to allow memory over allocation. If you set this parameter to a value that is greater than the default value 100, over allocation is allowed. Two options are available for unit: min_memory and max_memory, which are often set to the same value for unit allocation. To enable memory over allocation, you can leave the value of min_memory unchanged and increase that of max_memory.
However, do not increase the value of the resource_hard_limit and max_memory parameters before you enable the enable_global_freeze_trigger parameter. Otherwise, the total memory of all tenants exceeds the size of the physical memory. In this case, you must use the ob_admin tool to temporarily increase the value of memory_limit.
The preceding temporary solution is applicable only to a system deployed in the 1-1-1 architecture, with three servers evenly distributed in three zones. If partitions that consume a significant amount of memory are migrated to the same OBServer, the memory of the OBServer may be exhausted.
KVCache
The KVCache of the OBServer can automatically consume as much memory as possible. KVCache triggers a memory wash in the following scenarios:
No more memory can be allocated.
The remaining memory for the processes is less than cache_wash_threshold.
The value of max_memory reaches 90%.