From 79926c0f91d29067617a3a84d5ad63e9d47153ab Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 25 Oct 2004 15:42:02 +0000 Subject: [PATCH] In the new dispensation where REINDEX doesn't take exclusive lock on the parent table, it's essential that all index accesses take some kind of lock on the index. I had missed vacuumlazy.c :-( ... --- src/backend/commands/vacuumlazy.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/backend/commands/vacuumlazy.c b/src/backend/commands/vacuumlazy.c index bac5444a3b..dd0fa21745 100644 --- a/src/backend/commands/vacuumlazy.c +++ b/src/backend/commands/vacuumlazy.c @@ -554,9 +554,12 @@ lazy_scan_index(Relation indrel, LVRelStats *vacrelstats) vac_init_rusage(&ru0); /* - * If index is unsafe for concurrent access, must lock it. + * Acquire appropriate type of lock on index: must be exclusive if + * index AM isn't concurrent-safe. */ - if (!indrel->rd_am->amconcurrent) + if (indrel->rd_am->amconcurrent) + LockRelation(indrel, RowExclusiveLock); + else LockRelation(indrel, AccessExclusiveLock); /* @@ -576,7 +579,9 @@ lazy_scan_index(Relation indrel, LVRelStats *vacrelstats) /* * Release lock acquired above. */ - if (!indrel->rd_am->amconcurrent) + if (indrel->rd_am->amconcurrent) + UnlockRelation(indrel, RowExclusiveLock); + else UnlockRelation(indrel, AccessExclusiveLock); if (!stats) @@ -619,9 +624,12 @@ lazy_vacuum_index(Relation indrel, LVRelStats *vacrelstats) vac_init_rusage(&ru0); /* - * If index is unsafe for concurrent access, must lock it. + * Acquire appropriate type of lock on index: must be exclusive if + * index AM isn't concurrent-safe. */ - if (!indrel->rd_am->amconcurrent) + if (indrel->rd_am->amconcurrent) + LockRelation(indrel, RowExclusiveLock); + else LockRelation(indrel, AccessExclusiveLock); /* Do bulk deletion */ @@ -636,7 +644,9 @@ lazy_vacuum_index(Relation indrel, LVRelStats *vacrelstats) /* * Release lock acquired above. */ - if (!indrel->rd_am->amconcurrent) + if (indrel->rd_am->amconcurrent) + UnlockRelation(indrel, RowExclusiveLock); + else UnlockRelation(indrel, AccessExclusiveLock); if (!stats) -- 2.39.5