Movatterモバイル変換


[0]ホーム

URL:



Facebook
Postgres Pro
Facebook
Downloads
ALTER DEFAULT PRIVILEGES
Prev UpSQL CommandsHome Next

ALTER DEFAULT PRIVILEGES

ALTER DEFAULT PRIVILEGES — define default access privileges

Synopsis

ALTER DEFAULT PRIVILEGES    [ FOR { ROLE | USER }target_role [, ...] ]    [ IN SCHEMAschema_name [, ...] ]abbreviated_grant_or_revokewhereabbreviated_grant_or_revoke is one of:GRANT { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER }    [, ...] | ALL [ PRIVILEGES ] }    ON TABLES    TO { [ GROUP ]role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]GRANT { { USAGE | SELECT | UPDATE }    [, ...] | ALL [ PRIVILEGES ] }    ON SEQUENCES    TO { [ GROUP ]role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]GRANT { EXECUTE | ALL [ PRIVILEGES ] }    ON FUNCTIONS    TO { [ GROUP ]role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]GRANT { USAGE | ALL [ PRIVILEGES ] }    ON TYPES    TO { [ GROUP ]role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]GRANT { USAGE | CREATE | ALL [ PRIVILEGES ] }    ON SCHEMAS    TO { [ GROUP ]role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]REVOKE [ GRANT OPTION FOR ]    { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER }    [, ...] | ALL [ PRIVILEGES ] }    ON TABLES    FROM { [ GROUP ]role_name | PUBLIC } [, ...]    [ CASCADE | RESTRICT ]REVOKE [ GRANT OPTION FOR ]    { { USAGE | SELECT | UPDATE }    [, ...] | ALL [ PRIVILEGES ] }    ON SEQUENCES    FROM { [ GROUP ]role_name | PUBLIC } [, ...]    [ CASCADE | RESTRICT ]REVOKE [ GRANT OPTION FOR ]    { EXECUTE | ALL [ PRIVILEGES ] }    ON FUNCTIONS    FROM { [ GROUP ]role_name | PUBLIC } [, ...]    [ CASCADE | RESTRICT ]REVOKE [ GRANT OPTION FOR ]    { USAGE | ALL [ PRIVILEGES ] }    ON TYPES    FROM { [ GROUP ]role_name | PUBLIC } [, ...]    [ CASCADE | RESTRICT ]REVOKE [ GRANT OPTION FOR ]    { USAGE | CREATE | ALL [ PRIVILEGES ] }    ON SCHEMAS    FROM { [ GROUP ]role_name | PUBLIC } [, ...]    [ CASCADE | RESTRICT ]

Description

ALTER DEFAULT PRIVILEGES allows you to set the privileges that will be applied to objects created in the future. (It does not affect privileges assigned to already-existing objects.) Currently, only the privileges for schemas, tables (including views and foreign tables), sequences, functions, and types (including domains) can be altered.

You can change default privileges only for objects that will be created by yourself or by roles that you are a member of. The privileges can be set globally (i.e., for all objects created in the current database), or just for objects created in specified schemas.

As explained underGRANT, the default privileges for any object type normally grant all grantable permissions to the object owner, and may grant some privileges toPUBLIC as well. However, this behavior can be changed by altering the global default privileges withALTER DEFAULT PRIVILEGES.

Default privileges that are specified per-schema are added to whatever the global default privileges are for the particular object type. This means you cannot revoke privileges per-schema if they are granted globally (either by default, or according to a previousALTER DEFAULT PRIVILEGES command that did not specify a schema). Per-schemaREVOKE is only useful to reverse the effects of a previous per-schemaGRANT.

Parameters

target_role

The name of an existing role of which the current role is a member. IfFOR ROLE is omitted, the current role is assumed.

schema_name

The name of an existing schema. If specified, the default privileges are altered for objects later created in that schema. IfIN SCHEMA is omitted, the global default privileges are altered.IN SCHEMA is not allowed when setting privileges for schemas, since schemas can't be nested.

role_name

The name of an existing role to grant or revoke privileges for. This parameter, and all the other parameters inabbreviated_grant_or_revoke, act as described underGRANT orREVOKE, except that one is setting permissions for a whole class of objects rather than specific named objects.

Notes

Usepsql's\ddp command to obtain information about existing assignments of default privileges. The meaning of the privilege values is the same as explained for\dp underGRANT.

If you wish to drop a role for which the default privileges have been altered, it is necessary to reverse the changes in its default privileges or useDROP OWNED BY to get rid of the default privileges entry for the role.

Examples

Grant SELECT privilege to everyone for all tables (and views) you subsequently create in schemamyschema, and allow rolewebuser to INSERT into them too:

ALTER DEFAULT PRIVILEGES IN SCHEMA myschema GRANT SELECT ON TABLES TO PUBLIC;ALTER DEFAULT PRIVILEGES IN SCHEMA myschema GRANT INSERT ON TABLES TO webuser;

Undo the above, so that subsequently-created tables won't have any more permissions than normal:

ALTER DEFAULT PRIVILEGES IN SCHEMA myschema REVOKE SELECT ON TABLES FROM PUBLIC;ALTER DEFAULT PRIVILEGES IN SCHEMA myschema REVOKE INSERT ON TABLES FROM webuser;

Remove the public EXECUTE permission that is normally granted on functions, for all functions subsequently created by roleadmin:

ALTER DEFAULT PRIVILEGES FOR ROLE admin REVOKE EXECUTE ON FUNCTIONS FROM PUBLIC;

Note however that youcannot accomplish that effect with a command limited to a single schema. This command has no effect, unless it is undoing a matchingGRANT:

ALTER DEFAULT PRIVILEGES IN SCHEMA public REVOKE EXECUTE ON FUNCTIONS FROM PUBLIC;

That's because per-schema default privileges can only add privileges to the global setting, not remove privileges granted by it.

Compatibility

There is noALTER DEFAULT PRIVILEGES statement in the SQL standard.

See Also

GRANT,REVOKE

Prev Up Next
ALTER DATABASE Home ALTER DOMAIN
epubpdf
Go to Postgres Pro Enterprise 10
By continuing to browse this website, you agree to the use of cookies. Go toPrivacy Policy.

[8]ページ先頭

©2009-2025 Movatter.jp