]> begriffs open source - ai-pg/blob - full-docs/txt/sql-alterdefaultprivileges.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / sql-alterdefaultprivileges.txt
1
2 ALTER DEFAULT PRIVILEGES
3
4    ALTER DEFAULT PRIVILEGES — define default access privileges
5
6 Synopsis
7
8 ALTER DEFAULT PRIVILEGES
9     [ FOR { ROLE | USER } target_role [, ...] ]
10     [ IN SCHEMA schema_name [, ...] ]
11     abbreviated_grant_or_revoke
12
13 where abbreviated_grant_or_revoke is one of:
14
15 GRANT { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER |
16 MAINTAIN }
17     [, ...] | ALL [ PRIVILEGES ] }
18     ON TABLES
19     TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]
20
21 GRANT { { USAGE | SELECT | UPDATE }
22     [, ...] | ALL [ PRIVILEGES ] }
23     ON SEQUENCES
24     TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]
25
26 GRANT { EXECUTE | ALL [ PRIVILEGES ] }
27     ON { FUNCTIONS | ROUTINES }
28     TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]
29
30 GRANT { USAGE | ALL [ PRIVILEGES ] }
31     ON TYPES
32     TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]
33
34 GRANT { { USAGE | CREATE }
35     [, ...] | ALL [ PRIVILEGES ] }
36     ON SCHEMAS
37     TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]
38
39 GRANT { { SELECT | UPDATE }
40     [, ...] | ALL [ PRIVILEGES ] }
41     ON LARGE OBJECTS
42     TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]
43
44 REVOKE [ GRANT OPTION FOR ]
45     { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER | MA
46 INTAIN }
47     [, ...] | ALL [ PRIVILEGES ] }
48     ON TABLES
49     FROM { [ GROUP ] role_name | PUBLIC } [, ...]
50     [ CASCADE | RESTRICT ]
51
52 REVOKE [ GRANT OPTION FOR ]
53     { { USAGE | SELECT | UPDATE }
54     [, ...] | ALL [ PRIVILEGES ] }
55     ON SEQUENCES
56     FROM { [ GROUP ] role_name | PUBLIC } [, ...]
57     [ CASCADE | RESTRICT ]
58
59 REVOKE [ GRANT OPTION FOR ]
60     { EXECUTE | ALL [ PRIVILEGES ] }
61     ON { FUNCTIONS | ROUTINES }
62     FROM { [ GROUP ] role_name | PUBLIC } [, ...]
63     [ CASCADE | RESTRICT ]
64
65 REVOKE [ GRANT OPTION FOR ]
66     { USAGE | ALL [ PRIVILEGES ] }
67     ON TYPES
68     FROM { [ GROUP ] role_name | PUBLIC } [, ...]
69     [ CASCADE | RESTRICT ]
70
71 REVOKE [ GRANT OPTION FOR ]
72     { { USAGE | CREATE }
73     [, ...] | ALL [ PRIVILEGES ] }
74     ON SCHEMAS
75     FROM { [ GROUP ] role_name | PUBLIC } [, ...]
76     [ CASCADE | RESTRICT ]
77
78 REVOKE [ GRANT OPTION FOR ]
79     { { SELECT | UPDATE }
80     [, ...] | ALL [ PRIVILEGES ] }
81     ON LARGE OBJECTS
82     FROM { [ GROUP ] role_name | PUBLIC } [, ...]
83     [ CASCADE | RESTRICT ]
84
85 Description
86
87    ALTER DEFAULT PRIVILEGES allows you to set the privileges that will be
88    applied to objects created in the future. (It does not affect
89    privileges assigned to already-existing objects.) Privileges can be set
90    globally (i.e., for all objects created in the current database), or
91    just for objects created in specified schemas.
92
93    While you can change your own default privileges and the defaults of
94    roles that you are a member of, at object creation time, new object
95    permissions are only affected by the default privileges of the current
96    role, and are not inherited from any roles in which the current role is
97    a member.
98
99    As explained in Section 5.8, the default privileges for any object type
100    normally grant all grantable permissions to the object owner, and may
101    grant some privileges to PUBLIC as well. However, this behavior can be
102    changed by altering the global default privileges with ALTER DEFAULT
103    PRIVILEGES.
104
105    Currently, only the privileges for schemas, tables (including views and
106    foreign tables), sequences, functions, types (including domains), and
107    large objects can be altered. For this command, functions include
108    aggregates and procedures. The words FUNCTIONS and ROUTINES are
109    equivalent in this command. (ROUTINES is preferred going forward as the
110    standard term for functions and procedures taken together. In earlier
111    PostgreSQL releases, only the word FUNCTIONS was allowed. It is not
112    possible to set default privileges for functions and procedures
113    separately.)
114
115    Default privileges that are specified per-schema are added to whatever
116    the global default privileges are for the particular object type. This
117    means you cannot revoke privileges per-schema if they are granted
118    globally (either by default, or according to a previous ALTER DEFAULT
119    PRIVILEGES command that did not specify a schema). Per-schema REVOKE is
120    only useful to reverse the effects of a previous per-schema GRANT.
121
122 Parameters
123
124    target_role
125           Change default privileges for objects created by the
126           target_role, or the current role if unspecified.
127
128    schema_name
129           The name of an existing schema. If specified, the default
130           privileges are altered for objects later created in that schema.
131           If IN SCHEMA is omitted, the global default privileges are
132           altered. IN SCHEMA is not allowed when setting privileges for
133           schemas and large objects, since schemas can't be nested and
134           large objects don't belong to a schema.
135
136    role_name
137           The name of an existing role to grant or revoke privileges for.
138           This parameter, and all the other parameters in
139           abbreviated_grant_or_revoke, act as described under GRANT or
140           REVOKE, except that one is setting permissions for a whole class
141           of objects rather than specific named objects.
142
143 Notes
144
145    Use psql's \ddp command to obtain information about existing
146    assignments of default privileges. The meaning of the privilege display
147    is the same as explained for \dp in Section 5.8.
148
149    If you wish to drop a role for which the default privileges have been
150    altered, it is necessary to reverse the changes in its default
151    privileges or use DROP OWNED BY to get rid of the default privileges
152    entry for the role.
153
154 Examples
155
156    Grant SELECT privilege to everyone for all tables (and views) you
157    subsequently create in schema myschema, and allow role webuser to
158    INSERT into them too:
159 ALTER DEFAULT PRIVILEGES IN SCHEMA myschema GRANT SELECT ON TABLES TO PUBLIC;
160 ALTER DEFAULT PRIVILEGES IN SCHEMA myschema GRANT INSERT ON TABLES TO webuser;
161
162    Undo the above, so that subsequently-created tables won't have any more
163    permissions than normal:
164 ALTER DEFAULT PRIVILEGES IN SCHEMA myschema REVOKE SELECT ON TABLES FROM PUBLIC;
165 ALTER DEFAULT PRIVILEGES IN SCHEMA myschema REVOKE INSERT ON TABLES FROM webuser
166 ;
167
168    Remove the public EXECUTE permission that is normally granted on
169    functions, for all functions subsequently created by role admin:
170 ALTER DEFAULT PRIVILEGES FOR ROLE admin REVOKE EXECUTE ON FUNCTIONS FROM PUBLIC;
171
172    Note however that you cannot accomplish that effect with a command
173    limited to a single schema. This command has no effect, unless it is
174    undoing a matching GRANT:
175 ALTER DEFAULT PRIVILEGES IN SCHEMA public REVOKE EXECUTE ON FUNCTIONS FROM PUBLI
176 C;
177
178    That's because per-schema default privileges can only add privileges to
179    the global setting, not remove privileges granted by it.
180
181 Compatibility
182
183    There is no ALTER DEFAULT PRIVILEGES statement in the SQL standard.
184
185 See Also
186
187    GRANT, REVOKE