Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit68f7b91

Browse files
committed
In rebuild_relation(), don't access an already-closed relcache entry.
This reliably fails with -DRELCACHE_FORCE_RELEASE, as reported byAndrew Dunstan, and could sometimes fail in normal operation, resultingin a wrong persistence value being used for the transient table.It's not immediately clear to me what effects that might have beyondthe risk of a crash while accessing OldHeap->rd_rel->relpersistence,but it's probably not good.Bug introduced by commitf41872d, and made substantially worse bycommit85b506b, which added a second such access significantlylater than the heap_close. I doubt the first reference could failin a production scenario, but the second one definitely could.Discussion:https://postgr.es/m/7b52f900-0579-cda9-ae2e-de5da17090e6@2ndQuadrant.com
1 parentb0344f8 commit68f7b91

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

‎src/backend/commands/cluster.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ rebuild_relation(Relation OldHeap, Oid indexOid, bool verbose)
559559
OidtableOid=RelationGetRelid(OldHeap);
560560
OidtableSpace=OldHeap->rd_rel->reltablespace;
561561
OidOIDNewHeap;
562+
charrelpersistence;
562563
boolis_system_catalog;
563564
boolswap_toast_by_content;
564565
TransactionIdfrozenXid;
@@ -568,15 +569,16 @@ rebuild_relation(Relation OldHeap, Oid indexOid, bool verbose)
568569
if (OidIsValid(indexOid))
569570
mark_index_clustered(OldHeap,indexOid, true);
570571

571-
/* Remember if it's a system catalog */
572+
/* Remember info about rel before closing OldHeap */
573+
relpersistence=OldHeap->rd_rel->relpersistence;
572574
is_system_catalog=IsSystemRelation(OldHeap);
573575

574576
/* Close relcache entry, but keep lock until transaction commit */
575577
heap_close(OldHeap,NoLock);
576578

577579
/* Create the transient table that will receive the re-ordered data */
578580
OIDNewHeap=make_new_heap(tableOid,tableSpace,
579-
OldHeap->rd_rel->relpersistence,
581+
relpersistence,
580582
AccessExclusiveLock);
581583

582584
/* Copy the heap data into the new table in the desired order */
@@ -590,7 +592,7 @@ rebuild_relation(Relation OldHeap, Oid indexOid, bool verbose)
590592
finish_heap_swap(tableOid,OIDNewHeap,is_system_catalog,
591593
swap_toast_by_content, false, true,
592594
frozenXid,cutoffMulti,
593-
OldHeap->rd_rel->relpersistence);
595+
relpersistence);
594596
}
595597

596598

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp