pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: Peter Geoghegan <pg@bowt.ie>
Cc: hubert depesz lubaczewski <depesz@depesz.com>
Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Subject: Re: Pg 15 devel crashes when fetching data from table using cursor
Date: Thu, 10 Mar 2022 19:44:49 -0800
Message-ID: <20220311034449.4hal3lu3s4sseihq@alap3.anarazel.de> (raw)
In-Reply-To: <20220311030721.olixpzcquqkw2qyt@alap3.anarazel.de>
References: <20220307094423.GA24798@depesz.com>
	<20220311005045.vnwb3aa5htilh3rh@alap3.anarazel.de>
	<20220311023643.wjfhoi5xbggvmluu@alap3.anarazel.de>
	<765892.1646966405@sss.pgh.pa.us>
	<20220311030721.olixpzcquqkw2qyt@alap3.anarazel.de>

Hi,

On 2022-03-10 19:07:21 -0800, Andres Freund wrote:
> This suggests that we should assert that we have a suitable snapshot in
> pg_detoast_datum*, so that we don't need to have an externally toasted datum
> to notice such bugs. The reason I put it in init_toast_snapshot() was that the
> bug leading to the assert was from toast_delete_datum(). But even there it'd
> be better to put the assert to before the early return?

I added an assert like that, but it'd be a lot of stuff to clean up to make it
work :(. There's some easy to ignore cases like bootstrap (safe),
PostgresInit() (probably not). But after that there's just countless unsafe
accesses. Including the one Peter just mentioned in do_autovacuum(). And of
course the one triggering this report.

In a lot of places we fetch a tuple (using a snapshot of course) and then
later after the snapshot is released, take actions that cause datums to be
detoasted (if they were toasted).  Afaict that's plainly not safe - nothing
prevents the toasted datum to be pruned away and replaced with something else,
potentially of a different datatype.

It kinda works for relations using catalog snapshots, because we do hold the
catalog snapshot for longer - but only until the next invalidations are
processed.


I wonder what a debugging mode forcing everything toastable to be toasted
would bring to light *shudder*.

Greetings,

Andres Freund





view thread (11+ messages)

Message-ID: <20220311034449.4hal3lu3s4sseihq@alap3.anarazel.de>
Permalink:  ../20220311034449.4hal3lu3s4sseihq@alap3.anarazel.de/
Also on:    postgresql.org/message-id/20220311034449.4hal3lu3s4sseihq@alap3.anarazel.de

 · 

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-bugs@postgresql.org
  Cc: andres@anarazel.de, tgl@sss.pgh.pa.us, pg@bowt.ie, depesz@depesz.com
  Subject: Re: Pg 15 devel crashes when fetching data from table using cursor
  In-Reply-To: <20220311034449.4hal3lu3s4sseihq@alap3.anarazel.de>
  References: <20220307094423.GA24798@depesz.com> <20220311005045.vnwb3aa5htilh3rh@alap3.anarazel.de> <20220311023643.wjfhoi5xbggvmluu@alap3.anarazel.de> <765892.1646966405@sss.pgh.pa.us> <20220311030721.olixpzcquqkw2qyt@alap3.anarazel.de> <20220311034449.4hal3lu3s4sseihq@alap3.anarazel.de>

* 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