pg_log_backend_memory_contexts()
是一个系统函数,用于指示服务器记录具有指定 PID 的后端的内存上下文。
pg_log_backend_memory_contexts()
在 PostgreSQL 14 中添加。
用法
pg_log_backend_memory_contexts( pid
integer ) → boolean
执行后,指定后端的内存上下文将以 LOG
消息级别记录。
此函数只能由超级用户执行,或者(在 PostgreSQL 15 及更高版本中)授予对该函数执行权限的用户执行,例如使用
GRANT EXECUTE ON FUNCTION pg_log_backend_memory_contexts TO someuser
变更历史
- PostgreSQL 15
- 非超级用户可以被授予执行权限 (提交 f0b051e3)
- PostgreSQL 14
- 添加 (提交 43620e32)
示例
pg_log_backend_memory_contexts()
执行示例
postgres=# SELECT pg_log_backend_memory_contexts(11727); pg_log_backend_memory_contexts -------------------------------- t (1 row)
这里,选定的 PID 代表自动清理启动器。
PostgreSQL 日志文件中的相关输出
[2021-04-15 08:12:51 UTC] psql postgres postgres LOG: 00000: statement: SELECT pg_log_backend_memory_contexts(11727); ... [2021-04-15 08:13:30 UTC] LOG: 00000: logging memory contexts of PID 11727 [2021-04-15 08:13:30 UTC] LOG: 00000: level: 0; TopMemoryContext: 60528 total in 5 blocks; 16224 free (6 chunks); 44304 used [2021-04-15 08:13:30 UTC] LOG: 00000: level: 1; TopTransactionContext: 8192 total in 1 blocks; 6728 free (0 chunks); 1464 used [2021-04-15 08:13:30 UTC] LOG: 00000: level: 1; smgr relation table: 16384 total in 2 blocks; 4544 free (3 chunks); 11840 used [2021-04-15 08:13:30 UTC] LOG: 00000: level: 1; pgstat TabStatusArray lookup hash table: 8192 total in 1 blocks; 1408 free (0 chunks); 6784 used [2021-04-15 08:13:30 UTC] LOG: 00000: level: 1; TransactionAbortContext: 32768 total in 1 blocks; 32504 free (0 chunks); 264 used [2021-04-15 08:13:30 UTC] LOG: 00000: level: 1; Autovacuum Launcher: 8192 total in 1 blocks; 7928 free (1 chunks); 264 used [2021-04-15 08:13:30 UTC] LOG: 00000: level: 2; Start worker tmp cxt: 8192 total in 1 blocks; 7928 free (0 chunks); 264 used [2021-04-15 08:13:30 UTC] LOG: 00000: level: 2; AV dblist: 8192 total in 1 blocks; 7840 free (0 chunks); 352 used [2021-04-15 08:13:30 UTC] LOG: 00000: level: 1; Portal hash: 8192 total in 1 blocks; 512 free (0 chunks); 7680 used [2021-04-15 08:13:30 UTC] LOG: 00000: level: 1; TopPortalContext: 8192 total in 1 blocks; 7928 free (0 chunks); 264 used [2021-04-15 08:13:30 UTC] LOG: 00000: level: 1; Relcache by OID: 16384 total in 2 blocks; 7616 free (3 chunks); 8768 used [2021-04-15 08:13:30 UTC] LOG: 00000: level: 1; CacheMemoryContext: 262144 total in 6 blocks; 128408 free (3 chunks); 133736 used [2021-04-15 08:13:30 UTC] LOG: 00000: level: 1; WAL record construction: 49776 total in 2 blocks; 6344 free (0 chunks); 43432 used [2021-04-15 08:13:30 UTC] LOG: 00000: level: 1; PrivateRefCount: 8192 total in 1 blocks; 2584 free (0 chunks); 5608 used [2021-04-15 08:13:30 UTC] LOG: 00000: level: 1; MdSmgr: 8192 total in 1 blocks; 7896 free (0 chunks); 296 used [2021-04-15 08:13:30 UTC] LOG: 00000: level: 1; LOCALLOCK hash: 8192 total in 1 blocks; 512 free (0 chunks); 7680 used [2021-04-15 08:13:30 UTC] LOG: 00000: level: 1; Timezones: 104128 total in 2 blocks; 2584 free (0 chunks); 101544 used [2021-04-15 08:13:30 UTC] LOG: 00000: level: 1; Postmaster: 8192 total in 1 blocks; 7600 free (6 chunks); 592 used [2021-04-15 08:13:30 UTC] LOG: 00000: level: 2; ident parser context: 1024 total in 1 blocks; 760 free (0 chunks); 264 used [2021-04-15 08:13:30 UTC] LOG: 00000: level: 2; hba parser context: 17408 total in 5 blocks; 4840 free (6 chunks); 12568 used [2021-04-15 08:13:30 UTC] LOG: 00000: level: 1; ErrorContext: 8192 total in 1 blocks; 7928 free (4 chunks); 264 used [2021-04-15 08:13:30 UTC] LOG: 00000: Grand total: 658848 bytes in 38 blocks; 270616 free (32 chunks); 388232 used
使用无效 PID 执行
postgres=# SELECT pg_log_backend_memory_contexts(12345); WARNING: PID 12345 is not a PostgreSQL server process pg_log_backend_memory_contexts -------------------------------- f (1 row)
参考文献
- PostgreSQL 14 文档: 服务器信号函数