Revert function to get memory context stats for processes
authorDaniel Gustafsson
Fri, 23 May 2025 13:44:54 +0000 (15:44 +0200)
committerDaniel Gustafsson
Fri, 23 May 2025 13:44:54 +0000 (15:44 +0200)
Due to concerns raised about the approach, and memory leaks found
in sensitive contexts the functionality is reverted. This reverts
commits 45e7e8ca9f8c115a6cd2a1ed17255ef7abf8 and 042a66291
for v18 with an intent to revisit this patch for v19.

Discussion: https://postgr.es/m/594293.1747708165@sss.pgh.pa.us

29 files changed:
doc/src/sgml/func.sgml
doc/src/sgml/release-18.sgml
src/backend/catalog/system_views.sql
src/backend/postmaster/autovacuum.c
src/backend/postmaster/checkpointer.c
src/backend/postmaster/interrupt.c
src/backend/postmaster/pgarch.c
src/backend/postmaster/startup.c
src/backend/postmaster/walsummarizer.c
src/backend/storage/ipc/ipci.c
src/backend/storage/ipc/procsignal.c
src/backend/storage/lmgr/lwlock.c
src/backend/storage/lmgr/proc.c
src/backend/tcop/postgres.c
src/backend/utils/activity/wait_event_names.txt
src/backend/utils/adt/mcxtfuncs.c
src/backend/utils/adt/pg_locale.c
src/backend/utils/init/globals.c
src/backend/utils/init/postinit.c
src/backend/utils/mb/mbutils.c
src/backend/utils/mmgr/mcxt.c
src/include/catalog/pg_proc.dat
src/include/miscadmin.h
src/include/storage/lwlock.h
src/include/storage/procsignal.h
src/include/utils/memutils.h
src/test/regress/expected/sysviews.out
src/test/regress/sql/sysviews.sql
src/tools/pgindent/typedefs.list

index b405525a465c5d95ea7fe08687116d7a54d1f9e8..c67688cbf5f98fbcb6b87a91d05bc27d2ab007ca 100644 (file)
@@ -28663,143 +28663,6 @@ acl      | {postgres=arwdDxtm/postgres,foo=r/postgres}
        
       
 
-      
-       
-        
-         pg_get_process_memory_contexts
-        
-        pg_get_process_memory_contexts ( pid integersummary booleantimeout float )
-        setof record
-        ( name text,
-        ident text,
-        type text,
-        path integer[],
-        level integer,
-        total_bytes bigint,
-        total_nblocks bigint,
-        free_bytes bigint,
-        free_chunks bigint,
-        used_bytes bigint,
-        num_agg_contexts integer,
-        stats_timestamp timestamptz )
-       
-       
-        This function handles requests to display the memory contexts of a
-        PostgreSQL process with the specified
-        process ID.  The function can be used to send requests to backends as
-        well as auxiliary processes.
-       
-       
-        The returned record contains extended statistics per each memory
-        context:
-        
-         
-          
-           name - The name of the memory context.
-          
-         
-         
-          
-           ident - Memory context ID (if any).
-          
-         
-         
-          
-           type - The type of memory context, possible
-           values are: AllocSet, Generation, Slab and Bump.
-          
-         
-         
-          
-           path - Memory contexts are organized in a
-           tree model with TopMemoryContext as the root, and all other memory
-           contexts as nodes in the tree. The path
-           displays the path from the root to the current memory context. The
-           path is limited to 100 children per node, which each node limited
-           to a max depth of 100, to preserve memory during reporting. The
-           printed path will also be limited to 100 nodes counting from the
-           TopMemoryContext.
-          
-         
-         
-          
-           level - The level in the tree of the current
-           memory context.
-          
-         
-         
-          
-           total_bytes - The total number of bytes
-           allocated to this memory context.
-          
-         
-         
-          
-           total_nblocks - The total number of blocks
-           used for the allocated memory.
-          
-         
-         
-          
-           free_bytes - The amount of free memory in
-           this memory context.
-          
-         
-         
-          
-           free_chunks - The number of chunks that
-           free_bytes corresponds to.
-          
-         
-         
-          
-           used_bytes - The total number of bytes
-           currently occupied.
-          
-         
-         
-          
-           num_agg_contexts - The number of memory
-           contexts aggregated in the displayed statistics.
-          
-         
-         
-          
-           stats_timestamp - When the statistics were
-           extracted from the process.
-          
-         
-        
-       
-       
-        When summary is true, statistics
-        for memory contexts at levels 1 and 2 are displayed, with level 1
-        representing the root node (i.e., TopMemoryContext).
-        Statistics for contexts on level 2 and below are aggregates of all
-        child contexts' statistics, where num_agg_contexts
-        indicate the number aggregated child contexts.  When
-        summary is false,
-        the num_agg_contexts value is 1,
-        indicating that individual statistics are being displayed.
-       
-       
-        Busy processes can delay reporting memory context statistics,
-        timeout specifies the number of seconds
-        to wait for updated statistics. timeout can be
-        specified in fractions of a second.
-       
-       
-        After receiving memory context statistics from the target process, it
-        returns the results as one row per context.  If all the contexts don't
-        fit within the pre-determined size limit, the remaining context
-        statistics are aggregated and a cumulative total is displayed.  The
-        num_agg_contexts column indicates the number of
-        contexts aggregated in the displayed statistics.  When
-        num_agg_contexts is 1 it means
-        that the context statistics are displayed separately.
-       
-      
-
       
        
         
@@ -28939,40 +28802,6 @@ LOG:  Grand total: 1651920 bytes in 201 blocks; 622360 free (88 chunks); 1029560
     because it may generate a large number of log messages.
    
 
-   
-    pg_get_process_memory_contexts can be used to request
-    memory contexts statistics of any PostgreSQL
-    process.  For example:
-
-postgres=# SELECT * FROM pg_get_process_memory_contexts(
-  (SELECT pid FROM pg_stat_activity
-    WHERE backend_type = 'checkpointer'),
-  false, 0.5) LIMIT 1;
--[ RECORD 1 ]----+------------------------------
-name             | TopMemoryContext
-ident            |
-type             | AllocSet
-path             | {1}
-level            | 1
-total_bytes      | 90304
-total_nblocks    | 3
-free_bytes       | 2880
-free_chunks      | 1
-used_bytes       | 87424
-num_agg_contexts | 1
-stats_timestamp  | 2025-03-24 13:55:47.796698+01
-
-    
-     
-      While pg_get_process_memory_contexts can be used to
-      query memory contexts of the local backend,
-      pg_backend_memory_contexts
-      (see  for more details)
-      will be less resource intensive when only the local backend is of interest.
-     
-    
-   
-
   
 
   
index 246e49ce74013b6985759de13dc26f63f83bce06..73523289d979c3f48d12b011d5080b7c43e01a59 100644 (file)
@@ -961,21 +961,6 @@ This is true even if the tables in different schemas have different column names
 
 
 
-
-
-
-
-Add function pg_get_process_memory_contexts() to report process memory context statistics (Rahila Syed)
-§
-§
-
-
-