diff options
author | Robert Haas <rhaas@postgresql.org> | 2011-12-21 15:17:28 -0500 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2011-12-21 15:17:28 -0500 |
commit | cbe24a6dd8fb224b9585f25b882d5ffdb55a0ba5 (patch) | |
tree | f0da9150a207733d26be4b99a61cff43fb98a254 /src/backend/commands/tablecmds.c | |
parent | d573e239f03506920938bf0be56c868d9c3416da (diff) | |
download | postgresql-cbe24a6dd8fb224b9585f25b882d5ffdb55a0ba5.tar.gz postgresql-cbe24a6dd8fb224b9585f25b882d5ffdb55a0ba5.zip |
Improve behavior of concurrent CLUSTER.
In the previous coding, a user could queue up for an AccessExclusiveLock
on a table they did not have permission to cluster, thus potentially
interfering with access by authorized users who got stuck waiting behind
the AccessExclusiveLock. This approach avoids that. cluster() has the
same permissions-checking requirements as REINDEX TABLE, so this commit
moves the now-shared callback to tablecmds.c and renames it, per
discussion with Noah Misch.
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r-- | src/backend/commands/tablecmds.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 61689b13386..65a28bfb9a7 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -9933,3 +9933,38 @@ AtEOSubXact_on_commit_actions(bool isCommit, SubTransactionId mySubid, } } } + +/* + * This is intended as a callback for RangeVarGetRelidExtended(). It allows + * the table to be locked only if (1) it's a plain table or TOAST table and + * (2) the current user is the owner (or the superuser). This meets the + * permission-checking needs of both CLUTER and REINDEX TABLE; we expose it + * here so that it can be used by both. + */ +void +RangeVarCallbackOwnsTable(const RangeVar *relation, + Oid relId, Oid oldRelId, void *arg) +{ + char relkind; + + /* Nothing to do if the relation was not found. */ + if (!OidIsValid(relId)) + return; + + /* + * If the relation does exist, check whether it's an index. But note + * that the relation might have been dropped between the time we did the + * name lookup and now. In that case, there's nothing to do. + */ + relkind = get_rel_relkind(relId); + if (!relkind) + return; + if (relkind != RELKIND_RELATION && relkind != RELKIND_TOASTVALUE) + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("\"%s\" is not a table", relation->relname))); + + /* Check permissions */ + if (!pg_class_ownercheck(relId, GetUserId())) + aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS, relation->relname); +} |