2 53.5. pg_backend_memory_contexts #
4 The view pg_backend_memory_contexts displays all the memory contexts of
5 the server process attached to the current session.
7 pg_backend_memory_contexts contains one row for each memory context.
9 Table 53.5. pg_backend_memory_contexts Columns
17 Name of the memory context
21 Identification information of the memory context. This field is
22 truncated at 1024 bytes
26 Type of the memory context
30 The 1-based level of the context in the memory context hierarchy. The
31 level of a context also shows the position of that context in the path
36 Array of transient numerical identifiers to describe the memory context
37 hierarchy. The first element is for TopMemoryContext, subsequent
38 elements contain intermediate parents and the final element contains
39 the identifier for the current context.
43 Total bytes allocated for this memory context
47 Total number of blocks allocated for this memory context
55 Total number of free chunks
61 By default, the pg_backend_memory_contexts view can be read only by
62 superusers or roles with the privileges of the pg_read_all_stats role.
64 Since memory contexts are created and destroyed during the running of a
65 query, the identifiers stored in the path column can be unstable
66 between multiple invocations of the view in the same query. The example
67 below demonstrates an effective usage of this column and calculates the
68 total number of bytes used by CacheMemoryContext and all of its
70 WITH memory_contexts AS (
71 SELECT * FROM pg_backend_memory_contexts
73 SELECT sum(c1.total_bytes)
74 FROM memory_contexts c1, memory_contexts c2
75 WHERE c2.name = 'CacheMemoryContext'
76 AND c1.path[c2.level] = c2.path[c2.level];
78 The Common Table Expression is used to ensure the context IDs in the
79 path column match between both evaluations of the view.