aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/tablecmds.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2023-10-16 14:06:11 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2023-10-16 14:06:11 -0400
commit07eb22a7761f88a826c1d561c41aaeace23d3f7f (patch)
tree632eacb7d6e66f10dae16c0dc729c61ad909e59d /src/backend/commands/tablecmds.c
parent43c979086825e5df1816307fea9b41378cdc31bd (diff)
downloadpostgresql-07eb22a7761f88a826c1d561c41aaeace23d3f7f.tar.gz
postgresql-07eb22a7761f88a826c1d561c41aaeace23d3f7f.zip
Ensure we have a snapshot while dropping ON COMMIT DROP temp tables.
Dropping a temp table could entail TOAST table access to clean out toasted catalog entries, such as large pg_constraint.conbin strings for complex CHECK constraints. If we did that via ON COMMIT DROP, we triggered the assertion in init_toast_snapshot(), because there was no provision for setting up a snapshot for the drop actions. Fix that. (I assume here that the adjacent truncation actions for ON COMMIT DELETE ROWS don't have a similar problem: it doesn't seem like nontransactional truncations would need to touch any toasted fields. If that proves wrong, we could refactor a bit to have the same snapshot acquisition cover that too.) The test case added here does not fail before v15, because that assertion was added in 277692220 which was not back-patched. However, the race condition the assertion warns of surely exists further back, so back-patch to all supported branches. Per report from Richard Guo. Discussion: https://postgr.es/m/CAMbWs4-x26=_QxxgdJyNbiCDzvtr2WV5ZDso_v-CukKEe6cBZw@mail.gmail.com
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r--src/backend/commands/tablecmds.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index a798643c4f4..ae830127f01 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -15374,12 +15374,20 @@ PreCommit_on_commit_actions(void)
}
/*
+ * Object deletion might involve toast table access (to clean up
+ * toasted catalog entries), so ensure we have a valid snapshot.
+ */
+ PushActiveSnapshot(GetTransactionSnapshot());
+
+ /*
* Since this is an automatic drop, rather than one directly initiated
* by the user, we pass the PERFORM_DELETION_INTERNAL flag.
*/
performMultipleDeletions(targetObjects, DROP_CASCADE,
PERFORM_DELETION_INTERNAL | PERFORM_DELETION_QUIETLY);
+ PopActiveSnapshot();
+
#ifdef USE_ASSERT_CHECKING
/*