postgres.git / summary / log / commit / refs

commit    86e58ae023a93e778cec195b19ffe7ccb01f7038
Author:   Stephen Frost <sfrost@snowman.net>
Date:     Sat Jan 18 23:41:52 2014 +0000
First released in: 9.4.0, 8.4.20, 9.0.16, 9.1.12, 9.2.7, 9.3.3

    Allow SET TABLESPACE to database default
    
    We've always allowed CREATE TABLE to create tables in the database's default
    tablespace without checking for CREATE permissions on that tablespace.
    Unfortunately, the original implementation of ALTER TABLE ... SET TABLESPACE
    didn't pick up on that exception.
    
    This changes ALTER TABLE ... SET TABLESPACE to allow the database's default
    tablespace without checking for CREATE rights on that tablespace, just as
    CREATE TABLE works today.  Users could always do this through a series of
    commands (CREATE TABLE ... AS SELECT * FROM ...; DROP TABLE ...; etc), so
    let's fix the oversight in SET TABLESPACE's original implementation.


src/backend/commands/tablecmds.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 6631be8eeb4..c0cbd970e3b 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8534,21 +8534,26 @@ static void ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, char *tablespacename, LOCKMODE lockmode) { Oid tablespaceId; - AclResult aclresult; /* Check that the tablespace exists */ tablespaceId = get_tablespace_oid(tablespacename, false); - /* Check its permissions */ - aclresult = pg_tablespace_aclcheck(tablespaceId, GetUserId(), ACL_CREATE); - if (aclresult != ACLCHECK_OK) - aclcheck_error(aclresult, ACL_KIND_TABLESPACE, tablespacename); + /* Check permissions except when moving to database's default */ + if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) + { + AclResult aclresult; + + aclresult = pg_tablespace_aclcheck(tablespaceId, GetUserId(), ACL_CREATE); + if (aclresult != ACLCHECK_OK) + aclcheck_error(aclresult, ACL_KIND_TABLESPACE, tablespacename); + } /* Save info for Phase 3 to do the real work */ if (OidIsValid(tab->newTableSpace)) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("cannot have multiple SET TABLESPACE subcommands"))); + tab->newTableSpace = tablespaceId; } [parent: 586bea6124cd]