mirror of
https://github.com/postgres/postgres.git
synced 2025-11-06 07:49:08 +03:00
Mega-commit to make heap_open/heap_openr/heap_close take an
additional argument specifying the kind of lock to acquire/release (or 'NoLock' to do no lock processing). Ensure that all relations are locked with some appropriate lock level before being examined --- this ensures that relevant shared-inval messages have been processed and should prevent problems caused by concurrent VACUUM. Fix several bugs having to do with mismatched increment/decrement of relation ref count and mismatched heap_open/close (which amounts to the same thing). A bogus ref count on a relation doesn't matter much *unless* a SI Inval message happens to arrive at the wrong time, which is probably why we got away with this sloppiness for so long. Repair missing grab of AccessExclusiveLock in DROP TABLE, ALTER/RENAME TABLE, etc, as noted by Hiroshi. Recommend 'make clean all' after pulling this update; I modified the Relation struct layout slightly. Will post further discussion to pghackers list shortly.
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.64 1999/07/16 04:59:55 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.65 1999/09/18 19:07:44 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -165,38 +165,39 @@ ProcessUtility(Node *parsetree,
|
||||
case T_DestroyStmt:
|
||||
{
|
||||
DestroyStmt *stmt = (DestroyStmt *) parsetree;
|
||||
List *arg;
|
||||
List *args = stmt->relNames;
|
||||
Relation rel;
|
||||
List *arg;
|
||||
|
||||
PS_SET_STATUS(commandTag = "DROP");
|
||||
CHECK_IF_ABORTED();
|
||||
|
||||
/* check as much as we can before we start dropping ... */
|
||||
foreach(arg, args)
|
||||
{
|
||||
Relation rel;
|
||||
|
||||
relname = strVal(lfirst(arg));
|
||||
if (!allowSystemTableMods && IsSystemRelationName(relname))
|
||||
elog(ERROR, "class \"%s\" is a system catalog",
|
||||
relname);
|
||||
rel = heap_openr(relname);
|
||||
if (RelationIsValid(rel))
|
||||
{
|
||||
if (stmt->sequence &&
|
||||
rel->rd_rel->relkind != RELKIND_SEQUENCE)
|
||||
elog(ERROR, "Use DROP TABLE to drop table '%s'",
|
||||
relname);
|
||||
if (!(stmt->sequence) &&
|
||||
rel->rd_rel->relkind == RELKIND_SEQUENCE)
|
||||
elog(ERROR, "Use DROP SEQUENCE to drop sequence '%s'",
|
||||
relname);
|
||||
heap_close(rel);
|
||||
}
|
||||
rel = heap_openr(relname, AccessExclusiveLock);
|
||||
if (stmt->sequence &&
|
||||
rel->rd_rel->relkind != RELKIND_SEQUENCE)
|
||||
elog(ERROR, "Use DROP TABLE to drop table '%s'",
|
||||
relname);
|
||||
if (!(stmt->sequence) &&
|
||||
rel->rd_rel->relkind == RELKIND_SEQUENCE)
|
||||
elog(ERROR, "Use DROP SEQUENCE to drop sequence '%s'",
|
||||
relname);
|
||||
/* close rel, but keep lock until end of xact */
|
||||
heap_close(rel, NoLock);
|
||||
#ifndef NO_SECURITY
|
||||
if (!pg_ownercheck(userName, relname, RELNAME))
|
||||
elog(ERROR, "you do not own class \"%s\"",
|
||||
relname);
|
||||
#endif
|
||||
}
|
||||
/* OK, terminate 'em all */
|
||||
foreach(arg, args)
|
||||
{
|
||||
relname = strVal(lfirst(arg));
|
||||
|
||||
Reference in New Issue
Block a user