pg_backend_memory_contexts
是一个 系统目录 视图,显示附加到当前会话的服务器进程的内存上下文使用情况。这提供了一种可访问的方法来检查各个后端中的内存使用情况,而无需附加调试器。
pg_backend_memory_contexts
在 PostgreSQL 14 中添加。
按 PostgreSQL 版本定义
pg_backend_memory_contexts (PostgreSQL 18)
View "pg_catalog.pg_backend_memory_contexts" Column | Type | Collation | Nullable | Default ---------------+-----------+-----------+----------+--------- name | text | | | ident | text | | | type | text | | | level | integer | | | path | integer[] | | | total_bytes | bigint | | | total_nblocks | bigint | | | free_bytes | bigint | | | free_chunks | bigint | | | used_bytes | bigint | | |
pg_backend_memory_contexts (PostgreSQL 17)
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 | | |
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 | | |
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 | | |
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 | | |
更改历史
- PostgreSQL 18
- PostgreSQL 15
- 可被
pg_read_all_stats
成员访问 (提交 77ea4f94)
- 可被
- PostgreSQL 14
- 添加 (提交 3e98c0ba);讨论主题:创建用于公开后端进程内存使用情况的函数
示例
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)
参考
- PostgreSQL 文档: pg_backend_memory_contexts
有用链接
- pg_backend_memory_contexts - 2023 年 2 月 Taraka Vuyyuru / OpenSource DB 博客文章