pgsql: Fix temporary object cleanup failing due to toast access without - Mailing list pgsql-committers

From Andres Freund
Subject pgsql: Fix temporary object cleanup failing due to toast access without
Date
Msg-id E1nMDX0-0001Mc-AZ@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
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_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/cebc54b90bda3ce43dc60faf216d2d149eebd3f3

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(+)


pgsql-committers by date:

Previous
From: Andres Freund
Date:
Subject: pgsql: pg_upgrade: Don't print progress status when output is not a tty
Next
From: Tom Lane
Date:
Subject: pgsql: Disallow setting bogus GUCs within an extension's reserved names