Home Explore Blog CI



postgresql

9th chunk of `doc/src/sgml/system-views.sgml`
3282de51703e268c25fb3de44be1fb78762213aa7d63c6cc0000000100000fa0
 <type>text</type>
      </para>
      <para>
       Type of the memory context
      </para></entry>
     </row>

     <row>
      <entry role="catalog_table_entry"><para role="column_definition">
       <structfield>level</structfield> <type>int4</type>
      </para>
      <para>
       The 1-based level of the context in the memory context hierarchy. The
       level of a context also shows the position of that context in the
       <structfield>path</structfield> column.
      </para></entry>
     </row>

     <row>
      <entry role="catalog_table_entry"><para role="column_definition">
       <structfield>path</structfield> <type>int4[]</type>
      </para>
      <para>
       Array of transient numerical identifiers to describe the memory
       context hierarchy. The first element is for
       <literal>TopMemoryContext</literal>, subsequent elements contain
       intermediate parents and the final element contains the identifier for
       the current context.
      </para></entry>
     </row>

     <row>
      <entry role="catalog_table_entry"><para role="column_definition">
       <structfield>total_bytes</structfield> <type>int8</type>
      </para>
      <para>
       Total bytes allocated for this memory context
      </para></entry>
     </row>

     <row>
      <entry role="catalog_table_entry"><para role="column_definition">
       <structfield>total_nblocks</structfield> <type>int8</type>
      </para>
      <para>
       Total number of blocks allocated for this memory context
      </para></entry>
     </row>

     <row>
      <entry role="catalog_table_entry"><para role="column_definition">
       <structfield>free_bytes</structfield> <type>int8</type>
      </para>
      <para>
       Free space in bytes
      </para></entry>
     </row>

     <row>
      <entry role="catalog_table_entry"><para role="column_definition">
       <structfield>free_chunks</structfield> <type>int8</type>
      </para>
      <para>
       Total number of free chunks
      </para></entry>
     </row>

     <row>
      <entry role="catalog_table_entry"><para role="column_definition">
       <structfield>used_bytes</structfield> <type>int8</type>
      </para>
      <para>
       Used space in bytes
      </para></entry>
     </row>
    </tbody>
   </tgroup>
  </table>

  <para>
   By default, the <structname>pg_backend_memory_contexts</structname> view can be
   read only by superusers or roles with the privileges of the
   <literal>pg_read_all_stats</literal> role.
  </para>

  <para>
   Since memory contexts are created and destroyed during the running of a
   query, the identifiers stored in the <structfield>path</structfield> column
   can be unstable between multiple invocations of the view in the same query.
   The example below demonstrates an effective usage of this column and
   calculates the total number of bytes used by
   <literal>CacheMemoryContext</literal> and all of its children:

<programlisting>
WITH memory_contexts AS (
    SELECT * FROM pg_backend_memory_contexts
)
SELECT sum(c1.total_bytes)
FROM memory_contexts c1, memory_contexts c2
WHERE c2.name = 'CacheMemoryContext'
AND c1.path[c2.level] = c2.path[c2.level];
</programlisting>

   The <link linkend="queries-with">Common Table Expression</link> is used
   to ensure the context IDs in the <structfield>path</structfield> column
   match between both evaluations of the view.
  </para>
 </sect1>

 <sect1 id="view-pg-config">
  <title><structname>pg_config</structname></title>

  <indexterm zone="view-pg-config">
   <primary>pg_config</primary>
  </indexterm>

  <para>
   The view <structname>pg_config</structname> describes the
   compile-time configuration parameters of the currently installed
   version of <productname>PostgreSQL</productname>. It is intended, for example, to
   be used by software packages that want to interface to
   <productname>PostgreSQL</productname> to facilitate finding the required header
   files and libraries. It provides the same

Title: pg_backend_memory_contexts View and pg_config View
Summary
The pg_backend_memory_contexts view provides detailed information about the memory contexts of the server process, including total bytes allocated, free space, and used space. The view can be read only by superusers or roles with the pg_read_all_stats role. An example is given to demonstrate how to calculate the total bytes used by a specific memory context and its children. The section also introduces the pg_config view, which describes the compile-time configuration parameters of the currently installed PostgreSQL version, intended for use by software packages interfacing with PostgreSQL.