Contents
pg_log_backend_memory_contexts()
A function for logging the memory contexts of the specified backed
pg_log_backend_memory_contexts()
is a system function for instructing the server to log the memory contexts of the backend with the specified PID.
pg_log_backend_memory_contexts()
was added in PostgreSQL 14.
Usage
pg_log_backend_memory_contexts( pid
integer ) → boolean
After execution, the specified backend's memory contexts will be logged at LOG
message level.
This function can only be executed by a superuser or (in PostgreSQL 15 and later) a user granted execution permissions on the function, e.g. with:
GRANT EXECUTE ON FUNCTION pg_log_backend_memory_contexts TO someuser
Change history
- PostgreSQL 15
- non-superusers can be granted execution permissions (commit f0b051e3)
- PostgreSQL 14
- added (commit 43620e32)
Examples
Example of pg_log_backend_memory_contexts()
execution:
postgres=# SELECT pg_log_backend_memory_contexts(11727); pg_log_backend_memory_contexts -------------------------------- t (1 row)
Here, the selected PID here represents an autovacuum launcher.
The relevant output in the PostgreSQL log file:
[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
Executing with an invalid 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)
References
- PostgreSQL 14 documentation: Server Signaling Functions