pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Restrict the use of temporary namespace in two-phase transaction
Date: Fri, 18 Jan 2019 00:22:52 +0000
Message-ID: <E1gkHvw-00010e-3K@gemulon.postgresql.org> (raw)

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
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/3e4fdb3bc0dc3314a0396bc7067afb40e0df186e

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(-)



view thread (17+ messages)  latest in thread

Message-ID: <E1gkHvw-00010e-3K@gemulon.postgresql.org>
Permalink:  ../E1gkHvw-00010e-3K@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1gkHvw-00010e-3K@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: michael@paquier.xyz, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Restrict the use of temporary namespace in two-phase transaction
  In-Reply-To: <E1gkHvw-00010e-3K@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 DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox