技术时刻丨OceanBase内存问题排查思路与方法17认证网

正规官方授权
更专业・更权威

技术时刻丨OceanBase内存问题排查思路与方法

报错信息
1
错误码 4013

错误码 4013 的错误信息如下:

ERROR 4013 ( HY001 ): No memory or reach tenant memory limit

该错误码表示各个模块内存不足,例如 working area 不足。出现该问题的可能原因是编译和执行模块内存不足。此时 MemStore 并没有占满,仅仅是各个模块内存不足导致的报错。

如果分析TOP MOD内存,没有异常占用,可以通过调大工作区内存系统变量来规避,将系统变量 ob_sql_work_area_percentage 设置为 10 或者更大。

obclient> SET GLOBAL ob_sql_work_area_percentage=10;

OceanBase 数据库的内存管理方法禁止任何模块通过 glibc 库中的的 malloc 与 free 接口申请和释放内存。OceanBase 数据库的内存除了预留给 500 租户和 sys 租户之外,大部分预留给了普通租户,普通租户的内存限制是可以调节的。但是普通租户的内存限制了普通租户下的 CTX 内存,而 CTX 内存的是被多个 MOD 分配占用。因此,找到对应的 MOD 或者 CTX 就可以确定申请内存失败的操作类型。

2
错误码 4030

错误码 4030 的错误信息如下:

ERROR 4030 ( HY000 ): Over tenant memory limits

该错误码表示 MemStore 内存不足,该错误通常发生在 INSERT、UPDATE、DELETE 语句及 table_scan 动作等 MemStore 操作上,此时错误的日志信息不是 ERROR 级别,而是 WARN 级别。

当 MemStore 内存超限时,需要检查数据写入是否过量或未做限流。当遇到大量写入且数据转储跟不上写入速度的时候就会报这种错误。运行下述语句查看内存状态。

obclient> SELECT /*+ READ_CONSISTENCY(WEAK),query_timeout(100000000) */ TENANT_ID,IP,           round(ACTIVE/1024/1024/1024,2)ACTIVE_GB,           round(TOTAL/1024/1024/1024,2) TOTAL_GB,           round(FREEZE_TRIGGER/1024/1024/1024,2) FREEZE_TRIGGER_GB,           round(TOTAL/FREEZE_TRIGGER*100,2) percent_trigger,           round(MEM_LIMIT/1024/1024/1024,2) MEM_LIMIT_GB FROM gv$memstoreWHERE tenant_id >1000 OR TENANT_ID=1ORDER BY tenant_id,TOTAL_GB DESC;

错误码 4030 的出现可能有以下原因。

1. 模块内存超限。

该问题的紧急应对措施是增加租户内存。问题解决之后需要分析原因,如果是因为未做限流引起,需要加上相应措施,然后回滚之前的租户内存修改。如果确实因为业务规模增长导致租户内存不足以支撑业务时,需要根据转储的频度设置合理的租户内存大小。如 MemStore 内存未超限,运行下述语句判断是哪个内存模块超限。

obclient> SELECT tenant_id,svr_ip,sum(hold) module_sumFROM __all_virtual_memory_infoWHERE tenant_id>1000 AND hold<>0 AND mod_name NOT IN ( 'OB_KVSTORE_CACHE','OB_MEMSTORE'GROUP BY tenant_id,svr_ip;

内存模块超限的判断标准是:module_sum > 租户 min_memory – 租户 MemStore。模块内存超限,可能需要先调整单独模块的内存,如 ob_sql_work_area_percentage。如租户内存过小,也需要加租户内存。

2. PLANCACHE 命中率低于 90%。

OLTP 系统的 PLANCACHE 命中率应不低于 90%,运行下述语句查看 PLANCACHE 命中率。

obclient> SELECT hit_count,executions,(hit_count/executions) AS hit_ratioFROM v$plan_cache_plan_statWHERE (hit_count/executions) < 0.9;
obclient> SELECT hit_count,executions,(hit_count/executions) AS hit_ratioFROM v$plan_cache_plan_statWHERE (hit_count/executions) < 0.9 AND executions > 1000;

寻找是否有相似语句,如 in 或 n``ot in 后面的参数个数随机,导致大量浪费;如果不是上述情况,可能业务量或会话激增导致内存不足,需要调整租户内存大小。

3. 日志中有 fail to alloc memory 或 allocate memory fail 等错误信息。

日志中包含 tenant_id (租户编号)及 mod_id (内存模块编号)信息,可以通过以下语句查询具体的内存模块信息。

obclient> select * from __all_virtual_memory_info where mod_id=xxx and tenant_id = xxx;
如第一个常见内存问题中所述,模块内存超限,可能需要先调整单独模块的内存。如租户内存过小,也需要加租户内存

模块内存超限,可能需要先调整单独模块的内存。如租户内存过小,也需要加租户内存。

3
内存爆分类

内存爆主要分为五类,可以通过关键词 OOPS 确定内存爆的类型。

内存爆的类型
日志信息(关键字为 [OOPS])
SINGLE_ALLOC_SIZE_OVERFLOW
single alloc size large than 4G is not allowed(alloc_size: %ld)
CTX_HOLD_REACH_LIMIT
ctx memory has reached the upper limit(ctx_name: %s, ctx_hold: %ld, ctx_limit: %ld, alloc_size: %ld)
TENANT_HOLD_REACH_LIMIT
tenant memory has reached the upper limit(tenant_id: %lu, tenant_hold: %ld, tenant_limit: %ld, alloc_size: %ld)
SERVER_HOLD_REACH_LIMIT
server memory has reached the upper limit(server_hold: %ld, server_limit: %ld, alloc_size: %ld)
PHYSICAL_MEMORY_EXHAUST
physical memory exhausted(os_total: %ld, os_available: %ld, server_hold: %ld, errno: %d, alloc_size: %ld)

可以在内存爆的时间点(比如 20250109091328503),搜索 OOPS 日志,确定属于哪个类型的内存爆。

grep '\[OOPS\]' observer.log.20250109091328503
内存分析常用SQL

查询OBSERVER列表,确定IP列表与OB准确版本

select id,svr_ip,svr_port,with_rootserver rs,substr(build_version,1,instr(build_version,'-')-1) build_version,status,cast(usec_to_time(start_service_time) as datetime) start_service_time,stop_time from __all_server;
+----+----------------+----------+----+----------------------------+--------+---------------------+-----------+| id | svr_ip         | svr_port | rs | build_version              | status | start_service_time  | stop_time |+----+----------------+----------+----+----------------------------+--------+---------------------+-----------+|  3 | 192.168.56.202 |     2882 |  0 | 3.2.4.5_105000012023081513 | active | 2023-10-10 15:17:55 |         0 ||  4 | 192.168.56.204 |     2882 |  0 | 3.2.4.5_105000012023081513 | active | 2023-10-10 15:18:01 |         0 ||  5 | 192.168.56.209 |     2882 |  0 | 3.2.4.5_105000012023081513 | active | 2023-10-10 15:17:59 |         0 ||  2 | 192.168.56.210 |     2882 |  0 | 3.2.4.5_105000012023081513 | active | 2023-10-14 16:40:51 |         0 ||  6 | 192.168.56.217 |     2882 |  0 | 3.2.4.5_105000012023081513 | active | 2023-10-10 15:18:00 |         0 ||  1 | 192.168.56.225 |     2882 |  1 | 3.2.4.5_105000012023081513 | active | 2023-10-14 18:02:10 |         0 |+----+----------------+----------+----+----------------------------+--------+---------------------+-----------+6 rows in set (0.008 sec)

OBSERVER内存分配情况

select zone,svr_ip,cpu_total,cpu_assigned,round(mem_total/1024/1024/1024) mem_total_GB,round(mem_assigned/1024/1024/1024) mem_assigned_GBfrom oceanbase.__all_virtual_server_stat order by 1,2;
+-------+---------------+-----------+--------------+--------------+-----------------+| zone  | svr_ip        | cpu_total | cpu_assigned | mem_total_GB | mem_assigned_GB |+-------+---------------+-----------+--------------+--------------+-----------------+| zone1 | 192.16.56.42  |       190 |          130 |          553 |             516 || zone1 | 192.16.56.68  |       190 |          120 |          553 |             500 || zone1 | 192.16.56.69  |       190 |          120 |          553 |             500 || zone2 | 192.16.56.137 |       190 |          120 |          553 |             500 || zone2 | 192.16.56.153 |       190 |          120 |          553 |             500 || zone2 | 192.16.56.96  |       190 |          130 |          553 |             516 || zone3 | 192.16.56.163 |       190 |          130 |          553 |             516 || zone3 | 192.16.56.208 |       190 |          120 |          553 |             500 || zone3 | 192.16.56.235 |       190 |          120 |          553 |             500 |+-------+---------------+-----------+--------------+--------------+-----------------+9 rows in set (0.007 sec)

租户UNIT资源分配情况

select  unit_id,tenant_id,tenant_name,svr_ip,min_memory/(1024*1024*1024) min_memory,max_memory/(1024*1024*1024) max_memory,min_cpu,max_cpu from oceanbase.gv$unit order by tenant_id,svr_ip ;+---------+-----------+-------------+----------------+------------+------------+---------+---------+| unit_id | tenant_id | tenant_name | svr_ip         | min_memory | max_memory | min_cpu | max_cpu |+---------+-----------+-------------+----------------+------------+------------+---------+---------+|       3 |         1 | sys         | 192.168.56.104 |    12.0000 |    16.0000 |     2.5 |       5 ||       1 |         1 | sys         | 192.168.56.111 |    12.0000 |    16.0000 |     2.5 |       5 ||       2 |         1 | sys         | 192.168.56.185 |    12.0000 |    16.0000 |     2.5 |       5 ||    1034 |      1004 | testf       | 192.168.56.103 |   500.0000 |   500.0000 |     120 |     120 ||    1036 |      1004 | testf       | 192.168.56.104 |   500.0000 |   500.0000 |     120 |     120 ||    1042 |      1004 | testf       | 192.168.56.111 |   500.0000 |   500.0000 |     120 |     120 ||    1037 |      1004 | testf       | 192.168.56.150 |   500.0000 |   500.0000 |     120 |     120 ||    1039 |      1004 | testf       | 192.168.56.185 |   500.0000 |   500.0000 |     120 |     120 ||    1040 |      1004 | testf       | 192.168.56.194 |   500.0000 |   500.0000 |     120 |     120 ||    1041 |      1004 | testf       | 192.168.56.71  |   500.0000 |   500.0000 |     120 |     120 ||    1038 |      1004 | testf       | 192.168.56.72  |   500.0000 |   500.0000 |     120 |     120 ||    1035 |      1004 | testf       | 192.168.56.73  |   500.0000 |   500.0000 |     120 |     120 |+---------+-----------+-------------+----------------+------------+------------+---------+---------+12 rows in set (0.015 sec)

租户内存使用情况

select svr_ip,round(sum(hold)/1024/1024/1024) hold_gb,(select round(max_memory/1024/1024/1024,2from gv$unit where tenant_id=t.tenant_id and svr_ip=t.svr_ip) as max_memory_limit from __all_virtual_memory_info t where tenant_id=1001 group by  svr_ip;
MySQL [oceanbase]> select svr_ip,round(sum(hold)/1024/1024/1024) hold_gb,(select round(max_memory/1024/1024/1024,2from gv$unit where tenant_id=t.tenant_id and svr_ip=t.svr_ip) as max_memory_limit from __all_virtual_memory_info t where tenant_id=1001 group by  svr_ip;+---------------+---------+------------------+| svr_ip        | hold_gb | max_memory_limit |+---------------+---------+------------------+| 192.16.56.137 |     426 |           500.00 || 192.16.56.153 |     417 |           500.00 || 192.16.56.163 |     482 |           500.00 || 192.16.56.208 |     483 |           500.00 || 192.16.56.235 |     482 |           500.00 || 192.16.56.42  |     466 |           500.00 || 192.16.56.68  |     433 |           500.00 || 192.16.56.69  |     446 |           500.00 || 192.16.56.96  |     378 |           500.00 |+---------------+---------+------------------+9 rows in set (0.174 sec)

查看租户memstore使用情况

select a.IP,a.tenant_id,b.tenant_name,round(active/1024/1024/1024,2) active,round(total/1024/1024/1024,2) total,round(freeze_trigger/1024/1024/1024,2) freeze_trigger,round(total/freeze_trigger,2"total/freeze_trigger",round(mem_limit/1024/1024/1024,2) mem_limit,FREEZE_CNTfrom oceanbase.gv$memstore a,oceanbase.__all_tenant b where a.tenant_id>1000 and a.tenant_id=b.tenant_id order by 1,2,3;
active 正在使用的,total 全部分配使用的(active+freeze),free_trigger触发冻结的阀值,mem_limit memstore上限,超过则报4030+---------------+-----------+-----------------+--------+-------+----------------+----------------------+-----------+------------+| IP            | tenant_id | tenant_name     | active | total | freeze_trigger | total/freeze_trigger | mem_limit | FREEZE_CNT |+---------------+-----------+-----------------+--------+-------+----------------+----------------------+-----------+------------+192.168.56.36 |      1005 | tpcc_tenant     |   0.58 |  0.58 |          14.00 |                 0.04 |     20.00 |          0 |192.168.56.37 |      1005 | tpcc_tenant     |   0.59 |  0.59 |          14.00 |                 0.04 |     20.00 |          0 |192.168.56.38 |      1005 | tpcc_tenant     |   0.00 |  0.29 |          14.00 |                 0.02 |     20.00 |          0 |192.168.56.38 |      1006 | tpcc_tenant_111 |   1.00 |  1.00 |          28.00 |                 0.04 |     40.00 |          0 |192.168.56.86 |      1005 | tpcc_tenant     |   0.00 |  0.47 |          14.00 |                 0.03 |     20.00 |          0 |192.168.56.86 |      1006 | tpcc_tenant_111 |   0.99 |  1.00 |          28.00 |                 0.04 |     40.00 |          0 |192.168.56.87 |      1005 | tpcc_tenant     |   0.00 |  0.27 |          14.00 |                 0.02 |     20.00 |          0 |192.168.56.87 |      1006 | tpcc_tenant_111 |   1.00 |  1.00 |          28.00 |                 0.04 |     40.00 |          0 |192.168.56.88 |      1005 | tpcc_tenant     |   0.58 |  0.58 |          14.00 |                 0.04 |     20.00 |          0 |+---------------+-----------+-----------------+--------+-------+----------------+----------------------+-----------+------------+21 rows in set (0.038 sec)

obclient [oceanbase]> 

非memstore内存使用情况

MySQL [oceanbase]> select svr_ip,round(sum(hold)/1024/1024/1024) gb from __all_virtual_memory_info where mod_name not in ('OB_KVSTORE_CACHE','OB_MEMSTORE')  and tenant_id=1001 group by  svr_ip;
+---------------+------+| svr_ip        | gb   |+---------------+------+| 192.16.56.137 |  360 || 192.16.56.153 |  408 || 192.16.56.163 |  475 || 192.16.56.208 |  417 || 192.16.56.235 |  467 || 192.16.56.42  |  450 || 192.16.56.68  |  357 || 192.16.56.69  |  430 || 192.16.56.96  |  364 |+---------------+------+9 rows in set (0.149 sec)

TOP 模块内存(非memstore)

--tenant_id=1001改为报错的租户IDMySQL [oceanbase]> select * from __all_virtual_memory_info  where mod_name not in ('OB_KVSTORE_CACHE','OB_MEMSTORE')   and tenant_id=1001  order by used desc limit 10;+-----------+---------------+----------+--------+-----------------+-------------------+----------+--------+-----------------+-------+-------------+-------------+----------+-------------+------------+| tenant_id | svr_ip        | svr_port | ctx_id | label           | ctx_name          | mod_type | mod_id | mod_name        | zone  | hold        | used        | count    | alloc_count | free_count |+-----------+---------------+----------+--------+-----------------+-------------------+----------+--------+-----------------+-------+-------------+-------------+----------+-------------+------------+|      1001 | 192.16.56.42  |     2882 |     33 | SqlPsCache      | PS_CACHE_CTX_ID   | user     |      0 | SqlPsCache      | zone1 | 29432209968 | 25362888283 | 10405720 |           0 |          0 ||      1001 | 192.16.56.69  |     2882 |     33 | SqlPsCache      | PS_CACHE_CTX_ID   | user     |      0 | SqlPsCache      | zone1 | 23442790304 | 20534608390 | 10996936 |           0 |          0 ||      1001 | 192.16.56.68  |     2882 |     33 | SqlPsCache      | PS_CACHE_CTX_ID   | user     |      0 | SqlPsCache      | zone1 | 18802404704 | 17258674095 | 11805159 |           0 |          0 ||      1001 | 192.16.56.68  |     2882 |     22 | OB_SQL_PHY_PLAN | PLAN_CACHE_CTX_ID | user     |      0 | OB_SQL_PHY_PLAN | zone1 | 15889853952 | 15196217169 |  1504673 |           0 |          0 ||      1001 | 192.16.56.235 |     2882 |      0 | MysqlRequesReco | DEFAULT_CTX_ID    | user     |      0 | MysqlRequesReco | zone3 | 14944869888 | 14888637440 |     7090 |           0 |          0 ||      1001 | 192.16.56.68  |     2882 |      0 | MysqlRequesReco | DEFAULT_CTX_ID    | user     |      0 | MysqlRequesReco | zone1 | 14471029248 | 14416532480 |     6864 |           0 |          0 ||      1001 | 192.16.56.42  |     2882 |      0 | MysqlRequesReco | DEFAULT_CTX_ID    | user     |      0 | MysqlRequesReco | zone1 | 14414419968 | 14360130560 |     6837 |           0 |          0 ||      1001 | 192.16.56.153 |     2882 |      0 | MysqlRequesReco | DEFAULT_CTX_ID    | user     |      0 | MysqlRequesReco | zone2 | 14364100608 | 14309995520 |     6813 |           0 |          0 ||      1001 | 192.16.56.69  |     2882 |      0 | MysqlRequesReco | DEFAULT_CTX_ID    | user     |      0 | MysqlRequesReco | zone1 | 14338940928 | 14284928000 |     6801 |           0 |          0 ||      1001 | 192.16.56.163 |     2882 |      0 | MysqlRequesReco | DEFAULT_CTX_ID    | user     |      0 | MysqlRequesReco | zone3 | 14261365248 | 14207636480 |     6764 |           0 |          0 |+-----------+---------------+-

'OB_KVSTORE_CACHE','OB_MEMSTORE'

workarea内存分析

MySQL [oceanbase]> desc gv$sql_workarea ;+------------------------+--------------+------+-----+---------+-------+| Field                  | Type         | Null | Key | Default | Extra |+------------------------+--------------+------+-----+---------+-------+| address                | varbinary(8| NO   |     |         |       || hash_value             | bigint(0)    | NO   |     |         |       || sql_id                 | varchar(32)  | NO   |     | NULL    |       || child_number           | bigint(0)    | NO   |     |         |       || workarea_address       | varbinary(8| NO   |     |         |       || operation_type         | varchar(40)  | NO   |     | NULL    |       || operation_id           | bigint(20)   | NO   |     | NULL    |       || policy                 | varchar(10)  | NO   |     | NULL    |       || estimated_optimal_size | bigint(20)   | NO   |     | NULL    |       || estimated_onepass_size | bigint(20)   | NO   |     | NULL    |       || last_memory_used       | bigint(20)   | NO   |     | NULL    |       || last_execution         | varchar(10)  | NO   |     | NULL    |       || last_degree            | bigint(20)   | NO   |     | NULL    |       || total_executions       | bigint(20)   | NO   |     | NULL    |       || optimal_executions     | bigint(20)   | NO   |     | NULL    |       || onepass_executions     | bigint(20)   | NO   |     | NULL    |       || multipasses_executions | bigint(20)   | NO   |     | NULL    |       || active_time            | bigint(20)   | NO   |     | NULL    |       || max_tempseg_size       | bigint(20)   | NO   |     | NULL    |       || last_tempseg_size      | bigint(20)   | NO   |     | NULL    |       || con_id                 | bigint(20)   | NO   |     | NULL    |       |+------------------------+--------------+------+-----+---------+-------+21 rows in set (0.004 sec)
select * from (select * from gv$sql_workarea order by last_memory_used desc)  limit 5\G

*************************** 1. row ***************************               address: NULL            hash_value: NULL                sql_id: 8257AE4903C5DDEC7DF9725B8BDB996D          child_number: NULL      workarea_address: NULL        operation_type: PHY_SORT          operation_id: 8                policy: AUTOestimated_optimal_size: 246185881estimated_onepass_size: 4016720      last_memory_used: 235339776        last_execution: OPTIMAL           last_degree: 1      total_executions: 283897    optimal_executions: 283895    onepass_executions: 2multipasses_executions: 0           active_time: 90650      max_tempseg_size: 4585840     last_tempseg_size: 0                con_id: 1001
select * from (select * from gv$sql_workarea order by MAX_TEMPSEG_SIZE desc)  limit 5\G
*************************** 1. row ***************************               address: NULL            hash_value: NULL                sql_id: A9BE27683B46C64B10CF6221B9B76CB2          child_number: NULL      workarea_address: NULL        operation_type: PHY_HASH_JOIN          operation_id: 39                policy: AUTOestimated_optimal_size: 6276878246estimated_onepass_size: 20282049      last_memory_used: 40032        last_execution: OPTIMAL           last_degree: 1      total_executions: 36536    optimal_executions: 36535    onepass_executions: 0multipasses_executions: 1           active_time: 243395      max_tempseg_size: 47318465944     last_tempseg_size: 0                con_id: 1001
MySQL [oceanbase]> select OPERATION_TYPE,COUNT(*from gv$sql_workarea GROUP BY OPERATION_TYPE;+----------------------------+----------+| OPERATION_TYPE             | COUNT(*|+----------------------------+----------+| PHY_HASH_JOIN              |     5230 || PHY_SORT                   |      787 || PHY_HASH_GROUP_BY          |      147 || PHY_HASH_DISTINCT          |      111 || PHY_HASH_UNION             |       46 || PHY_HASH_EXCEPT            |       11 || PHY_MATERIAL               |        9 || PHY_INVALID                |        9 || PHY_HASH_INTERSECT         |        4 || PHY_NESTED_LOOP_CONNECT_BY |       12 |+----------------------------+----------+10 rows in set (0.036 sec)
内存泄露抓取call stack

示例

1、构造一行LOB数据时报错 -4013, No memory or reach tenant memory limit

DECLAREblob;BEGINdbms_lob.createtemporary(lob_loc => c, cache => true, dur => dbms_lob.call);    FOR i IN 1..10240 loop    DBMS_LOB.WRITEAPPEND(c,1024,hextoraw(rpad('01',2048,'01')));END LOOP;INSERT INTO  tlob VALUES (2,c);COMMIT;END;/

obclient [SYS]> DECLARE    -> c blob;    -> BEGIN    -> dbms_lob.createtemporary(lob_loc => c, cache => FALSE, dur => dbms_lob.call);    ->     FOR i IN 1..10240 loop    ->     DBMS_LOB.WRITEAPPEND(c,1024,hextoraw(rpad('01',2048,'01')));    -> END LOOP;    -> INSERT INTO  tlob VALUES (2,c);    -> COMMIT;    -> END;    -> /ORA-00600: internal error code, arguments: -4013No memory or reach tenant memory limit

2、 因能重现,在执行过程中查询TOP MOD占用,可以看到SQL_EXEC_CTX_ID CTX内存使用不断增长,增长到100G以上后释放(SQL执行报错后释放)

obclient [oceanbase]> select * from __all_virtual_tenant_ctx_memory_info where  tenant_id=1001 order by hold desc limit 30;+-----------+---------------+----------+--------+----------------------+-------------+-------------+| tenant_id | svr_ip        | svr_port | ctx_id | ctx_name             | hold        | used        |+-----------+---------------+----------+--------+----------------------+-------------+-------------+|      1001 | 192.168.56.36 |     2882 |      5 | SQL_EXEC_CTX_ID      | 25035800576 | 20710254976 ||      1001 | 192.168.56.37 |     2882 |     31 | KVSTORE_CACHE_ID     |  1927282688 |  1927282688 ||      1001 | 192.168.56.38 |     2882 |     31 | KVSTORE_CACHE_ID     |  1862270976 |  1862270976 ||      1001 | 192.168.56.36 |     2882 |      0 | DEFAULT_CTX_ID       |  1698693120 |  1606241648 ||      1001 | 192.168.56.36 |     2882 |      1 | MEMSTORE_CTX_ID      |  1075838976 |  1073507456 ||      1001 | 192.168.56.38 |     2882 |      1 | MEMSTORE_CTX_ID      |   643825664 |   641602176 ||      1001 | 192.168.56.37 |     2882 |      1 | MEMSTORE_CTX_ID      |   599785472 |   597572736 ||      1001 | 192.168.56.38 |     2882 |      5 | SQL_EXEC_CTX_ID      |   528482304 |       27776 ||      1001 | 192.168.56.37 |     2882 |      5 | SQL_EXEC_CTX_ID      |   463470592 |       27776 ||      1001 | 192.168.56.37 |     2882 |      0 | DEFAULT_CTX_ID       |   318767104 |   253025472 ||      1001 | 192.168.56.36 |     2882 |     32 | TX_CALLBACK_CTX_ID   |   304087040 |   122315648 ||      1001 | 192.168.56.38 |     2882 |      0 | DEFAULT_CTX_ID       |   293601280 |   217898304 ||      1001 | 192.168.56.37 |     2882 |     32 | TX_CALLBACK_CTX_ID   |   199229440 |    22649216 ||      1001 | 192.168.56.38 |     2882 |     32 | TX_CALLBACK_CTX_ID   |   186646528 |    20742080 ||      1001 | 192.168.56.36 |     2882 |     31 | KVSTORE_CACHE_ID     |    33554432 |    33554432 ||      1001 | 192.168.56.36 |     2882 |     22 | PLAN_CACHE_CTX_ID    |    25165824 |    13518752 ||      1001 | 192.168.56.37 |     2882 |      6 | TRANS_CTX_MGR_ID     |    16777216 |      848128 ||      1001 | 192.168.56.36 |     2882 |      6 | TRANS_CTX_MGR_ID     |    16777216 |      848128 ||      1001 | 192.168.56.37 |     2882 |     17 | REPLAY_STATUS_CTX_ID |    16777216 |     1165696 ||      1001 | 192.168.56.36 |     2882 |     24 | WORK_AREA            |    16777216 |       27776 ||      1001 | 192.168.56.36 |     2882 |      4 | EXECUTE_CTX_ID       |    16777216 |       36032 ||      1001 | 192.168.56.36 |     2882 |     17 | REPLAY_STATUS_CTX_ID |    16777216 |     1165696 ||      1001 | 192.168.56.38 |     2882 |      6 | TRANS_CTX_MGR_ID     |    14680064 |      844160 ||      1001 | 192.168.56.36 |     2882 |     33 | PS_CACHE_CTX_ID      |    14680064 |       79136 ||      1001 | 192.168.56.38 |     2882 |     17 | REPLAY_STATUS_CTX_ID |    14680064 |     1161728 ||      1001 | 192.168.56.37 |     2882 |     22 | PLAN_CACHE_CTX_ID    |    10485760 |      674976 ||      1001 | 192.168.56.38 |     2882 |     22 | PLAN_CACHE_CTX_ID    |    10485760 |       11904 ||      1001 | 192.168.56.37 |     2882 |      4 | EXECUTE_CTX_ID       |     6291456 |        7936 ||      1001 | 192.168.56.38 |     2882 |     24 | WORK_AREA            |     6291456 |       27776 ||      1001 | 192.168.56.38 |     2882 |      4 | EXECUTE_CTX_ID       |     6291456 |        7936 |+-----------+---------------+----------+--------+----------------------+-------------+-------------+30 rows in set (0.030 sec)

obclient [oceanbase]> select * from __all_virtual_memory_info  where tenant_id=1001 order by used desc limit 10;+-----------+---------------+----------+--------+-----------------+--------------------+----------+--------+-----------------+-------+-------------+-------------+-------+-------------+------------+| tenant_id | svr_ip        | svr_port | ctx_id | label           | ctx_name           | mod_type | mod_id | mod_name        | zone  | hold        | used        | count | alloc_count | free_count |+-----------+---------------+----------+--------+-----------------+--------------------+----------+--------+-----------------+-------+-------------+-------------+-------+-------------+------------+|      1001 | 192.168.56.36 |     2882 |      5 | SqlExecutor     | SQL_EXEC_CTX_ID    | user     |      0 | SqlExecutor     | zone1 | 53738147328 | 43948083592 | 11489 |           0 |          0 ||      1001 | 192.168.56.36 |     2882 |      0 | MysqlRequesReco | DEFAULT_CTX_ID     | user     |      0 | MysqlRequesReco | zone1 |  1444610048 |  1436936320 |   642 |           0 |          0 ||      1001 | 192.168.56.36 |     2882 |      1 | OB_MEMSTORE     | MEMSTORE_CTX_ID    | user     |      0 | OB_MEMSTORE     | zone1 |  1073479680 |  1073254400 |   512 |           0 |          0 ||      1001 | 192.168.56.38 |     2882 |      1 | OB_MEMSTORE     | MEMSTORE_CTX_ID    | user     |      0 | OB_MEMSTORE     | zone3 |   643671040 |   643052616 |   303 |           0 |          0 ||      1001 | 192.168.56.37 |     2882 |      1 | OB_MEMSTORE     | MEMSTORE_CTX_ID    | user     |      0 | OB_MEMSTORE     | zone2 |   597544960 |   596936216 |   281 |           0 |          0 ||      1001 | 192.168.56.37 |     2882 |      0 | MysqlRequesReco | DEFAULT_CTX_ID     | user     |      0 | MysqlRequesReco | zone2 |   132108288 |   130135040 |    25 |           0 |          0 ||      1001 | 192.168.56.36 |     2882 |     32 | MemtableCallbac | TX_CALLBACK_CTX_ID | user     |      0 | MemtableCallbac | zone1 |   122287872 |   121339904 | 14812 |           0 |          0 ||      1001 | 192.168.56.38 |     2882 |      0 | MysqlRequesReco | DEFAULT_CTX_ID     | user     |      0 | MysqlRequesReco | zone3 |   106948608 |   105067520 |    13 |           0 |          0 ||      1001 | 192.168.56.37 |     2882 |      0 | LogAggreBuffer  | DEFAULT_CTX_ID     | user     |      0 | LogAggreBuffer  | zone2 |    44994560 |    44302336 |   676 |           0 |          0 ||      1001 | 192.168.56.36 |     2882 |      0 | LogAggreBuffer  | DEFAULT_CTX_ID     | user     |      0 | LogAggreBuffer  | zone1 |    44994560 |    44302336 |   676 |           0 |          0 |+-----------+---------------+----------+--------+-----------------+--------------------+----------+--------+-----------------+-------+-------------+-------------+-------+-------------+------------+10 rows in set (0.050 sec)

3、造一行10M的LOB,竟然需要100多G的内存,尝试定位内存泄露,开启 mem_leak check

登录sys租户上面我们已知知道MOD SqlExecutor点用内存高,下面针对SqlExecutor开启mem leak check,抓取分配内存多的堆栈obclient [oceanbase]> alter system set leak_mod_to_check='SqlExecutor';Query OK, 0 rows affected (0.060 sec)

4、执行SQL

obclient [SYS]> DECLARE    -> c blob;    -> BEGIN    -> dbms_lob.createtemporary(lob_loc => c, cache => FALSE, dur => dbms_lob.call);    ->     FOR i IN 1..10240 loop    ->     DBMS_LOB.WRITEAPPEND(c,1024,hextoraw(rpad('01',2048,'01')));    -> END LOOP;    -> INSERT INTO  tlob VALUES (2,c);    -> COMMIT;    -> END;    -> /
ORA-00600: internal error code, arguments: -4013No memory or reach tenant memory limit

5、抓取分配内存多的堆栈

obclient [oceanbase]> SELECT * FROM oceanbase.__all_virtual_mem_leak_checker_info ORDER BY alloc_count DESC limit 10;+---------------+----------+-------------+----------+-------------+-------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| svr_ip        | svr_port | mod_name    | mod_type | alloc_count | alloc_size  | back_trace                                                                                                                                                                                                                                                                                                                                                                                 |+---------------+----------+-------------+----------+-------------+-------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| 192.168.56.36 |     2882 | SqlExecutor | user     |        7109 | 40773641064 | 0x1127126a 0x5d930dc 0x5ce1928 0x5d19f5c 0x5f4bd73 0x884f0f9 0x8857e92 0x8859508 0x885fd16 0xf9427a4 0x7fbc82bed031 0x8393031 0x839208d 0x8383e0a 0x83803ae 0x7fc293519839 0x8393079 0x839208d 0x8395290 0xfbe55df 0x5e9f00b 0x5d442ef 0x5ce4b27 0x5cd4291 0x5e8e44b 0x5cc1be2 0x5cbdf7c 0x5cbbf6e 0xcdc0ff1 0x5cbb097 0xcdbe75c 0x5cb6819 0xcdbed07 0x10bf22a3 0x10bf20ff 0x11bae3ff      || 192.168.56.36 |     2882 | SqlExecutor | user     |        7109 | 40773356704 | 0x1127126a 0x5d930dc 0x5ce1928 0x5d19f5c 0x5f4bd73 0x8857cfe 0x8859508 0x885fd16 0xf9427a4 0x7fbc82bed031 0x8393031 0x839208d 0x8383e0a 0x83803ae 0x7fc293519839 0x8393079 0x839208d 0x8395290 0xfbe55df 0x5e9f00b 0x5d442ef 0x5ce4b27 0x5cd4291 0x5e8e44b 0x5cc1be2 0x5cbdf7c 0x5cbbf6e 0xcdc0ff1 0x5cbb097 0xcdbe75c 0x5cb6819 0xcdbed07 0x10bf22a3 0x10bf20ff 0x11bae3ff                || 192.168.56.36 |     2882 | SqlExecutor | user     |        1465 |  3070827520 | 0x1127126a 0x5d930dc 0x5ce1928 0x5d19f5c 0x5f4be0c 0x8857cfe 0x8859508 0x885fd16 0xf9427a4 0x7fbc82bed031 0x8393031 0x839208d 0x8383e0a 0x83803ae 0x7fc293519839 0x8393079 0x839208d 0x8395290 0xfbe55df 0x5e9f00b 0x5d442ef 0x5ce4b27 0x5cd4291 0x5e8e44b 0x5cc1be2 0x5cbdf7c 0x5cbbf6e 0xcdc0ff1 0x5cbb097 0xcdbe75c 0x5cb6819 0xcdbed07 0x10bf22a3 0x10bf20ff 0x11bae3ff                || 192.168.56.36 |     2882 | SqlExecutor | user     |        1170 |  2452469760 | 0x1127126a 0x5d930dc 0x5ce1928 0x5d19f5c 0x5f4be0c 0x884f0f9 0x8857e92 0x8859508 0x885fd16 0xf9427a4 0x7fbc82bed031 0x8393031 0x839208d 0x8383e0a 0x83803ae 0x7fc293519839 0x8393079 0x839208d 0x8395290 0xfbe55df 0x5e9f00b 0x5d442ef 0x5ce4b27 0x5cd4291 0x5e8e44b 0x5cc1be2 0x5cbdf7c 0x5cbbf6e 0xcdc0ff1 0x5cbb097 0xcdbe75c 0x5cb6819 0xcdbed07 0x10bf22a3 0x10bf20ff 0x11bae3ff      || 192.168.56.36 |     2882 | SqlExecutor | user     |          24 |    50307072 | 0x1127126a 0x5d930dc 0x5ce1928 0x5d19f5c 0x5f4be0c 0x5de10ad 0x885fbdd 0xf9427a4 0x7fbc82bed031 0x8393031 0x839208d 0x8383e0a 0x83803ae 0x7fc293519839 0x8393079 0x839208d 0x8395290 0xfbe55df 0x5e9f00b 0x5d442ef 0x5ce4b27 0x5cd4291 0x5e8e44b 0x5cc1be2 0x5cbdf7c 0x5cbbf6e 0xcdc0ff1 0x5cbb097 0xcdbe75c 0x5cb6819 0xcdbed07 0x10bf22a3 0x10bf20ff 0x11bae3ff                          || 192.168.56.36 |     2882 | SqlExecutor | user     |          18 |    37730304 | 0x1127126a 0x5d930dc 0x5ce1928 0x5d19f5c 0x5f4be0c 0xdf65c76 0xdf677eb 0xdf6636e 0xdf6dff2 0x5edceb3 0x5edcb4e 0x5edc8ea 0x5edc59e 0xfd2dc25 0xf8f1cd7 0xf8f6e65 0x7fc2935197c6 0x8393079 0x839208d 0x8395290 0xfbe55df 0x5e9f00b 0x5d442ef 0x5ce4b27 0x5cd4291 0x5e8e44b 0x5cc1be2 0x5cbdf7c 0x5cbbf6e 0xcdc0ff1 0x5cbb097 0xcdbe75c 0x5cb6819 0xcdbed07 0x10bf22a3 0x10bf20ff 0x11bae3ff || 192.168.56.36 |     2882 | SqlExecutor | user     |          16 |    33538048 | 0x1127126a 0x5d930dc 0x5ce1928 0x5d19f5c 0x5f4be0c 0x76c445f 0x76c69da 0xd7c180b 0x5edcecb 0x5edcb4e 0x5edc59e 0xfd2dc25 0xf8f1cd7 0xf8f6e65 0x7fc2935197c6 0x8393079 0x839208d 0x8395290 0xfbe55df 0x5e9f00b 0x5d442ef 0x5ce4b27 0x5cd4291 0x5e8e44b 0x5cc1be2 0x5cbdf7c 0x5cbbf6e 0xcdc0ff1 0x5cbb097 0xcdbe75c 0x5cb6819 0xcdbed07 0x10bf22a3 0x10bf20ff 0x11bae3ff                     || 192.168.56.36 |     2882 | SqlExecutor | user     |           2 |     4192256 | 0x1127126a 0x5d930dc 0x5ce1928 0x5d19f5c 0x5f4bc8d 0x5d1bc66 0x5cbc61d 0x5cbbe9e 0xcdc0fb7 0x5cbb097 0xcdbe75c 0x5cb6819 0xcdbed07 0x10bf22a3 0x10bf20ff 0x11bae3ff                                                                                                                                                                                                                        || 192.168.56.38 |     2882 | SqlExecutor | user     |           1 |     2096128 | 0x1127126a 0x5d930dc 0x5ce1928 0x5d19f5c 0x5f4bc8d 0xd0cae01 0x5d3b881 0x5cbc672 0x5cbbe9e 0xcdc0fb7 0x5cbb097 0xcdbe75c 0x5cb6819 0xcdbed07 0x10bf22a3 0x10bf20ff 0x11bae3ff                                                                                                                                                                                                              || 192.168.56.37 |     2882 | SqlExecutor | user     |           1 |     2096128 | 0x1127126a 0x5d930dc 0x5ce1928 0x5d19f5c 0x5f4bc8d 0xd0cae01 0x5d3b881 0x5cbc672 0x5cbbe9e 0xcdc0fb7 0x5cbb097 0xcdbe75c 0x5cb6819 0xcdbed07 0x10bf22a3 0x10bf20ff 0x11bae3ff                                                                                                                                                                                                              |+---------------+----------+-------------+----------+-------------+-------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+10 rows in set (0.046 sec)

6、将16进制地址转换实际函数名

[root@ob1 ~]# addr2line -pCfe /home/admin/oceanbase/bin/observer 0x1127126a 0x5d930dc 0x5ce1928 0x5d19f5c 0x5f4bd73 0x884f0f9 0x8857e92 0x8859508 0x885fd16 0xf9427a4 0x7fbc82bed031 0x8393031 0x839208d 0x8383e0a 0x83803ae 0x7fc293519839 0x8393079 0x839208d 0x8395290 0xfbe55df 0x5e9f00b 0x5d442ef 0x5ce4b27 0x5cd4291 0x5e8e44b 0x5cc1be2 0x5cbdf7c 0x5cbbf6e 0xcdc0ff1 0x5cbb097 0xcdbe75c 0x5cb6819 0xcdbed07 0x10bf22a3 0x10bf20ff 0x11bae3ffoceanbase::common::lbt(char*, int) at ./build_rpm/deps/oblib/src/lib/./deps/oblib/src/lib/utility/ob_backtrace.cpp:136oceanbase::common::ObMemLeakChecker::on_alloc(oceanbase::lib::AObject&) at ./build_rpm/deps/oblib/src/lib/./deps/oblib/src/lib/allocator/ob_mem_leak_checker.h:187oceanbase::common::ObAllocator::alloc(long, oceanbase::lib::ObMemAttr const&) at ??:?oceanbase::common::PageArena<char, oceanbase::common::ModulePageAllocator>::alloc_new_page(long) at ./build_rpm/deps/oblib/src/lib/./deps/oblib/src/lib/allocator/page_arena.h:328oceanbase::common::PageArena<char, oceanbase::common::ModulePageAllocator>::alloc_big(long) at ./build_rpm/deps/oblib/src/lib/./deps/oblib/src/lib/allocator/page_arena.h:418oceanbase::pl::ObDbmsLobBase::build_lob_locator(oceanbase::common::ObLobLocator*&, oceanbase::common::ObIAllocator&, unsigned long, unsigned long, long, unsigned short, oceanbase::common::ObString const&, oceanbase::common::ObString const&) at ./build_rpm/src/pl/./src/pl/sys_package/ob_dbms_lob.cpp:193oceanbase::pl::ObDbmsLob::calc_write_result(oceanbase::sql::ObExecContext&, oceanbase::common::Ob2DArray<oceanbase::common::ObObjParam2096128, oceanbase::common::ObWrapperAllocatorfalse, oceanbase::common::ObSEArray<oceanbase::common::ObObjParam*, 1l, oceanbase::common::ObWrapperAllocatorfalse> >&, oceanbase::common::ObObj&) at ./build_rpm/src/pl/./src/pl/sys_package/ob_dbms_lob.cpp:719oceanbase::pl::ObDbmsLob::write(oceanbase::sql::ObExecContext&, oceanbase::common::Ob2DArray<oceanbase::common::ObObjParam2096128, oceanbase::common::ObWrapperAllocatorfalse, oceanbase::common::ObSEArray<oceanbase::common::ObObjParam*, 1l, oceanbase::common::ObWrapperAllocatorfalse> >&, oceanbase::common::ObObj&) at ./build_rpm/src/pl/./src/pl/sys_package/ob_dbms_lob.cpp:783oceanbase::pl::ObDbmsLob::writeappend(oceanbase::sql::ObExecContext&, oceanbase::common::Ob2DArray<oceanbase::common::ObObjParam2096128, oceanbase::common::ObWrapperAllocatorfalse, oceanbase::common::ObSEArray<oceanbase::common::ObObjParam*, 1l, oceanbase::common::ObWrapperAllocatorfalse> >&, oceanbase::common::ObObj&) at ./build_rpm/src/pl/./src/pl/sys_package/ob_dbms_lob.cpp:1079oceanbase::sql::ObSPIService::spi_interface_impl(oceanbase::pl::ObPLExecCtx*, long) at ./build_rpm/src/sql/./src/sql/ob_spi.cpp:5395?? ??:0oceanbase::pl::ObPLExecState::execute() at ??:?oceanbase::pl::ObPL::execute(oceanbase::sql::ObExecContext&, oceanbase::common::ObIAllocator&, oceanbase::pl::ObPLPackageGuard&, oceanbase::pl::ObPLFunction&, oceanbase::common::Ob2DArray<oceanbase::common::ObObjParam2096128, oceanbase::common::ObWrapperAllocatorfalse, oceanbase::common::ObSEArray<oceanbase::common::ObObjParam*, 1l, oceanbase::common::ObWrapperAllocatorfalse> >*, oceanbase::common::ObIArray<long> const*, oceanbase::common::ObObj*, int*, bool, bool, bool, bool, unsigned long, bool) at ./build_rpm/src/pl/./src/pl/ob_pl.cpp:1321oceanbase::pl::ObPL::execute(oceanbase::sql::ObExecContext&, oceanbase::common::ObIAllocator&, unsigned long, unsigned long, oceanbase::common::ObIArray<long> const&, oceanbase::common::Ob2DArray<oceanbase::common::ObObjParam2096128, oceanbase::common::ObWrapperAllocatorfalse, oceanbase::common::ObSEArray<oceanbase::common::ObObjParam*, 1l, oceanbase::common::ObWrapperAllocatorfalse> >&, oceanbase::common::ObIArray<long> const&, oceanbase::common::ObObj&, int*, bool, bool, unsigned long, bool, bool) at ./build_rpm/src/pl/./src/pl/ob_pl.cpp:1607oceanbase::pl::ObPL::execute_proc(oceanbase::pl::ObPLExecCtx&, unsigned long, unsigned long, long*, long, unsigned long, long, oceanbase::common::ObObjParam**, long*) at ./build_rpm/src/pl/./src/pl/ob_pl.cpp:295?? ??:0oceanbase::pl::ObPLExecState::execute() at ??:?oceanbase::pl::ObPL::execute(oceanbase::sql::ObExecContext&, oceanbase::common::ObIAllocator&, oceanbase::pl::ObPLPackageGuard&, oceanbase::pl::ObPLFunction&, oceanbase::common::Ob2DArray<oceanbase::common::ObObjParam2096128, oceanbase::common::ObWrapperAllocatorfalse, oceanbase::common::ObSEArray<oceanbase::common::ObObjParam*, 1l, oceanbase::common::ObWrapperAllocatorfalse> >*, oceanbase::common::ObIArray<long> const*, oceanbase::common::ObObj*, int*, bool, bool, bool, bool, unsigned long, bool) at ./build_rpm/src/pl/./src/pl/ob_pl.cpp:1321oceanbase::pl::ObPL::execute(oceanbase::sql::ObExecContext&, _ParseNode const*) at ./build_rpm/src/pl/./src/pl/ob_pl.cpp:1415oceanbase::sql::ObAnonymousBlockExecutor::execute(oceanbase::sql::ObExecContext&, oceanbase::sql::ObAnonymousBlockStmt&) at ./build_rpm/src/sql/./src/sql/engine/cmd/ob_routine_executor.cpp:516oceanbase::sql::ObCmdExecutor::execute(oceanbase::sql::ObExecContext&, oceanbase::sql::ObICmd&) at ??:?oceanbase::sql::ObResultSet::open_cmd() at ./build_rpm/src/sql/./src/sql/ob_result_set.cpp:94oceanbase::sql::ObResultSet::execute() at ??:?oceanbase::sql::ObResultSet::sync_open() at ./build_rpm/src/sql/./src/sql/ob_result_set.cpp:153oceanbase::observer::ObSyncCmdDriver::response_result(oceanbase::observer::ObMySQLResultSet&) at ./build_rpm/src/observer/./src/observer/mysql/ob_sync_cmd_driver.cpp:107oceanbase::observer::ObMPQuery::response_result(oceanbase::sql::ObQueryExecCtx&, bool, bool&) at ./build_rpm/src/observer/./src/observer/mysql/obmp_query.cpp:1319oceanbase::observer::ObMPQuery::process() at ./build_rpm/src/observer/./src/observer/mysql/obmp_query.cpp:315oceanbase::rpc::frame::ObSqlProcessor::run() at ./build_rpm/deps/oblib/src/rpc/./deps/oblib/src/rpc/frame/ob_sql_processor.cpp:50oceanbase::omt::ObWorkerProcessor::process_one(oceanbase::rpc::ObRequest&) at ./build_rpm/src/observer/./src/observer/omt/ob_worker_processor.cpp:76oceanbase::omt::ObWorkerProcessor::process(oceanbase::rpc::ObRequest&) at ./build_rpm/src/observer/./src/observer/omt/ob_worker_processor.cpp:147oceanbase::omt::ObThWorker::process_request(oceanbase::rpc::ObRequest&) at ./build_rpm/src/observer/./src/observer/omt/ob_th_worker.cpp:311oceanbase::omt::ObThWorker::worker(long&, long&, int&) at ./build_rpm/src/observer/./src/observer/omt/ob_th_worker.cpp:476non-virtual thunk to oceanbase::omt::ObThWorker::run(long) at ??:?operator() at ./build_rpm/deps/oblib/src/lib/./deps/oblib/src/lib/coro/co_user_thread.cpp:234eeentry(boost::context::detail::transfer_t) at ./build_rpm/deps/oblib/src/lib/./deps/oblib/src/lib/coro/co_user_thread.cpp:44?? at /home/jenkins/agent/workspace/rpm-oceanbase-3.2.4.5-1.1.18/ob_source_code_dir/deps/oblib/src/lib/coro/context/asm/make_x86_64_sysv_elf_gas.S:75

7、关闭 mem_leak check

登录sys租户obclient [oceanbase]> alter system set leak_mod_to_check='';Query OK, 0 rows affected (0.058 sec)
内存相关参数
参数
用途
默认值
取值范围
是否重启 OBServer 生效
memory_limit
表示可用的总内存大小
0
[0M, +∞)
memory_limit_percentage
用于设置系统总可用内存大小占总内存大小的百分比
80
[10, 90]
system_memory
用于设置系统预留给租户 ID 为 500 的租户的内存容量
30G
[0M, +∞)

memory_limit 的默认值为 0。如果该值不为 0,则系统会忽略 memory_limit_percentage 的设置而优先使用 memory_limit 配置的值。例如,一台物理机的内存为 100 GB,memory_limit_percentage 设置为 80,表示使用 80% 的内存,而 memory_limit 参数设置为 '90G',则实际物理机上 OceanBase 数据库可分配的内存使用 memory_limit 的配置,即 90 GB。

使用注意事项:

  • memory_limit 的默认单位为 MB。例如,memory_limit='40G' 表示设置 OceanBase 数据库进程的使用内存上限是 40 GB。由于默认单位为 MB,则 memory_limit=40960 与 memory_limit='40G' 设置的值相同。
  • memory_limit 的值目前无上限。如果设置的内存最大上限超过了实际的物理内存总和,则会导致系统中其他按总内存计算的值偏大。
  • 如果希望限制运行中的 OceanBase 数据库的内存大小,可以直接修改 memory_limit 的值,使其达到预期。设置后,后台参数 Reload 线程会使其动态生效,无需重启。但是在设置时,需要保证 memory_limit 的值小于系统总的值。

注意

memory_limit 的值必须大于 OBServer 实际已使用的内存。

查询当前已使用的内存数(单位:GB)的方法如下:

obclient> SELECT value/1024/1024/1024 used_gb FROM v$sysstat WHERE name LIKE '%observer memory%' AND con_id = 1 AND stat_id=140008 AND name='observer memory used size';
参数
用途
默认值
取值范围
是否重启 OBServer 生效
memstore_limit_percentage
用于设置租户使用 MemStore 的内存占其总可用内存的百分比
50
[1, 99]
freeze_trigger_percentage
用于设置租户触发冻结内存的使用阈值
70
[1, 99]
ob_sql_work_area_percentage
用于设置 SQL 工作区内存占整个租户内存百分比
5
[0, 100]

工作区内存,是指 SQL 排序等阻塞性算子使用的内存,通过租户系统变量 ob_sql_work_area_percentage 控制,默认值为 5%,即 工作区内存 = 租户内存 * ob_sql_work_area_percentage(默认 5%)

如果请求并发量较大,且每个请求占用的工作区内存比较多,可能出现工作区内存不足的报错,经常出现的场景有 unionsortgroup by 等。上述问题如果出现,可以通过适当调大系统变量来规避,例如:

obclient> SET GLOBAL ob_sql_work_area_percentage = 10;
范计杰
云和恩墨高级技术顾问
从事Oracle数据库技术服务10余年,近3年开始转型国产、开源数据库运维(OCEANBASE、PostgreSQL等),先后管理维护金融、能源、运营商以及政企事业单位等客户的核心数据库,擅长数据库故障诊断、性能调优、异常恢复、运维自动化、高级技术咨询等。

想了解更多干货,可通过下方扫码关注

可扫码添加上智启元官方客服微信👇

未经允许不得转载:17认证网 » 技术时刻丨OceanBase内存问题排查思路与方法
分享到:0

评论已关闭。

400-663-6632
咨询老师
咨询老师
咨询老师