1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

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
This commit is contained in:
Michael Paquier
2019-01-18 09:21:58 +09:00
parent 729c6c3f92
commit b15160bc71
11 changed files with 277 additions and 17 deletions

View File

@ -98,8 +98,8 @@ PREPARE TRANSACTION <replaceable class="PARAMETER">transaction_id</replaceable>
<para>
It is not currently allowed to <command>PREPARE</> a transaction that
has executed any operations involving temporary tables,
created any cursors <literal>WITH HOLD</>, or executed
has executed any operations involving temporary tables or the session's
temporary namespace, created any cursors <literal>WITH HOLD</>, or executed
<command>LISTEN</>, <command>UNLISTEN</>, or
<command>NOTIFY</>.
Those features are too tightly