From: Tom Lane Date: Thu, 2 Oct 2003 23:19:44 +0000 (+0000) Subject: Add a bit more locking to vac_update_relstats and vac_update_dbstats X-Git-Url: http://waps.l3s.uni-hannover.de/gitweb/?a=commitdiff_plain;h=c370c7715abf79add510a3245f995dca447ce09a;p=users%2Fbernd%2Fpostgres.git Add a bit more locking to vac_update_relstats and vac_update_dbstats to make them comparable to what UpdateStats does in the same situation. I'm not certain two instances of vac_update_relstats could run in parallel for the same relation, but parallel invocations of vac_update_dbstats do seem possible. --- diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index 8e40932a54..146f28272b 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -520,6 +520,9 @@ vac_update_relstats(Oid relid, BlockNumber num_pages, double num_tuples, elog(ERROR, "pg_class entry for relid %u vanished during vacuuming", relid); + /* ensure no one else does this at the same time */ + LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE); + /* overwrite the existing statistics in the tuple */ pgcform = (Form_pg_class) GETSTRUCT(&rtup); pgcform->relpages = (int32) num_pages; @@ -533,6 +536,8 @@ vac_update_relstats(Oid relid, BlockNumber num_pages, double num_tuples, if (!hasindex) pgcform->relhaspkey = false; + LockBuffer(buffer, BUFFER_LOCK_UNLOCK); + /* * Invalidate the tuple in the catcaches; this also arranges to flush * the relation's relcache entry. (If we fail to commit for some @@ -588,12 +593,17 @@ vac_update_dbstats(Oid dbid, if (!HeapTupleIsValid(tuple)) elog(ERROR, "could not find tuple for database %u", dbid); + /* ensure no one else does this at the same time */ + LockBuffer(scan->rs_cbuf, BUFFER_LOCK_EXCLUSIVE); + dbform = (Form_pg_database) GETSTRUCT(tuple); /* overwrite the existing statistics in the tuple */ dbform->datvacuumxid = vacuumXID; dbform->datfrozenxid = frozenXID; + LockBuffer(scan->rs_cbuf, BUFFER_LOCK_UNLOCK); + /* invalidate the tuple in the cache and write the buffer */ CacheInvalidateHeapTuple(relation, tuple); WriteNoReleaseBuffer(scan->rs_cbuf);