2 .\" Title: ALTER DEFAULT PRIVILEGES
3 .\" Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
6 .\" Manual: PostgreSQL 18.0 Documentation
7 .\" Source: PostgreSQL 18.0
10 .TH "ALTER DEFAULT PRIVILEGES" "7" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 ALTER_DEFAULT_PRIVILEGES \- define default access privileges
35 ALTER DEFAULT PRIVILEGES
36 [ FOR { ROLE | USER } \fItarget_role\fR [, \&.\&.\&.] ]
37 [ IN SCHEMA \fIschema_name\fR [, \&.\&.\&.] ]
38 \fIabbreviated_grant_or_revoke\fR
40 where \fIabbreviated_grant_or_revoke\fR is one of:
42 GRANT { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER | MAINTAIN }
43 [, \&.\&.\&.] | ALL [ PRIVILEGES ] }
45 TO { [ GROUP ] \fIrole_name\fR | PUBLIC } [, \&.\&.\&.] [ WITH GRANT OPTION ]
47 GRANT { { USAGE | SELECT | UPDATE }
48 [, \&.\&.\&.] | ALL [ PRIVILEGES ] }
50 TO { [ GROUP ] \fIrole_name\fR | PUBLIC } [, \&.\&.\&.] [ WITH GRANT OPTION ]
52 GRANT { EXECUTE | ALL [ PRIVILEGES ] }
53 ON { FUNCTIONS | ROUTINES }
54 TO { [ GROUP ] \fIrole_name\fR | PUBLIC } [, \&.\&.\&.] [ WITH GRANT OPTION ]
56 GRANT { USAGE | ALL [ PRIVILEGES ] }
58 TO { [ GROUP ] \fIrole_name\fR | PUBLIC } [, \&.\&.\&.] [ WITH GRANT OPTION ]
60 GRANT { { USAGE | CREATE }
61 [, \&.\&.\&.] | ALL [ PRIVILEGES ] }
63 TO { [ GROUP ] \fIrole_name\fR | PUBLIC } [, \&.\&.\&.] [ WITH GRANT OPTION ]
65 GRANT { { SELECT | UPDATE }
66 [, \&.\&.\&.] | ALL [ PRIVILEGES ] }
68 TO { [ GROUP ] \fIrole_name\fR | PUBLIC } [, \&.\&.\&.] [ WITH GRANT OPTION ]
70 REVOKE [ GRANT OPTION FOR ]
71 { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER | MAINTAIN }
72 [, \&.\&.\&.] | ALL [ PRIVILEGES ] }
74 FROM { [ GROUP ] \fIrole_name\fR | PUBLIC } [, \&.\&.\&.]
75 [ CASCADE | RESTRICT ]
77 REVOKE [ GRANT OPTION FOR ]
78 { { USAGE | SELECT | UPDATE }
79 [, \&.\&.\&.] | ALL [ PRIVILEGES ] }
81 FROM { [ GROUP ] \fIrole_name\fR | PUBLIC } [, \&.\&.\&.]
82 [ CASCADE | RESTRICT ]
84 REVOKE [ GRANT OPTION FOR ]
85 { EXECUTE | ALL [ PRIVILEGES ] }
86 ON { FUNCTIONS | ROUTINES }
87 FROM { [ GROUP ] \fIrole_name\fR | PUBLIC } [, \&.\&.\&.]
88 [ CASCADE | RESTRICT ]
90 REVOKE [ GRANT OPTION FOR ]
91 { USAGE | ALL [ PRIVILEGES ] }
93 FROM { [ GROUP ] \fIrole_name\fR | PUBLIC } [, \&.\&.\&.]
94 [ CASCADE | RESTRICT ]
96 REVOKE [ GRANT OPTION FOR ]
98 [, \&.\&.\&.] | ALL [ PRIVILEGES ] }
100 FROM { [ GROUP ] \fIrole_name\fR | PUBLIC } [, \&.\&.\&.]
101 [ CASCADE | RESTRICT ]
103 REVOKE [ GRANT OPTION FOR ]
104 { { SELECT | UPDATE }
105 [, \&.\&.\&.] | ALL [ PRIVILEGES ] }
107 FROM { [ GROUP ] \fIrole_name\fR | PUBLIC } [, \&.\&.\&.]
108 [ CASCADE | RESTRICT ]
112 \fBALTER DEFAULT PRIVILEGES\fR
113 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\&.) Privileges can be set globally (i\&.e\&., for all objects created in the current database), or just for objects created in specified schemas\&.
115 While you can change your own default privileges and the defaults of roles that you are a member of, at object creation time, new object permissions are only affected by the default privileges of the current role, and are not inherited from any roles in which the current role is a member\&.
118 Section\ \&5.8, the default privileges for any object type normally grant all grantable permissions to the object owner, and may grant some privileges to
120 as well\&. However, this behavior can be changed by altering the global default privileges with
121 \fBALTER DEFAULT PRIVILEGES\fR\&.
123 Currently, only the privileges for schemas, tables (including views and foreign tables), sequences, functions, types (including domains), and large objects can be altered\&. For this command, functions include aggregates and procedures\&. The words
127 are equivalent in this command\&. (ROUTINES
128 is preferred going forward as the standard term for functions and procedures taken together\&. In earlier PostgreSQL releases, only the word
130 was allowed\&. It is not possible to set default privileges for functions and procedures separately\&.)
132 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 previous
133 \fBALTER DEFAULT PRIVILEGES\fR
134 command that did not specify a schema)\&. Per\-schema
136 is only useful to reverse the effects of a previous per\-schema
142 Change default privileges for objects created by the
143 \fItarget_role\fR, or the current role if unspecified\&.
148 The name of an existing schema\&. If specified, the default privileges are altered for objects later created in that schema\&. If
150 is omitted, the global default privileges are altered\&.
152 is not allowed when setting privileges for schemas and large objects, since schemas can\*(Aqt be nested and large objects don\*(Aqt belong to a schema\&.
157 The name of an existing role to grant or revoke privileges for\&. This parameter, and all the other parameters in
158 \fIabbreviated_grant_or_revoke\fR, act as described under
161 \fBREVOKE\fR(7), except that one is setting permissions for a whole class of objects rather than specific named objects\&.
168 command to obtain information about existing assignments of default privileges\&. The meaning of the privilege display is the same as explained for
173 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 use
175 to get rid of the default privileges entry for the role\&.
178 Grant SELECT privilege to everyone for all tables (and views) you subsequently create in schema
179 myschema, and allow role
181 to INSERT into them too:
187 ALTER DEFAULT PRIVILEGES IN SCHEMA myschema GRANT SELECT ON TABLES TO PUBLIC;
188 ALTER DEFAULT PRIVILEGES IN SCHEMA myschema GRANT INSERT ON TABLES TO webuser;
194 Undo the above, so that subsequently\-created tables won\*(Aqt have any more permissions than normal:
200 ALTER DEFAULT PRIVILEGES IN SCHEMA myschema REVOKE SELECT ON TABLES FROM PUBLIC;
201 ALTER DEFAULT PRIVILEGES IN SCHEMA myschema REVOKE INSERT ON TABLES FROM webuser;
207 Remove the public EXECUTE permission that is normally granted on functions, for all functions subsequently created by role
214 ALTER DEFAULT PRIVILEGES FOR ROLE admin REVOKE EXECUTE ON FUNCTIONS FROM PUBLIC;
220 Note however that you
222 accomplish that effect with a command limited to a single schema\&. This command has no effect, unless it is undoing a matching
229 ALTER DEFAULT PRIVILEGES IN SCHEMA public REVOKE EXECUTE ON FUNCTIONS FROM PUBLIC;
235 That\*(Aqs because per\-schema default privileges can only add privileges to the global setting, not remove privileges granted by it\&.
239 \fBALTER DEFAULT PRIVILEGES\fR
240 statement in the SQL standard\&.
242 \fBGRANT\fR(7), \fBREVOKE\fR(7)