]> begriffs open source - ai-pg/blob - full-docs/txt/view-pg-backend-memory-contexts.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / view-pg-backend-memory-contexts.txt
1
2 53.5. pg_backend_memory_contexts #
3
4    The view pg_backend_memory_contexts displays all the memory contexts of
5    the server process attached to the current session.
6
7    pg_backend_memory_contexts contains one row for each memory context.
8
9    Table 53.5. pg_backend_memory_contexts Columns
10
11    Column Type
12
13    Description
14
15    name text
16
17    Name of the memory context
18
19    ident text
20
21    Identification information of the memory context. This field is
22    truncated at 1024 bytes
23
24    type text
25
26    Type of the memory context
27
28    level int4
29
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
32    column.
33
34    path int4[]
35
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.
40
41    total_bytes int8
42
43    Total bytes allocated for this memory context
44
45    total_nblocks int8
46
47    Total number of blocks allocated for this memory context
48
49    free_bytes int8
50
51    Free space in bytes
52
53    free_chunks int8
54
55    Total number of free chunks
56
57    used_bytes int8
58
59    Used space in bytes
60
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.
63
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
69    children:
70 WITH memory_contexts AS (
71     SELECT * FROM pg_backend_memory_contexts
72 )
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];
77
78    The Common Table Expression is used to ensure the context IDs in the
79    path column match between both evaluations of the view.