Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v7AWb-00G075-9J for pgsql-general@arkaria.postgresql.org; Fri, 10 Oct 2025 10:39:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1v7AWY-00Bd2m-0l for pgsql-general@arkaria.postgresql.org; Fri, 10 Oct 2025 10:38:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v7AWX-00Bd2X-LY for pgsql-general@lists.postgresql.org; Fri, 10 Oct 2025 10:38:58 +0000 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v7AWW-001Or1-12 for pgsql-general@lists.postgresql.org; Fri, 10 Oct 2025 10:38:58 +0000 Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-57d5ccd73dfso2016094e87.0 for ; Fri, 10 Oct 2025 03:38:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1760092735; x=1760697535; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=x7P6ueolUrtxh82POycI2q8VoT6SjRL5cXPtTh82vzo=; b=QlQYd0DUxNQr+Aj0xr+JQKG0tWdCZT/4gTdH6Mx9d1aS6vsr8EZR55sM8hl0RZDkUt e8HyyNB2ZSEQjuotBvVfsy+L7n1dBmP0wV9qP0MdbsUhH/mWPGUM9km28qr8oLIN37do /zU+1/WoexiQby8c+Hbx/fJGP5YTikUH16fijCT+qyxXIaE2V8iHe3xwnex3HuLZO8wG 20eFx9q7L/pJi7E/LHKNojgaBXiuM5cQiLyweIN6LdeG35Wcf1oA8hqeA6nm5eWJBJNk d/jfFkQS6zO2qYer4Jn5B5f7ZF2lJkDIMVkFMIepujv1E/U7Ir0EfLFECsYyBRRbUYng DF5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760092735; x=1760697535; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=x7P6ueolUrtxh82POycI2q8VoT6SjRL5cXPtTh82vzo=; b=e83x+NRYCV2ybCswFLJh/tQy0ASBGW4vUrsXiSHamIF8fdPjD9+jiYHmlotQwn+V1N 2aCU6lBguVD4TalS/gKiXm+yKhYCXJ2cLROqmEZwRsJOSSTMLniQdtJcwfq9JKZvg6E5 tWOhYP7wk528u6k51+HlP2zvHqj70xXziDsIQwvSGssWwQZoBPL/VywnjLOrIvUCL33+ 5hegk6+SRcO6gq1+kd7Vftz3RACQzOlqMEFFbKyM5/xKwkpq8kcKNrSy3BgGYtiIJlkj WCavWI8x7b+F30kM8h8w3NEr9+CqfLiG1yrroLUoshr7DD9P+Xdc8G9a2XLUTzh9HBGy Eqig== X-Forwarded-Encrypted: i=1; AJvYcCV2WclzHcwrwuZ28JVMa7OVHK+fXB//WVULiuG5CsjGk5LDhyYdmR/UUQgIMqKwkz4yL4aGAoOWcx/BzXUp@lists.postgresql.org X-Gm-Message-State: AOJu0YzaiuXRdQR561+6AiETLr5T4Qy6c+BBOR2pmaaQCHWFI7Oj3M8i bSvAXfJFmD48IeNUQwD2STH+Hf5QySQBOSKc/tGVwcG5y9ODoMdZGOMJjg9rtE78lNEQ+U9s4Yb rhQ2mbMzVHASDZkvnijkS/ytCVTy8GZ4= X-Gm-Gg: ASbGnculgW5+2iH0rJy1l5GjY+UedRANJI3PHtrOO0BSS+iKVt48FivTOP1nIXlGM/C OYEYTzfcNUnmEGcDd4n3rU5inXhFQE4XzUVn4NHLGghFqcOVHRzTexbP2Yf5mYhrl5Gru549QBu V6N9qEEqk/q7KXiD47C/G+aou7J3EXB/f7niPzlhTknc51ocptckd3KzbpMKnuhgDURZwq2zfpC VT3O9EDw2uKijMn8TuDhm04m7ITxUPN6KBJZi2i5ZUxidJLROjSVB/tC8s3JPUVLyPgBuSwJULu o19cTzelN3D2AjhxvQ== X-Google-Smtp-Source: AGHT+IHNz9/EFe+27a9rtlD9WDQ2hU8RsdLn/LeFLBHcnGkmexA9kUPuw8uixFdBdq3FODYCFnYFEbNQBztvMrRSJdw= X-Received: by 2002:a05:651c:b27:b0:372:921b:4b8a with SMTP id 38308e7fff4ca-37609cea71emr31170821fa.4.1760092734993; Fri, 10 Oct 2025 03:38:54 -0700 (PDT) MIME-Version: 1.0 References: <9f175444-6bfc-4c6e-a609-e552d85c45a1@aklaver.com> In-Reply-To: From: Rahila Syed Date: Fri, 10 Oct 2025 16:08:43 +0530 X-Gm-Features: AS18NWB1O1J4GuicwBLLCG6jdNR-cFgWgMP8PxoxKKKU9ND3SFb2oDkzpDgsTz4 Message-ID: Subject: Re: Alerting on memory use and instance crash To: sud Cc: Ron Johnson , pgsql-general Content-Type: multipart/alternative; boundary="0000000000003db8410640cb86e8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000003db8410640cb86e8 Content-Type: text/plain; charset="UTF-8" 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 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 Thank you, Rahila Syed --0000000000003db8410640cb86e8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

=
The other question I had was , are there any pg_* vie= ws using which, we are able to see which session/connection is using the hi= ghest amount of memory? I don't=C2=A0see any such columns=C2=A0in pg_st= ats_activity

From a purely postgresql data= base point of view,=C2=A0 this feature is being developed, you can view it = here :=C2=A0 PostgreSQL: Enhancing Memory= Context Statistics Reporting=C2=A0
Basically, this lets you provide= the pid of any PostgreSQL process to an sql function, which then returns i= ts memory usage statistics.=C2=A0=C2=A0
Once this feature is committed, = for obtaining=C2=A0memory usage statistics of any postgresql session you wo= uld need to run=C2=A0
SELECT pg_backend_pid() which will give you the pi= d of the postgresql backend.
You can then pass it to SELECT pg_get_proc= ess_memory_contexts(pid, ..),=C2=A0 which will return the memory consumptio= n data.=C2=A0
This is for future reference.

At the moment, you ca= n use the following function on the connection whose memory you wish to ins= pect.=C2=A0=C2=A0
This works only for local connection i.e you can't= use this function to query the=C2=A0statistics of any other=C2=A0
postg= resql process or connection.=C2=A0
PostgreSQL: Documentati= on: 18: 53.5.=C2=A0pg_backend_memory_contexts

Thank you,
Rahila Syed


=C2=A0
--0000000000003db8410640cb86e8--