pg_backend_memory_contexts
A view displaying the memory context usage of the server process attached to the current session
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 16)
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
pg_backend_memory_contexts (PostgreSQL 15)
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
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
- PostgreSQL 15
- can be accessed by members of
pg_read_all_stats
(commit 77ea4f94)
- can be accessed by members of
- PostgreSQL 14
- added (commit 3e98c0ba); discussion thread: Creating a function for exposing memory usage of backend process
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)
References
- PostgreSQL 14 documentation: pg_backend_memory_contexts