Skip to content

Commit b7ba2c0

Browse files
Ensure we have a snapshot when updating various system catalogs.
A few places that access system catalogs don't set up an active snapshot before potentially accessing their TOAST tables. To fix, push an active snapshot just before each section of code that might require accessing one of these TOAST tables, and pop it shortly afterwards. While at it, this commit adds some rather strict assertions in an attempt to prevent such issues in the future. Commit 16bf24e recently removed pg_replication_origin's TOAST table in order to fix the same problem for that catalog. On the back-branches, those bugs are left in place. We cannot easily remove a catalog's TOAST table on released major versions, and only replication origins with extremely long names are affected. Given the low severity of the issue, fixing older versions doesn't seem worth the trouble of significantly modifying the patch. Also, on v13 and v14, the aforementioned strict assertions have been omitted because commit 2776922, which added HaveRegisteredOrActiveSnapshot(), was not back-patched. While we could probably back-patch it now, I've opted against it because it seems unlikely that new TOAST snapshot issues will be introduced in the oldest supported versions. Reported-by: Alexander Lakhin <exclusion@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/18127-fe54b6a667f29658%40postgresql.org Discussion: https://postgr.es/m/18309-c0bf914950c46692%40postgresql.org Discussion: https://postgr.es/m/ZvMSUPOqUU-VNADN%40nathan Backpatch-through: 13
1 parent 271cb7e commit b7ba2c0

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/backend/commands/indexcmds.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3519,12 +3519,20 @@ ReindexRelationConcurrently(Oid relationOid, int options)
35193519
get_rel_namespace(heapId),
35203520
false);
35213521

3522+
/*
3523+
* Swapping the indexes might involve TOAST table access, so ensure we
3524+
* have a valid snapshot.
3525+
*/
3526+
PushActiveSnapshot(GetTransactionSnapshot());
3527+
35223528
/*
35233529
* Swap old index with the new one. This also marks the new one as
35243530
* valid and the old one as not valid.
35253531
*/
35263532
index_concurrently_swap(newIndexId, oldIndexId, oldName);
35273533

3534+
PopActiveSnapshot();
3535+
35283536
/*
35293537
* Invalidate the relcache for the table, so that after this commit
35303538
* all sessions will refresh any cached plans that might reference the

src/backend/postmaster/autovacuum.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,6 +2294,12 @@ do_autovacuum(void)
22942294
get_namespace_name(classForm->relnamespace),
22952295
NameStr(classForm->relname))));
22962296

2297+
/*
2298+
* Deletion might involve TOAST table access, so ensure we have a
2299+
* valid snapshot.
2300+
*/
2301+
PushActiveSnapshot(GetTransactionSnapshot());
2302+
22972303
object.classId = RelationRelationId;
22982304
object.objectId = relid;
22992305
object.objectSubId = 0;
@@ -2306,6 +2312,7 @@ do_autovacuum(void)
23062312
* To commit the deletion, end current transaction and start a new
23072313
* one. Note this also releases the locks we took.
23082314
*/
2315+
PopActiveSnapshot();
23092316
CommitTransactionCommand();
23102317
StartTransactionCommand();
23112318

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy