Skip to content

Commit 2c66dcf

Browse files
committed
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 :-( ...
1 parent 1d6b096 commit 2c66dcf

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/backend/commands/vacuumlazy.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*
3232
*
3333
* IDENTIFICATION
34-
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.47 2004/10/15 22:39:56 tgl Exp $
34+
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.48 2004/10/25 15:42:02 tgl Exp $
3535
*
3636
*-------------------------------------------------------------------------
3737
*/
@@ -554,9 +554,12 @@ lazy_scan_index(Relation indrel, LVRelStats *vacrelstats)
554554
vac_init_rusage(&ru0);
555555

556556
/*
557-
* If index is unsafe for concurrent access, must lock it.
557+
* Acquire appropriate type of lock on index: must be exclusive if
558+
* index AM isn't concurrent-safe.
558559
*/
559-
if (!indrel->rd_am->amconcurrent)
560+
if (indrel->rd_am->amconcurrent)
561+
LockRelation(indrel, RowExclusiveLock);
562+
else
560563
LockRelation(indrel, AccessExclusiveLock);
561564

562565
/*
@@ -576,7 +579,9 @@ lazy_scan_index(Relation indrel, LVRelStats *vacrelstats)
576579
/*
577580
* Release lock acquired above.
578581
*/
579-
if (!indrel->rd_am->amconcurrent)
582+
if (indrel->rd_am->amconcurrent)
583+
UnlockRelation(indrel, RowExclusiveLock);
584+
else
580585
UnlockRelation(indrel, AccessExclusiveLock);
581586

582587
if (!stats)
@@ -619,9 +624,12 @@ lazy_vacuum_index(Relation indrel, LVRelStats *vacrelstats)
619624
vac_init_rusage(&ru0);
620625

621626
/*
622-
* If index is unsafe for concurrent access, must lock it.
627+
* Acquire appropriate type of lock on index: must be exclusive if
628+
* index AM isn't concurrent-safe.
623629
*/
624-
if (!indrel->rd_am->amconcurrent)
630+
if (indrel->rd_am->amconcurrent)
631+
LockRelation(indrel, RowExclusiveLock);
632+
else
625633
LockRelation(indrel, AccessExclusiveLock);
626634

627635
/* Do bulk deletion */
@@ -636,7 +644,9 @@ lazy_vacuum_index(Relation indrel, LVRelStats *vacrelstats)
636644
/*
637645
* Release lock acquired above.
638646
*/
639-
if (!indrel->rd_am->amconcurrent)
647+
if (indrel->rd_am->amconcurrent)
648+
UnlockRelation(indrel, RowExclusiveLock);
649+
else
640650
UnlockRelation(indrel, AccessExclusiveLock);
641651

642652
if (!stats)

0 commit comments

Comments
 (0)