Skip to content

Commit 58d4f95

Browse files
author
Hiroshi Inoue
committed
Ensure to hold an exclusive lock while reindexing a relation.
This is mainly to help developers to understand the code.
1 parent 9df188b commit 58d4f95

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/backend/catalog/index.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.159 2001/08/10 18:57:33 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.160 2001/08/17 23:50:00 inoue Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -2016,11 +2016,16 @@ reindex_relation(Oid relid, bool force)
20162016
if (IsIgnoringSystemIndexes())
20172017
upd_pg_class_inplace = true;
20182018

2019+
/*
2020+
* Ensure to hold an exclusive lock throughout the
2021+
* transaction. The lock could be less intensive
2022+
* but now it's AccessExclusiveLock for simplicity.
2023+
*/
2024+
rel = heap_open(relid, AccessExclusiveLock);
20192025
/*
20202026
* ignore the indexes of the target system relation while processing
20212027
* reindex.
20222028
*/
2023-
rel = RelationIdGetRelation(relid);
20242029
if (!IsIgnoringSystemIndexes() && IsSystemRelationName(NameStr(rel->rd_rel->relname)))
20252030
deactivate_needed = true;
20262031
#ifndef ENABLE_REINDEX_NAILED_RELATIONS
@@ -2055,7 +2060,10 @@ reindex_relation(Oid relid, bool force)
20552060
else
20562061
elog(ERROR, "the target relation %u is shared", relid);
20572062
}
2058-
RelationClose(rel);
2063+
/*
2064+
* Continue to hold the lock.
2065+
*/
2066+
heap_close(rel, NoLock);
20592067

20602068
old = SetReindexProcessing(true);
20612069
if (deactivate_needed)

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