public inbox for [email protected]  
help / color / mirror / Atom feed
From: Daniel Gustafsson <[email protected]>
To: [email protected]
Subject: pgsql: Add function to get memory context stats for processes
Date: Tue, 08 Apr 2025 09:10:49 +0000
Message-ID: <[email protected]> (raw)

Add function to get memory context stats for processes

This adds a function for retrieving memory context statistics
and information from backends as well as auxiliary processes.
The intended usecase is cluster debugging when under memory
pressure or unanticipated memory usage characteristics.

When calling the function it sends a signal to the specified
process to submit statistics regarding its memory contexts
into dynamic shared memory.  Each memory context is returned
in detail, followed by a cumulative total in case the number
of contexts exceed the max allocated amount of shared memory.
Each process is limited to use at most 1Mb memory for this.

A summary can also be explicitly requested by the user, this
will return the TopMemoryContext and a cumulative total of
all lower contexts.

In order to not block on busy processes the caller specifies
the number of seconds during which to retry before timing out.
In the case where no statistics are published within the set
timeout,  the last known statistics are returned, or NULL if
no previously published statistics exist.  This allows dash-
board type queries to continually publish even if the target
process is temporarily congested.  Context records contain a
timestamp to indicate when they were submitted.

Author: Rahila Syed <[email protected]>
Reviewed-by: Daniel Gustafsson <[email protected]>
Reviewed-by: Andres Freund <[email protected]>
Reviewed-by: Tomas Vondra <[email protected]>
Reviewed-by: Atsushi Torikoshi <[email protected]>
Reviewed-by: Fujii Masao <[email protected]>
Reviewed-by: Alexander Korotkov <[email protected]>
Discussion: https://postgr.es/m/CAH2L28v8mc9HDt8QoSJ8TRmKau_8FM_HKS41NeO9-6ZAkuZKXw@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/042a66291b04f473cbc72f95f07438abd75ae3a9

Modified Files
--------------
doc/src/sgml/func.sgml                          | 172 +++++++
src/backend/catalog/system_views.sql            |   5 +
src/backend/postmaster/autovacuum.c             |   4 +
src/backend/postmaster/checkpointer.c           |   4 +
src/backend/postmaster/interrupt.c              |   4 +
src/backend/postmaster/pgarch.c                 |   4 +
src/backend/postmaster/startup.c                |   4 +
src/backend/postmaster/walsummarizer.c          |   4 +
src/backend/storage/ipc/ipci.c                  |   3 +
src/backend/storage/ipc/procsignal.c            |   3 +
src/backend/storage/lmgr/lwlock.c               |   2 +
src/backend/storage/lmgr/proc.c                 |   1 +
src/backend/tcop/postgres.c                     |   3 +
src/backend/utils/activity/wait_event_names.txt |   1 +
src/backend/utils/adt/mcxtfuncs.c               | 426 ++++++++++++++--
src/backend/utils/init/globals.c                |   1 +
src/backend/utils/init/postinit.c               |   7 +
src/backend/utils/mmgr/mcxt.c                   | 645 +++++++++++++++++++++++-
src/include/catalog/pg_proc.dat                 |  10 +
src/include/miscadmin.h                         |   1 +
src/include/storage/lwlock.h                    |   2 +
src/include/storage/procsignal.h                |   1 +
src/include/utils/memutils.h                    |  82 +++
src/test/regress/expected/sysviews.out          |  19 +
src/test/regress/sql/sysviews.sql               |  18 +
src/tools/pgindent/typedefs.list                |   4 +
26 files changed, 1385 insertions(+), 45 deletions(-)



view thread (8+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: pgsql: Add function to get memory context stats for processes
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox