By default, the memory allocated to tenants accounts for 80% of the maximum memory of the OceanBase database. In OceanBase Database, the internal memory of a tenant is divided into two parts:
Non-auto scaling memory (memstore)
Auto scaling memory (KVCache)
The non-auto scaling memory is used by the memstore, which stores incremental database data. The auto scaling memory is managed by KVCache. KVCache uses only the memory other than the non-auto scaling memory if possible.
In addition, many memory components, including the plan cache (for caching execution plans) and SQL Arena (memory for SQL statement execution), and some actions such as election occupy a specific amount of memory. You can query the __all_virtual_memory_info view to check the usage of all memory components.
Management of non-auto scaling memory
codememstore_limit_percentagecode is the only parameter related to the non-auto scaling memory. It specifies the maximum percentage of the total memory of the tenant for the memstore. The default value is 50% of the value of min_memory of the tenant. The memory occupied by the memstore increases when the tenant writes data to the memstore or updates data in the memstore. When the memory occupied by the memstore reaches the upper limit, subsequent write or update operations will be denied. OceanBase Database performs minor compactions or major compactions based on the percentage of the memory occupied by the memstore, to release the memory. When the percentage of the memory occupied by the memstore reaches the value of freeze_trigger_percentage, a freeze (an action performed prior to a minor compaction or major compaction) is performed. The default value is 70% of the upper limit of the tenant memory available for the memstore, that is, 35% of the value of min_memory of the tenant.
Management of auto scaling memory
KVCache is the main part of the auto scaling memory. OceanBase Database manages caches for most key-value (KV) formats in KVCache. KVCache supports auto scaling, priority control for different KV formats, and intelligent eviction mechanisms.
Generally, you do not need to configure KVCache. In special scenarios, you can set the priorities for different KV types. Data of a KV type with a higher priority is more likely to be retained in the cache than data of a KV type with a lower priority.
The following table lists the parameters for controlling the priorities of KV types. A greater value indicates a higher priority.
| Parameter | Description |
|---|---|
| fuse_row_cache_priority | The priority of the fuse row cache in the cache system. |
| location_cache_priority | The priority of the location cache in the cache system. |
| clog_cache_priority | The priority of transaction logs in the cache. |
| index_clog_cache_priority | The priority of the transaction log index in the cache system. |
| user_tab_col_stat_cache_priority | The priority of the statistics cache in the cache system. |
| index_cache_priority | The priority of the index in the cache system. |
| index_info_block_cache_priority | The priority of the block index in the cache system. |
| user_block_cache_priority | The priority of the data block cache in the cache system. |
| user_row_cache_priority | The priority of the baseline data row cache in the cache system. |
| bf_cache_priority | The priority of the Bloom filter cache. |
You can query the __all_virtual_kvcache_info parameter to obtain the information about the sub caches in KVCache. The sub caches of a SYS tenant are slightly different from those of a common tenant.
The following table lists the sub caches in the KVCache of a SYS tenant.
Sub cache Description schema_cache Stores the user Schema information, which provides the metadata of database objects for the normal running of SQL statements and the system. location_cache Stores the location information of partitions. You can query this cache to learn of the OBServers on which a partition is located. block_index_cache Caches microblock indexes to speed up access to microblock data. user_block_cache Caches microblock data. Microblocks can be compressed by using compression algorithms, so this cache caches decompressed microblock data, to speed up queries. fuse_row_cache Caches row snapshot data to speed up point queries and prevent cache failures caused by minor compactions or major compactions. index_clog_cache Caches the content of ilog files to minimize the overheads for reading ilog files. user_tab_col_stat_cache Caches the column statistics of the user table, for calculating the costs of executing SQL statements. user_table_stat_cache Caches the user table statistics, for calculating the costs of executing SQL statements.
The following table lists the sub caches in the KVCache of a common tenant.
Sub cache Description user_block_cache Caches microblock data. Microblocks can be compressed by using compression algorithms, so this cache caches decompressed microblock data, to speed up queries. block_index_cache Caches microblock indexes to speed up access to microblock data. fuse_row_cache Caches row snapshot data to speed up point queries and prevent cache failures caused by minor compactions or major compactions.