]> begriffs open source - ai-pg/blob - full-docs/html/view-pg-backend-memory-contexts.html
Include links to all subsection html pages, with shorter paths too
[ai-pg] / full-docs / html / view-pg-backend-memory-contexts.html
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>53.5. pg_backend_memory_contexts</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="view-pg-available-extension-versions.html" title="53.4. pg_available_extension_versions" /><link rel="next" href="view-pg-config.html" title="53.6. pg_config" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">53.5. <code class="structname">pg_backend_memory_contexts</code></th></tr><tr><td width="10%" align="left"><a accesskey="p" href="view-pg-available-extension-versions.html" title="53.4. pg_available_extension_versions">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="views.html" title="Chapter 53. System Views">Up</a></td><th width="60%" align="center">Chapter 53. System Views</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="view-pg-config.html" title="53.6. pg_config">Next</a></td></tr></table><hr /></div><div class="sect1" id="VIEW-PG-BACKEND-MEMORY-CONTEXTS"><div class="titlepage"><div><div><h2 class="title" style="clear: both">53.5. <code class="structname">pg_backend_memory_contexts</code> <a href="#VIEW-PG-BACKEND-MEMORY-CONTEXTS" class="id_link">#</a></h2></div></div></div><a id="id-1.10.5.9.2" class="indexterm"></a><p>
3    The view <code class="structname">pg_backend_memory_contexts</code> displays all
4    the memory contexts of the server process attached to the current session.
5   </p><p>
6    <code class="structname">pg_backend_memory_contexts</code> contains one row
7    for each memory context.
8   </p><div class="table" id="id-1.10.5.9.5"><p class="title"><strong>Table 53.5. <code class="structname">pg_backend_memory_contexts</code> Columns</strong></p><div class="table-contents"><table class="table" summary="pg_backend_memory_contexts Columns" border="1"><colgroup><col /></colgroup><thead><tr><th class="catalog_table_entry"><p class="column_definition">
9        Column Type
10       </p>
11       <p>
12        Description
13       </p></th></tr></thead><tbody><tr><td class="catalog_table_entry"><p class="column_definition">
14        <code class="structfield">name</code> <code class="type">text</code>
15       </p>
16       <p>
17        Name of the memory context
18       </p></td></tr><tr><td class="catalog_table_entry"><p class="column_definition">
19        <code class="structfield">ident</code> <code class="type">text</code>
20       </p>
21       <p>
22        Identification information of the memory context. This field is truncated at 1024 bytes
23       </p></td></tr><tr><td class="catalog_table_entry"><p class="column_definition">
24        <code class="structfield">type</code> <code class="type">text</code>
25       </p>
26       <p>
27        Type of the memory context
28       </p></td></tr><tr><td class="catalog_table_entry"><p class="column_definition">
29        <code class="structfield">level</code> <code class="type">int4</code>
30       </p>
31       <p>
32        The 1-based level of the context in the memory context hierarchy. The
33        level of a context also shows the position of that context in the
34        <code class="structfield">path</code> column.
35       </p></td></tr><tr><td class="catalog_table_entry"><p class="column_definition">
36        <code class="structfield">path</code> <code class="type">int4[]</code>
37       </p>
38       <p>
39        Array of transient numerical identifiers to describe the memory
40        context hierarchy. The first element is for
41        <code class="literal">TopMemoryContext</code>, subsequent elements contain
42        intermediate parents and the final element contains the identifier for
43        the current context.
44       </p></td></tr><tr><td class="catalog_table_entry"><p class="column_definition">
45        <code class="structfield">total_bytes</code> <code class="type">int8</code>
46       </p>
47       <p>
48        Total bytes allocated for this memory context
49       </p></td></tr><tr><td class="catalog_table_entry"><p class="column_definition">
50        <code class="structfield">total_nblocks</code> <code class="type">int8</code>
51       </p>
52       <p>
53        Total number of blocks allocated for this memory context
54       </p></td></tr><tr><td class="catalog_table_entry"><p class="column_definition">
55        <code class="structfield">free_bytes</code> <code class="type">int8</code>
56       </p>
57       <p>
58        Free space in bytes
59       </p></td></tr><tr><td class="catalog_table_entry"><p class="column_definition">
60        <code class="structfield">free_chunks</code> <code class="type">int8</code>
61       </p>
62       <p>
63        Total number of free chunks
64       </p></td></tr><tr><td class="catalog_table_entry"><p class="column_definition">
65        <code class="structfield">used_bytes</code> <code class="type">int8</code>
66       </p>
67       <p>
68        Used space in bytes
69       </p></td></tr></tbody></table></div></div><br class="table-break" /><p>
70    By default, the <code class="structname">pg_backend_memory_contexts</code> view can be
71    read only by superusers or roles with the privileges of the
72    <code class="literal">pg_read_all_stats</code> role.
73   </p><p>
74    Since memory contexts are created and destroyed during the running of a
75    query, the identifiers stored in the <code class="structfield">path</code> column
76    can be unstable between multiple invocations of the view in the same query.
77    The example below demonstrates an effective usage of this column and
78    calculates the total number of bytes used by
79    <code class="literal">CacheMemoryContext</code> and all of its children:
80
81 </p><pre class="programlisting">
82 WITH memory_contexts AS (
83     SELECT * FROM pg_backend_memory_contexts
84 )
85 SELECT sum(c1.total_bytes)
86 FROM memory_contexts c1, memory_contexts c2
87 WHERE c2.name = 'CacheMemoryContext'
88 AND c1.path[c2.level] = c2.path[c2.level];
89 </pre><p>
90
91    The <a class="link" href="queries-with.html" title="7.8. WITH Queries (Common Table Expressions)">Common Table Expression</a> is used
92    to ensure the context IDs in the <code class="structfield">path</code> column
93    match between both evaluations of the view.
94   </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="view-pg-available-extension-versions.html" title="53.4. pg_available_extension_versions">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="views.html" title="Chapter 53. System Views">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="view-pg-config.html" title="53.6. pg_config">Next</a></td></tr><tr><td width="40%" align="left" valign="top">53.4. <code class="structname">pg_available_extension_versions</code> </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 53.6. <code class="structname">pg_config</code></td></tr></table></div></body></html>