更新时间:2023-04-23 GMT+08:00

PV_SESSION_MEMORY_DETAIL

PV_SESSION_MEMORY_DETAIL统计线程的内存使用情况,以MemoryContext节点来统计。

其中内存上下文“TempSmallContextGroup”,记录当前线程中所有内存上下文字段“totalsize”小于8192字节的信息汇总,并且内存上下文统计计数记录到“usedsize”字段中。所以在视图中,“TempSmallContextGroup”内存上下文中的“totalsize”和“freesize”是该线程中所有内存上下文“totalsize”小于8192字节的汇总总和,usedsize字段表示统计的内存上下文个数。

可通过"select * from pv_session_memctx_detail(threadid, '');"将某个线程所有内存上下文信息记录到“/tmp/dumpmem”目录下的“threadid_timestamp.log”文件中。其中threadid可通过下表sessid中获得。

表1 PV_SESSION_MEMORY_DETAIL字段

名称

类型

描述

sessid

text

线程启动时间+线程标识(字符串信息为timestamp.threadid)。

sesstype

text

线程名称。

contextname

text

内存上下文名称。

level

smallint

当前上下文在整体内存上下文中的层级。

parent

text

父内存上下文名称。

totalsize

bigint

当前内存上下文的内存总数,单位Byte。

freesize

bigint

当前内存上下文中已释放的内存总数,单位Byte。

usedsize

bigint

当前内存上下文中已使用的内存总数,单位Byte;“TempSmallContextGroup”内存上下文中该字段含义为统计计数。

应用示例

查询当前节点上所有MemoryContext的使用情况。

根据sessid定位到该MemoryContext是在哪个线程中创建和使用的,依据totalsize,freesize及usedsize来确认内存的使用情况是否符合预期,预先判断是否可能存在内存泄露的风险。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
SELECT * FROM PV_SESSION_MEMORY_DETAIL order by totalsize desc;
           sessid           |        sesstype         |                 contextname                 | level |            parent            | totalsize | freesize | usedsize
----------------------------+-------------------------+---------------------------------------------+-------+------------------------------+-----------+----------+----------
 0.139975915622720          | postmaster              | gs_signal                                   |     1 | TopMemoryContext             |  17209904 |  8081136 |  9128768
 1667462258.139973631031040 | postgres                | SRF multi-call context                      |     5 | FunctionScan_139973631031040 |   1725504 |     3168 |  1722336
 1667461280.139973666686720 | postgres                | CacheMemoryContext                          |     1 | TopMemoryContext             |   1472544 |   284456 |  1188088
 1667450443.139973877479168 | postgres                | CacheMemoryContext                          |     1 | TopMemoryContext             |   1472544 |   356088 |  1116456
 1667462258.139973631031040 | postgres                | CacheMemoryContext                          |     1 | TopMemoryContext             |   1472544 |   128216 |  1344328
 1667461250.139973915236096 | postgres                | CacheMemoryContext                          |     1 | TopMemoryContext             |   1472544 |   226352 |  1246192
 1667450439.139974010144512 | WLMarbiter              | CacheMemoryContext                          |     1 | TopMemoryContext             |   1472544 |   386736 |  1085808
 1667450439.139974151726848 | WDRSnapshot             | CacheMemoryContext                          |     1 | TopMemoryContext             |   1472544 |   159720 |  1312824
 1667450439.139974026925824 | WLMmonitor              | CacheMemoryContext                          |     1 | TopMemoryContext             |   1472544 |   297976 |  1174568
 1667451036.139973746386688 | postgres                | CacheMemoryContext                          |     1 | TopMemoryContext             |   1472544 |   208064 |  1264480
 1667461250.139973950891776 | postgres                | CacheMemoryContext                          |     1 | TopMemoryContext             |   1472544 |   270016 |  1202528
 1667450439.139974076212992 | WLMCalSpaceInfo         | CacheMemoryContext                          |     1 | TopMemoryContext             |   1472544 |   393952 |  1078592
 1667450439.139974092994304 | WLMCollectWorker        | CacheMemoryContext                          |     1 | TopMemoryContext             |   1472544 |    94848 |  1377696
 1667461254.139973971343104 | postgres                | CacheMemoryContext                          |     1 | TopMemoryContext             |   1472544 |   338544 |  1134000
 1667461280.139973822945024 | postgres                | CacheMemoryContext                          |     1 | TopMemoryContext             |   1472544 |   284456 |  1188088
 1667450439.139974202070784 | JobScheduler            | CacheMemoryContext                          |     1 | TopMemoryContext             |   1472544 |   216728 |  1255816
 1667450454.139973860697856 | postgres                | CacheMemoryContext                          |     1 | TopMemoryContext             |   1472544 |   388384 |  1084160
 0.139975915622720          | postmaster              | Postmaster                                  |     1 | TopMemoryContext             |   1004288 |    88792 |   915496
 1667450439.139974218852096 | AutoVacLauncher         | CacheMemoryContext                          |     1 | TopMemoryContext             |    948256 |   183488 |   764768
 1667461250.139973915236096 | postgres                | TempSmallContextGroup                       |     0 |                              |    584448 |   148032 |      119
 1667462258.139973631031040 | postgres                | TempSmallContextGroup                       |     0 |                              |    579712 |   162128 |      123