aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2019-10-23 15:04:48 +0900
committerMichael Paquier <michael@paquier.xyz>2019-10-23 15:04:48 +0900
commit5d3500da72611018f2280d6a31e58ccdb4b16152 (patch)
tree517424e40de5a0698c016707c3ca5a9a953f86b0 /src
parent508e84d79910cdb3b61fc410a245fd46e4fad30f (diff)
downloadpostgresql-5d3500da72611018f2280d6a31e58ccdb4b16152.tar.gz
postgresql-5d3500da72611018f2280d6a31e58ccdb4b16152.zip
Acquire properly session-level lock on new index in REINDEX CONCURRENTLY
In the first transaction run for REINDEX CONCURRENTLY, a thinko in the existing logic caused two session locks to be taken on the old index, causing the session lock on the newly-created index to be missed. This made possible concurrent DDL commands (like ALTER INDEX) on the new index while REINDEX CONCURRENTLY was processing from the point where the first internal transaction committed. This issue has been discovered while digging into another bug. Author: Michael Paquier Discussion: https://postgr.es/m/20191021074323.GB1869@paquier.xyz Backpatch-through: 12
Diffstat (limited to 'src')
-rw-r--r--src/backend/commands/indexcmds.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index e9da06a9fa7..4448b986b62 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -2960,8 +2960,11 @@ ReindexRelationConcurrently(Oid relationOid, int options)
indexId,
concurrentName);
- /* Now open the relation of the new index, a lock is also needed on it */
- newIndexRel = index_open(indexId, ShareUpdateExclusiveLock);
+ /*
+ * Now open the relation of the new index, a session-level lock is
+ * also needed on it.
+ */
+ newIndexRel = index_open(newIndexId, ShareUpdateExclusiveLock);
/*
* Save the list of OIDs and locks in private context