| From: | Fujii Masao <fujii(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Avoid backend hang during temp table cleanup in deferrable trans |
| Date: | 2026-09-03 03:17:58 |
| Message-ID: | E1x1xxc-00000003GBe-3vWd@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
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(at)gmail(dot)com>
Author: Andrey Rachitskiy <pl0h0yp1(at)gmail(dot)com>
Reviewed-by: Andrey Borodin <x4mmm(at)yandex-team(dot)ru>
Reviewed-by: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Discussion: https://postgr.es/m/19441-ec29f3b1363b4a68@postgresql.org
Backpatch-through: 14
Branch
------
REL_19_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/e65f21a274eb9de52b8286ff3b721259e6c37e82
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(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Fujii Masao | 2026-09-03 03:18:23 | pgsql: Avoid backend hang during temp table cleanup in deferrable trans |
| Previous Message | Fujii Masao | 2026-09-03 03:17:42 | pgsql: Stabilize recovery conflict stats checks in 031_recovery_conflic |