内存泄漏
虚谷数据库设计有多种类型内存,主要包括线程工作内存、连接内存和其他共享内存(事务、消息、元信息等)。
可通过查询相关系统表获取内存使用信息。
进程内存分析
- 查看操作系统内存情况(总大小、空闲大小)。
- 查看数据库当前内存大小,同时观察内存使用变化情况。
- 查看xugu.ini配置确认数据库内存配置情况,预估正常内存值。
- 通过监控工具,查看内存和CPU历史变化情况。
查看数据缓存和SGA(排序、连接操作等使用)
select * from sys_mem_status;
select * from sys_all_mem_status;
线程工作内存分析
刷新工作线程内存,观察是否有内存持续增长线程。
select mem_size,* from sys_thd_status order by mem_size desc limit 10;--查看内存使用大的线程;
不存在持续内核增长线程和大内存消耗线程,则进行其他分析。
连接内存分析
刷新连接内存,观察是否有内存持续增长连接。
select mem_size,* from sys_sessions order by mem_size desc limit 10;--查看内存使用多的连接;
系统公共内存分析
刷新内存监控数据,观察是否存在内存持续增加。
select *,(targ_value::bigint/1024/1024)||'M' from sys_monitors where targ_name like '%mem%' order by targ_value::bigint desc ;--各类内存监控项;
--等价于上面sql,格式化输出内存大小(可把格式化封装为 size_format 函数后使用)
select *,
case
when targ_value::bigint>1024*1024*1024 then (targ_value::bigint/1024/1024/1024)||'G'
when targ_value::bigint>1024*1024 then (targ_value::bigint/1024/1024)||'M'
when targ_value::bigint>1024 then (targ_value::bigint/1024)||'K'
else targ_value end MSIZE
from sys_monitors where targ_name like '%mem%'
order by targ_value::bigint desc ;--各类内存监控项;
SQL内存开销
--查看线程工作内存高的SQL
select t1.*,t2.sql from sys_thd_status t1 left join sys_thd_session t2
on t1.nodeid=t2.nodeid and t1.id=t2.thd_id
where t1.mem_size>1024*1024 --内存大于1M
order by t1.mem_size limit 10;
--查看连接内高的SQL
select t1.mem_size,* from sys_sessions t1 left join sys_thd_session t2 using (nodeid,session_id)
where t1.mem_size>1024*1024 and mod(t1.status,10)=4--仅限活动连接且内存大于1M
order by mem_size desc limit 10;