1 /*-------------------------------------------------------------------------
4 * Lock command support code
6 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * $PostgreSQL: pgsql/src/backend/commands/lockcmds.c,v 1.12 2004/12/31 21:59:41 pgsql Exp $
13 *-------------------------------------------------------------------------
17 #include "access/heapam.h"
18 #include "catalog/namespace.h"
19 #include "commands/lockcmds.h"
20 #include "miscadmin.h"
21 #include "utils/acl.h"
22 #include "utils/lsyscache.h"
29 LockTableCommand(LockStmt *lockstmt)
34 * Iterate over the list and open, lock, and close the relations one
38 foreach(p, lockstmt->relations)
40 RangeVar *relation = lfirst(p);
46 * We don't want to open the relation until we've checked
47 * privilege. So, manually get the relation OID.
49 reloid = RangeVarGetRelid(relation, false);
51 if (lockstmt->mode == AccessShareLock)
52 aclresult = pg_class_aclcheck(reloid, GetUserId(),
55 aclresult = pg_class_aclcheck(reloid, GetUserId(),
56 ACL_UPDATE | ACL_DELETE);
58 if (aclresult != ACLCHECK_OK)
59 aclcheck_error(aclresult, ACL_KIND_CLASS,
60 get_rel_name(reloid));
62 rel = conditional_relation_open(reloid, lockstmt->mode, lockstmt->nowait);
64 /* Currently, we only allow plain tables to be locked */
65 if (rel->rd_rel->relkind != RELKIND_RELATION)
67 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
68 errmsg("\"%s\" is not a table",
71 relation_close(rel, NoLock); /* close rel, keep lock */