pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: Matthias van de Meent <boekewurm+postgres@gmail.com>
Cc: Alexander Lakhin <exclusion@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: Unexpected behavior after OOM errors
Date: Fri, 19 Jun 2026 08:55:30 +0900
Message-ID: <ajSFcksGRhNJEs5H@paquier.xyz> (raw)
In-Reply-To: <CAEze2Wj3HUz+Z4A8GaoSQyP1V_qGZEkxhp6dquF3+gNyoAmJNw@mail.gmail.com>
References: <e77acaac-a1b3-40b3-99ee-5769b4e453e4@gmail.com>
	<CAEze2Wgktuo+_QWfbALRW-UXXZhbSC+OgGGDFDV9m_BLy5KozQ@mail.gmail.com>
	<ajN2DkXPOzzC1GSj@paquier.xyz>
	<CAEze2Wj3HUz+Z4A8GaoSQyP1V_qGZEkxhp6dquF3+gNyoAmJNw@mail.gmail.com>

On Thu, Jun 18, 2026 at 11:27:28AM +0200, Matthias van de Meent wrote:
> Each of the calls to
> CacheRegisterSyscacheCallback/CacheRegisterRelcacheCallback can throw
> an ERROR when all slots have been used.  This would leave the typcache
> in an invalid state, so I think that must be wrapped in a critical
> section: neither syscache nor relcache has options to release
> callbacks, and we can't safely continue without the callbacks
> installed, so once an error is thrown here this backend can't ever be
> properly initialized.  This is unlike OOMs, whose conditions for
> failure may (and often do) change as workloads change in other
> backends.

We don't ERROR when failing to register a syscache/relcache callback,
we FATAL if we reach one of the thresholds.  Reaching these thresholds
points to me to a programming error anyway, so these should not matter
in the field.  The OOM is a random pattern that can happen outside the
Postgres realm.

Just in case, I have planted a elog(FATAL) triggering randomly in the
middle of cache registration callback calls, and the typcache
inconsistency does not come in play with the shutdown sequence once
these trigger even if we have the tables set but not the callbacks.
As a whole, I tend to think that reordering the actions is a solution
good enough here.

> I think Heikki's suggestion for a FATAL critical section option would
> be a good alternative. It wouldn't always be sufficient, but would fix
> issues here.

That sounds like an interesting idea, potentially reusable for other
areas, but I'm not really convinced that we need to add this kind of
facility for the case dealt with here.  To me, that's also where we
could use a TRY/CATCH block and call it a day.  If others feel
differently about this matter, I'm fine to be outvoted.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

view thread (32+ messages)  latest in thread

Message-ID: <ajSFcksGRhNJEs5H@paquier.xyz>
Permalink:  ../ajSFcksGRhNJEs5H@paquier.xyz/
Also on:    postgresql.org/message-id/ajSFcksGRhNJEs5H@paquier.xyz

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: michael@paquier.xyz, boekewurm+postgres@gmail.com, exclusion@gmail.com
  Subject: Re: Unexpected behavior after OOM errors
  In-Reply-To: <ajSFcksGRhNJEs5H@paquier.xyz>
  References: <e77acaac-a1b3-40b3-99ee-5769b4e453e4@gmail.com> <CAEze2Wgktuo+_QWfbALRW-UXXZhbSC+OgGGDFDV9m_BLy5KozQ@mail.gmail.com> <ajN2DkXPOzzC1GSj@paquier.xyz> <CAEze2Wj3HUz+Z4A8GaoSQyP1V_qGZEkxhp6dquF3+gNyoAmJNw@mail.gmail.com> <ajSFcksGRhNJEs5H@paquier.xyz>

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

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