summaryrefslogtreecommitdiff
path: root/src/backend/utils/cache/relcache.c
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2014-11-17 11:23:35 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2014-11-17 11:23:35 -0300
commit0f9692b40d1292f1b2640f026561908fd37b7407 (patch)
treece97fbab4a35657069568b8469a733c94e7907a1 /src/backend/utils/cache/relcache.c
parent7466a1b75f01c10c2eb33ed50663fe27f66194e9 (diff)
Fix relpersistence setting in reindex_index
Buildfarm members with CLOBBER_CACHE_ALWAYS advised us that commit 85b506bbfc2937 was mistaken in setting the relpersistence value of the index directly in the relcache entry, within reindex_index. The reason for the failure is that an invalidation message that comes after mucking with the relcache entry directly, but before writing it to the catalogs, would cause the entry to become rebuilt in place from catalogs with the old contents, losing the update. Fix by passing the correct persistence value to RelationSetNewRelfilenode instead; this routine also writes the updated tuple to pg_class, avoiding the problem. Suggested by Tom Lane.
Diffstat (limited to 'src/backend/utils/cache/relcache.c')
-rw-r--r--src/backend/utils/cache/relcache.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index 2250c56d28b..c80ef3c6f89 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -3005,10 +3005,14 @@ RelationBuildLocalRelation(const char *relname,
* The relation is marked with relfrozenxid = freezeXid (InvalidTransactionId
* must be passed for indexes and sequences). This should be a lower bound on
* the XIDs that will be put into the new relation contents.
+ *
+ * The new filenode's persistence is set to the given value. This is useful
+ * for the cases that are changing the relation's persistence; other callers
+ * need to pass the original relpersistence value.
*/
void
-RelationSetNewRelfilenode(Relation relation, TransactionId freezeXid,
- MultiXactId minmulti)
+RelationSetNewRelfilenode(Relation relation, char persistence,
+ TransactionId freezeXid, MultiXactId minmulti)
{
Oid newrelfilenode;
RelFileNodeBackend newrnode;
@@ -3025,7 +3029,7 @@ RelationSetNewRelfilenode(Relation relation, TransactionId freezeXid,
/* Allocate a new relfilenode */
newrelfilenode = GetNewRelFileNode(relation->rd_rel->reltablespace, NULL,
- relation->rd_rel->relpersistence);
+ persistence);
/*
* Get a writable copy of the pg_class tuple for the given relation.
@@ -3048,7 +3052,7 @@ RelationSetNewRelfilenode(Relation relation, TransactionId freezeXid,
newrnode.node = relation->rd_node;
newrnode.node.relNode = newrelfilenode;
newrnode.backend = relation->rd_backend;
- RelationCreateStorage(newrnode.node, relation->rd_rel->relpersistence);
+ RelationCreateStorage(newrnode.node, persistence);
smgrclosenode(newrnode);
/*
@@ -3078,7 +3082,7 @@ RelationSetNewRelfilenode(Relation relation, TransactionId freezeXid,
}
classform->relfrozenxid = freezeXid;
classform->relminmxid = minmulti;
- classform->relpersistence = relation->rd_rel->relpersistence;
+ classform->relpersistence = persistence;
simple_heap_update(pg_class, &tuple->t_self, tuple);
CatalogUpdateIndexes(pg_class, tuple);