2 ALTER DEFAULT PRIVILEGES
4 ALTER DEFAULT PRIVILEGES — define default access privileges
8 ALTER DEFAULT PRIVILEGES
9 [ FOR { ROLE | USER } target_role [, ...] ]
10 [ IN SCHEMA schema_name [, ...] ]
11 abbreviated_grant_or_revoke
13 where abbreviated_grant_or_revoke is one of:
15 GRANT { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER |
17 [, ...] | ALL [ PRIVILEGES ] }
19 TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]
21 GRANT { { USAGE | SELECT | UPDATE }
22 [, ...] | ALL [ PRIVILEGES ] }
24 TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]
26 GRANT { EXECUTE | ALL [ PRIVILEGES ] }
27 ON { FUNCTIONS | ROUTINES }
28 TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]
30 GRANT { USAGE | ALL [ PRIVILEGES ] }
32 TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]
34 GRANT { { USAGE | CREATE }
35 [, ...] | ALL [ PRIVILEGES ] }
37 TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]
39 GRANT { { SELECT | UPDATE }
40 [, ...] | ALL [ PRIVILEGES ] }
42 TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]
44 REVOKE [ GRANT OPTION FOR ]
45 { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER | MA
47 [, ...] | ALL [ PRIVILEGES ] }
49 FROM { [ GROUP ] role_name | PUBLIC } [, ...]
50 [ CASCADE | RESTRICT ]
52 REVOKE [ GRANT OPTION FOR ]
53 { { USAGE | SELECT | UPDATE }
54 [, ...] | ALL [ PRIVILEGES ] }
56 FROM { [ GROUP ] role_name | PUBLIC } [, ...]
57 [ CASCADE | RESTRICT ]
59 REVOKE [ GRANT OPTION FOR ]
60 { EXECUTE | ALL [ PRIVILEGES ] }
61 ON { FUNCTIONS | ROUTINES }
62 FROM { [ GROUP ] role_name | PUBLIC } [, ...]
63 [ CASCADE | RESTRICT ]
65 REVOKE [ GRANT OPTION FOR ]
66 { USAGE | ALL [ PRIVILEGES ] }
68 FROM { [ GROUP ] role_name | PUBLIC } [, ...]
69 [ CASCADE | RESTRICT ]
71 REVOKE [ GRANT OPTION FOR ]
73 [, ...] | ALL [ PRIVILEGES ] }
75 FROM { [ GROUP ] role_name | PUBLIC } [, ...]
76 [ CASCADE | RESTRICT ]
78 REVOKE [ GRANT OPTION FOR ]
80 [, ...] | ALL [ PRIVILEGES ] }
82 FROM { [ GROUP ] role_name | PUBLIC } [, ...]
83 [ CASCADE | RESTRICT ]
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.
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
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
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
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.
125 Change default privileges for objects created by the
126 target_role, or the current role if unspecified.
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.
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.
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.
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
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;
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
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;
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
178 That's because per-schema default privileges can only add privileges to
179 the global setting, not remove privileges granted by it.
183 There is no ALTER DEFAULT PRIVILEGES statement in the SQL standard.