pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix temporary object cleanup failing due to toast access without
Date: Mon, 21 Feb 2022 18:35:29 +0000
Message-ID: <E1nMDX0-0001MZ-A3@gemulon.postgresql.org> (raw)

Fix temporary object cleanup failing due to toast access without snapshot.

When cleaning up temporary objects during process exit the cleanup could fail
with:
  FATAL: cannot fetch toast data without an active snapshot

The bug is caused by RemoveTempRelationsCallback() not setting up a
snapshot. If an object with toasted catalog data needs to be cleaned up,
init_toast_snapshot() could fail with the above error.

Most of the time however the the problem is masked due to cached catalog
snapshots being returned by GetOldestSnapshot(). But dropping an object can
cause catalog invalidations to be emitted. If no further catalog accesses are
necessary between the invalidation processing and the next toast datum
deletion, the bug becomes visible.

It's easy to miss this bug because it typically happens after clients
disconnect and the FATAL error just ends up in the log.

Luckily temporary table cleanup at the next use of the same temporary schema
or during DISCARD ALL does not have the same problem.

Fix the bug by pushing a snapshot in RemoveTempRelationsCallback(). Also add
isolation tests for temporary object cleanup, including objects with toasted
catalog data.

A future HEAD only commit will add more assertions.

Reported-By: Miles Delahunty
Author: Andres Freund
Discussion: https://postgr.es/m/CAOFAq3BU5Mf2TTvu8D9n_ZOoFAeQswuzk7yziAb7xuw_qyw5gw@mail.gmail.com
Backpatch: 10-

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/3faa21bb761f52974cfc59dd9d3993f89d81f44e

Modified Files
--------------
src/backend/catalog/namespace.c                    |   3 +
.../isolation/expected/temp-schema-cleanup.out     | 115 +++++++++++++++++++++
src/test/isolation/isolation_schedule              |   1 +
src/test/isolation/specs/temp-schema-cleanup.spec  |  85 +++++++++++++++
4 files changed, 204 insertions(+)



view thread (6+ messages)  latest in thread

Message-ID: <E1nMDX0-0001MZ-A3@gemulon.postgresql.org>
Permalink:  ../E1nMDX0-0001MZ-A3@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1nMDX0-0001MZ-A3@gemulon.postgresql.org

 · 

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-committers@postgresql.org
  Cc: andres@anarazel.de
  Subject: Re: pgsql: Fix temporary object cleanup failing due to toast access without
  In-Reply-To: <E1nMDX0-0001MZ-A3@gemulon.postgresql.org>
  References: <E1nMDX0-0001MZ-A3@gemulon.postgresql.org>

* 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