aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/vacuumlazy.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2006-07-31 20:09:10 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2006-07-31 20:09:10 +0000
commit09d3670df3e4593be1d2299a62d982829016b847 (patch)
tree7a62e91c1cf595d0334dd2c196d1c79835cc267b /src/backend/commands/vacuumlazy.c
parent4cd72b53b9975bab5f4ca0792cf4f54c84829404 (diff)
downloadpostgresql-09d3670df3e4593be1d2299a62d982829016b847.tar.gz
postgresql-09d3670df3e4593be1d2299a62d982829016b847.zip
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.
Diffstat (limited to 'src/backend/commands/vacuumlazy.c')
-rw-r--r--src/backend/commands/vacuumlazy.c38
1 files changed, 2 insertions, 36 deletions
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;