agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Fujii Masao <fujii@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Avoid backend hang during temp table cleanup in deferrable trans
Date: Thu, 03 Sep 2026 03:18:47 +0000
Message-ID: <E1x1xyQ-00000003GFS-17hy@gemulon.postgresql.org> (raw)

Avoid backend hang during temp table cleanup in deferrable transactions

Previously, a session that had created temporary objects could hang during
exit if its default transaction mode was SERIALIZABLE READ ONLY DEFERRABLE
and a concurrent serializable transaction was prepared. During backend
exit, temporary-relation cleanup pushed a regular transaction snapshot,
which honored the session's default settings and could wait for a safe
serializable snapshot. So, if the conflicting transaction was prepared,
this wait could last indefinitely.

The wait occurred while the backend was already exiting and interrupts
were held off, so even pg_terminate_backend() could not cancel it. The
backend therefore remained until the prepared transaction was resolved.

Temporary-relation cleanup only needs an active MVCC snapshot for fetching
TOAST data from catalog tuples while dropping temporary objects. It does
not need a transaction snapshot affected by the user's default isolation
settings. So, use a catalog snapshot instead, which provides the needed
protection without entering the deferrable safe-snapshot wait.

Backpatch to all supported versions.

Bug: #19441
Reported-by: Alexander Lakhin <exclusion@gmail.com>
Author: Andrey Rachitskiy <pl0h0yp1@gmail.com>
Reviewed-by: Andrey Borodin <x4mmm@yandex-team.ru>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/19441-ec29f3b1363b4a68@postgresql.org
Backpatch-through: 14

Branch
------
REL_16_STABLE

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

Modified Files
--------------
src/backend/catalog/namespace.c                    | 10 +++-
src/test/modules/test_misc/meson.build             |  1 +
.../test_misc/t/015_temp_schema_exit_deferrable.pl | 58 ++++++++++++++++++++++
3 files changed, 68 insertions(+), 1 deletion(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1x1xyQ-00000003GFS-17hy@gemulon.postgresql.org>
Permalink:  ../E1x1xyQ-00000003GFS-17hy@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1x1xyQ-00000003GFS-17hy@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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: fujii@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Avoid backend hang during temp table cleanup in deferrable trans
  In-Reply-To: <E1x1xyQ-00000003GFS-17hy@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 agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox