首页 > 数据库 > > 资源监控-内存资源监控
GaussDB 200提供了监控当前CN实例内存使用状态的视图及监控整个集群内存使用状态的视图:
gsql -d postgres -p 25308postgres为需要连接的数据库名称,25308为CN的端口号。
连接成功后,系统显示类似如下信息:
gsql ((GaussDB Kernel V300R002C00 build 50dc16a6) compiled at 2019-01-29 05:49:21 commit 1071 last mr 1373)
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
postgres=#
SELECT * FROM pg_total_memory_detail;
SELECT * FROM pgxc_total_memory_detail;如果查询该视图时出现以下错误,请参考内存资源管理开启内存管理功能。
SELECT * FROM pgxc_total_memory_detail;
ERROR: unsupported view for memory protection feature is disabled.
CONTEXT: PL/pgSQL function pgxc_total_memory_detail() line 12 at FOR over EXECUTE statement
用户可以通过视图pg_shared_memory_detail查询共享内存上下文信息:
SELECT * FROM pg_shared_memory_detail;
contextname | level | parent | totalsize | freesize | usedsize
---------------------------------+-------+---------------------------------+-----------+----------+----------
ProcessMemory | | | 24576 | 9840 | 14736
Workload manager memory context | 1 | ProcessMemory | 2105400 | 7304 | 2098096
wlm collector hash table | 2 | Workload manager memory context | 8192 | 3736 | 4456
Resource pool hash table | 2 | Workload manager memory context | 24576 | 15968 | 8608
wlm cgroup hash table | 2 | Workload manager memory context | 24576 | 15968 | 8608
(5 rows)
该视图列举了内存使用的上下文名称、级别、上级内存上下文、共享内存总大小等。
另外,在数据库中,GUC参数“memory_tracking_mode”用来设置内存信息统计的模式,共支持四种模式:
当为executor模式时,将在DN进程的pg_log目录下生成cvs格式文件,命名方式为:memory_track_<DN名称>_query_<queryid>.csv。作业执行时,执行器postgres线程和所有stream线程执行的算子信息,都将输入该文件。
文件内容根据以下面内容组成实例如下:
0, 0, ExecutorState, 0, PortalHeapMemory, 0, 40K, 602K, 23
1, 3, CStoreScan_29360131_25, 0, ExecutorState, 1, 265K, 554K, 23
2, 128, cstore scan per scan memory context, 1, CStoreScan_29360131_25, 2, 24K, 24K, 23
3, 127, cstore scan memory context, 1, CStoreScan_29360131_25, 2, 264K, 264K, 23
4, 7, InitPartitionMapTmpMemoryContext, 1, CStoreScan_29360131_25, 2, 31K, 31K, 23
5, 2, VecPartIterator_29360131_24, 0, ExecutorState, 1, 16K, 16K, 23
0, 0, ExecutorState, 0, PortalHeapMemory, 0, 24K, 1163K, 20
1, 3, CStoreScan_29360131_22, 0, ExecutorState, 1, 390K, 1122K, 20
2, 20, cstore scan per scan memory context, 1, CStoreScan_29360131_22, 2, 476K, 476K, 20
3, 19, cstore scan memory context, 1, CStoreScan_29360131_22, 2, 264K, 264K, 20
4, 7, InitPartitionMapTmpMemoryContext, 1, CStoreScan_29360131_22, 2, 23K, 23K, 20
5, 2, VecPartIterator_29360131_21, 0, ExecutorState, 1, 16K, 16K, 20
其中各字段分别为:输出顺序号、线程内分配内存上下文的顺序号、当前内存上下文的名称、父内存上下文的输出顺序号、父内存上下文的名称、内存上下文树形层次级别号、当前内存上下文使用的内存峰值、当前内存上下文及其所有子内存上下文使用的内存峰值、当前线程所在query的plannodeid。
在本例中,记录“1, 3, CStoreScan_29360131_22, 0, ExecutorState, 1, 390K, 1122K, 20”和Explain Analyze的对应关系如下:
当设置为fullexec模式时,输出信息和executor模式相同,但可能增加部分内存上下文分配信息,因为所有申请内存(无论是否申请成功)相关的信息都会被打印出来。由于仅记录内存申请信息,故记录中内存上下文使用的峰值均为0。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69959250/viewspace-3133658/ ,如需转载,请注明出处,否则将追究法律责任。