pg_backend_memory_contexts

A system catalogue view displaying the memory context usage of the server process attached to the current session
This entry relates to a PostgreSQL feature which is part of PostgreSQL 14, due to be released in late 2021.

pg_backend_memory_contexts is a system catalogue view displaying the memory context usage of the server process attached to the current session. This provides an accessible method for examining memory usage in individual backends without needing to attatch a debugger.

pg_backend_memory_contexts was added in PostgreSQL 14 .

Definition by PostgreSQL version

pg_backend_memory_contexts (PostgreSQL 14)

       View "pg_catalog.pg_backend_memory_contexts"
    Column     |  Type   | Collation | Nullable | Default
---------------+---------+-----------+----------+---------
 name          | text    |           |          |
 ident         | text    |           |          |
 parent        | text    |           |          |
 level         | integer |           |          |
 total_bytes   | bigint  |           |          |
 total_nblocks | bigint  |           |          |
 free_bytes    | bigint  |           |          |
 free_chunks   | bigint  |           |          |
 used_bytes    | bigint  |           |          |
    

Documentation: pg_backend_memory_contexts

Change history

 

Examples

postgres=# SELECT name, parent, level, total_bytes, total_nblocks, free_bytes, free_chunks, used_bytes
  FROM pg_backend_memory_contexts WHERE name != 'index info';
           name           |       parent       | level | total_bytes | total_nblocks | free_bytes | free_chunks | used_bytes 
--------------------------+--------------------+-------+-------------+---------------+------------+-------------+------------
 TopMemoryContext         |                    |     0 |       68720 |             5 |      14976 |          12 |      53744
 TopTransactionContext    | TopMemoryContext   |     1 |        8192 |             1 |       7720 |           0 |        472
 Operator lookup cache    | TopMemoryContext   |     1 |       24576 |             2 |      10712 |           4 |      13864
 Record information cache | TopMemoryContext   |     1 |        8192 |             1 |       1536 |           0 |       6656
 RowDescriptionContext    | TopMemoryContext   |     1 |        8192 |             1 |       6880 |           0 |       1312
 MessageContext           | TopMemoryContext   |     1 |       65536 |             4 |      24144 |           0 |      41392
 Operator class cache     | TopMemoryContext   |     1 |        8192 |             1 |        512 |           0 |       7680
 smgr relation table      | TopMemoryContext   |     1 |       16384 |             2 |       4544 |           3 |      11840
 TransactionAbortContext  | TopMemoryContext   |     1 |       32768 |             1 |      32504 |           0 |        264
 Portal hash              | TopMemoryContext   |     1 |        8192 |             1 |        512 |           0 |       7680
 TopPortalContext         | TopMemoryContext   |     1 |        8192 |             1 |       7648 |           0 |        544
 PortalContext            | TopPortalContext   |     2 |        1024 |             1 |        568 |           0 |        456
 ExecutorState            | PortalContext      |     3 |       49216 |             4 |      13040 |           3 |      36176
 printtup                 | ExecutorState      |     4 |        8192 |             1 |       7928 |           0 |        264
 Table function arguments | ExecutorState      |     4 |        8192 |             1 |       7872 |           0 |        320
 ExprContext              | ExecutorState      |     4 |        8192 |             1 |       3336 |           0 |       4856
 Relcache by OID          | TopMemoryContext   |     1 |       16384 |             2 |       3424 |           3 |      12960
 CacheMemoryContext       | TopMemoryContext   |     1 |      524288 |             7 |     104416 |           0 |     419872
 relation rules           | CacheMemoryContext |     2 |        8192 |             4 |        464 |           0 |       7728
 WAL record construction  | TopMemoryContext   |     1 |       49776 |             2 |       6344 |           0 |      43432
 PrivateRefCount          | TopMemoryContext   |     1 |        8192 |             1 |       2584 |           0 |       5608
 MdSmgr                   | TopMemoryContext   |     1 |        8192 |             1 |       7864 |           0 |        328
 LOCALLOCK hash           | TopMemoryContext   |     1 |        8192 |             1 |        512 |           0 |       7680
 Timezones                | TopMemoryContext   |     1 |      104128 |             2 |       2584 |           0 |     101544
 ErrorContext             | TopMemoryContext   |     1 |        8192 |             1 |       7928 |           5 |        264
(25 rows)

Categories

Memory, PostgreSQL internals, System catalogue