Restrict the use of temporary namespace in two-phase transactions

Enterprise / PostgreSQL - Michael Paquier [] - 18 January 2019 00:21 EST

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.

c5660e0aa5 Restrict the use of temporary namespace in two-phase transactions
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(-)


  • Share