REL_11_STABLE.patch

application/octet-stream

Filename: REL_11_STABLE.patch
Type: application/octet-stream
Part: 0
Message: Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0

Patch

Format: format-patch
Series: patch 0002
Subject: Handle parallel index builds on mapped relations.
File+
src/backend/optimizer/plan/planner.c 5 3
From 25fa716a81eac0c922c224c225eb4f8fd687a9e4 Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <pg@bowt.ie>
Date: Tue, 7 Aug 2018 15:48:48 -0700
Subject: [PATCH 2/3] Handle parallel index builds on mapped relations.

Commit 9da0cc35284, which introduced parallel CREATE INDEX, failed to
propagate relmapper.c backend local cache state to parallel worker
processes.  This could result in parallel index builds against mapped
catalog relations where the leader process (participating as a worker)
scans the new, pristine relfilenode, while worker processes scan the
obsolescent relfilenode.  When this happened, the final index structure
was typically not consistent with the owning table's structure.  The
final index structure could contain entries formed from both heap
relfilenodes.

Only rebuilds on mapped catalog relations that occur as part of a VACUUM
FULL or CLUSTER could become corrupt in practice, since their mapped
relation relfilenode swap is what allows the inconsistency to arise.

On master, fix the problem by propagating the required relmapper.c
backend state as part of standard parallel initialization (Cf. commit
29d58fd3).  On v11, simply disallow builds against mapped catalog
relations by treating it as a parallel safety issue.

Reported-By: "death lock"
Bug: #15309
Discussion: https://postgr.es/m/153329671686.1405.18298309097348420351@wrigleys.postgresql.org
Backpatch: 11-, where parallel CREATE INDEX was introduced.
---
 src/backend/optimizer/plan/planner.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index fd06da98b9..9157442e7b 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -6091,11 +6091,13 @@ plan_create_index_workers(Oid tableOid, Oid indexOid)
 	/*
 	 * Determine if it's safe to proceed.
 	 *
-	 * Currently, parallel workers can't access the leader's temporary tables.
-	 * Furthermore, any index predicate or index expressions must be parallel
-	 * safe.
+	 * Currently, parallel workers can't access the leader's temporary tables,
+	 * or the leader's relmapper.c state, which is needed for builds on mapped
+	 * relations.  Furthermore, any index predicate or index expressions must
+	 * be parallel safe.
 	 */
 	if (heap->rd_rel->relpersistence == RELPERSISTENCE_TEMP ||
+		RelationIsMapped(heap) ||
 		!is_parallel_safe(root, (Node *) RelationGetIndexExpressions(index)) ||
 		!is_parallel_safe(root, (Node *) RelationGetIndexPredicate(index)))
 	{
-- 
2.17.1