From 09d3670df3e4593be1d2299a62d982829016b847 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 31 Jul 2006 20:09:10 +0000 Subject: Change the relation_open protocol so that we obtain lock on a relation (table or index) before trying to open its relcache entry. This fixes race conditions in which someone else commits a change to the relation's catalog entries while we are in process of doing relcache load. Problems of that ilk have been reported sporadically for years, but it was not really practical to fix until recently --- for instance, the recent addition of WAL-log support for in-place updates helped. Along the way, remove pg_am.amconcurrent: all AMs are now expected to support concurrent update. --- src/backend/commands/vacuumlazy.c | 38 ++------------------------------------ 1 file changed, 2 insertions(+), 36 deletions(-) (limited to 'src/backend/commands/vacuumlazy.c') diff --git a/src/backend/commands/vacuumlazy.c b/src/backend/commands/vacuumlazy.c index d2727c4a470..2202e7b7e9a 100644 --- a/src/backend/commands/vacuumlazy.c +++ b/src/backend/commands/vacuumlazy.c @@ -31,7 +31,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.75 2006/07/14 14:52:18 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.76 2006/07/31 20:09:00 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -164,7 +164,7 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt) vacrelstats->minxid = RecentXmin; /* Open all indexes of the relation */ - vac_open_indexes(onerel, ShareUpdateExclusiveLock, &nindexes, &Irel); + vac_open_indexes(onerel, RowExclusiveLock, &nindexes, &Irel); hasindex = (nindexes > 0); /* Do the vacuuming */ @@ -621,15 +621,6 @@ lazy_vacuum_index(Relation indrel, pg_rusage_init(&ru0); - /* - * Acquire appropriate type of lock on index: must be exclusive if index - * AM isn't concurrent-safe. - */ - if (indrel->rd_am->amconcurrent) - LockRelation(indrel, RowExclusiveLock); - else - LockRelation(indrel, AccessExclusiveLock); - ivinfo.index = indrel; ivinfo.vacuum_full = false; ivinfo.message_level = elevel; @@ -640,14 +631,6 @@ lazy_vacuum_index(Relation indrel, *stats = index_bulk_delete(&ivinfo, *stats, lazy_tid_reaped, (void *) vacrelstats); - /* - * Release lock acquired above. - */ - if (indrel->rd_am->amconcurrent) - UnlockRelation(indrel, RowExclusiveLock); - else - UnlockRelation(indrel, AccessExclusiveLock); - ereport(elevel, (errmsg("scanned index \"%s\" to remove %d row versions", RelationGetRelationName(indrel), @@ -668,15 +651,6 @@ lazy_cleanup_index(Relation indrel, pg_rusage_init(&ru0); - /* - * Acquire appropriate type of lock on index: must be exclusive if index - * AM isn't concurrent-safe. - */ - if (indrel->rd_am->amconcurrent) - LockRelation(indrel, RowExclusiveLock); - else - LockRelation(indrel, AccessExclusiveLock); - ivinfo.index = indrel; ivinfo.vacuum_full = false; ivinfo.message_level = elevel; @@ -684,14 +658,6 @@ lazy_cleanup_index(Relation indrel, stats = index_vacuum_cleanup(&ivinfo, stats); - /* - * Release lock acquired above. - */ - if (indrel->rd_am->amconcurrent) - UnlockRelation(indrel, RowExclusiveLock); - else - UnlockRelation(indrel, AccessExclusiveLock); - if (!stats) return; -- cgit v1.2.3