pgsql: Restrict the use of temporary namespace in two-phase transaction
Michael Paquier <michael@paquier.xyz>
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Date: 2019-01-18T00:22:52Z
Lists: 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(-)
Commits
-
Adjust error message
- eb69147e67ab 10.7 landed
- 12055c8f643a 11.2 landed
-
Enforce non-parallel plan when calling current_schema() in newly-added test
- 08b53281f444 10.7 landed
- 3daac78d983f 11.2 landed
- 396676b0ec4b 12.0 landed
-
Restrict the use of temporary namespace in two-phase transactions
- c5660e0aa52d 12.0 cited