PostgreSQLLa base de données la plus sophistiquée au monde.
Documentation PostgreSQL 18 beta 1 » Internes » Vues système » pg_backend_memory_contexts

53.5. pg_backend_memory_contexts #

La vue pg_backend_memory_contexts affiche tous les contextes mémoire du processus serveur attaché à la session en cours.

pg_backend_memory_contexts contient une ligne pour chaque contexte mémoire.

Tableau 53.5. Colonnes de pg_backend_memory_contexts

Type de colonne

Description

name text

Nom du contexte mémoire

ident text

Information d'identification du contexte mémoire. Ce champ est tronqué à 1024 octets

type text

Type du contexte mémoire

level int4

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 path column.

path int4[]

Array of transient numerical identifiers to describe the memory context hierarchy. The first element is for TopMemoryContext, subsequent elements contain intermediate parents and the final element contains the identifier for the current context.

total_bytes int8

Nombre total d'octets alloués pour ce contexte mémoire

total_nblocks int8

Nombre total de blocs alloué pour ce contexte mémoire

free_bytes int8

Espace libre en octets

free_chunks int8

Nombre total de morceaux libres

used_bytes int8

Espace utilisé en octets


Par défaut, la vue pg_backend_memory_contexts peut seulement être lue par les superutilisateurs ou par les rôles qui ont les droits du rôle pg_read_all_stats.

Since memory contexts are created and destroyed during the running of a query, the identifiers stored in the path 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 CacheMemoryContext and all of its children:

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];

The Common Table Expression is used to ensure the context IDs in the path column match between both evaluations of the view.