pgsql: Restrict the use of temporary namespace in two-phase transaction

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Restrict the use of temporary namespace in two-phase transaction
Date: 2019-01-18 00:22:52
Message-ID: E1gkHvw-00010c-3O@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

Restrict the use of temporary namespace in two-phase transactions

Attempting to use a temporary table within a two-phase transaction is
forbidden for ages. However, there have been uncovered grounds for
a couple of other object types and commands which work on temporary
objects with two-phase commit. In short, trying to create, lock or drop
an object on a temporary schema should not be authorized within a
two-phase transaction, as it would cause its state to create
dependencies with other sessions, causing all sorts of side effects with
the existing session or other sessions spawned later on trying to use
the same temporary schema name.

Regression tests are added to cover all the grounds found, the original
report mentioned function creation, but monitoring closer there are many
other patterns with LOCK, DROP or CREATE EXTENSION which are involved.
One of the symptoms resulting in combining both is that the session
which used the temporary schema is not able to shut down completely,
waiting for being able to drop the temporary schema, something that it
cannot complete because of the two-phase transaction involved with
temporary objects. In this case the client is able to disconnect but
the session remains alive on the backend-side, potentially blocking
connection backend slots from being used. Other problems reported could
also involve server crashes.

This is back-patched down to v10, which is where 9b013dc has introduced
MyXactFlags, something that this patch relies on.

Reported-by: Alexey Bashtanov
Author: Michael Paquier
Reviewed-by: Masahiko Sawada
Discussion: https://postgr.es/m/5d910e2e-0db8-ec06-dd5f-baec420513c3@imap.cc
Backpatch-through: 10

Branch
------
master

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

Modified Files
--------------
doc/src/sgml/ref/prepare_transaction.sgml | 6 +-
src/backend/access/transam/xact.c | 12 ++++
src/backend/catalog/namespace.c | 59 +++++++++++++-----
src/backend/commands/dropcmds.c | 8 +++
src/backend/commands/extension.c | 7 +++
src/backend/commands/lockcmds.c | 10 +++
src/include/access/xact.h | 5 ++
.../test_extensions/expected/test_extensions.out | 33 ++++++++++
.../test_extensions/sql/test_extensions.sql | 29 +++++++++
src/test/regress/expected/temp.out | 71 ++++++++++++++++++++++
src/test/regress/sql/temp.sql | 56 +++++++++++++++++
11 files changed, 278 insertions(+), 18 deletions(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2019-01-18 00:26:34 Re: pgsql: Remove references to Majordomo
Previous Message Magnus Hagander 2019-01-17 13:04:44 pgsql: Remove references to Majordomo

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2019-01-18 00:26:34 Re: pgsql: Remove references to Majordomo
Previous Message Tom Lane 2019-01-18 00:21:08 Re: PSA: we lack TAP test coverage on NetBSD and OpenBSD