Re: Alerting on memory use and instance crash

From: Rahila Syed <rahilasyed90(at)gmail(dot)com>
To: sud <suds1434(at)gmail(dot)com>
Cc: Ron Johnson <ronljohnsonjr(at)gmail(dot)com>, pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Alerting on memory use and instance crash
Date: 2025-10-10 10:38:43
Message-ID: CAH2L28uRJcPy36jFd7TjGxm9YjAqdOLKZLwc7NxPoC4S=_DuJw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

The other question I had was , are there any pg_* views using which, we are
> able to see which session/connection is using the highest amount of memory?
> I don't see any such columns in pg_stats_activity
>

From a purely postgresql database point of view, this feature is being
developed, you can view it here : PostgreSQL: Enhancing Memory Context
Statistics Reporting
<https://www.postgresql.org/message-id/flat/CAH2L28v8mc9HDt8QoSJ8TRmKau_8FM_HKS41NeO9-6ZAkuZKXw(at)mail(dot)gmail(dot)com>

Basically, this lets you provide the pid of any PostgreSQL process to an
sql function, which then returns its memory usage statistics.
Once this feature is committed, for obtaining memory usage statistics of
any postgresql session you would need to run
SELECT pg_backend_pid() which will give you the pid of the postgresql
backend.
You can then pass it to SELECT pg_get_process_memory_contexts(pid, ..),
which will return the memory consumption data.
This is for future reference.

At the moment, you can use the following function on the connection whose
memory you wish to inspect.
This works only for local connection i.e you can't use this function to
query the statistics of any other
postgresql process or connection.
PostgreSQL: Documentation: 18: 53.5. pg_backend_memory_contexts
<https://www.postgresql.org/docs/current/view-pg-backend-memory-contexts.html>

Thank you,
Rahila Syed

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Wim Rouquart 2025-10-10 12:28:28 RE: Index (primary key) corrupt?
Previous Message Laurenz Albe 2025-10-10 09:01:31 Re: Upgrade & Rollback plan: My customer requests rollback via old-version standby (13 ↔ 17) — need community advice