1ALTER DEFAULT PRIVILEGES(7P)ostgreSQL 10.7 DocumentatiAoLnTER DEFAULT PRIVILEGES(7)
2
3
4

NAME

6       ALTER_DEFAULT_PRIVILEGES - define default access privileges
7

SYNOPSIS

9       ALTER DEFAULT PRIVILEGES
10           [ FOR { ROLE | USER } target_role [, ...] ]
11           [ IN SCHEMA schema_name [, ...] ]
12           abbreviated_grant_or_revoke
13
14       where abbreviated_grant_or_revoke is one of:
15
16       GRANT { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER }
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
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 | ALL [ PRIVILEGES ] }
35           ON SCHEMAS
36           TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]
37
38       REVOKE [ GRANT OPTION FOR ]
39           { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER }
40           [, ...] | ALL [ PRIVILEGES ] }
41           ON TABLES
42           FROM { [ GROUP ] role_name | PUBLIC } [, ...]
43           [ CASCADE | RESTRICT ]
44
45       REVOKE [ GRANT OPTION FOR ]
46           { { USAGE | SELECT | UPDATE }
47           [, ...] | ALL [ PRIVILEGES ] }
48           ON SEQUENCES
49           FROM { [ GROUP ] role_name | PUBLIC } [, ...]
50           [ CASCADE | RESTRICT ]
51
52       REVOKE [ GRANT OPTION FOR ]
53           { EXECUTE | ALL [ PRIVILEGES ] }
54           ON FUNCTIONS
55           FROM { [ GROUP ] role_name | PUBLIC } [, ...]
56           [ CASCADE | RESTRICT ]
57
58       REVOKE [ GRANT OPTION FOR ]
59           { USAGE | ALL [ PRIVILEGES ] }
60           ON TYPES
61           FROM { [ GROUP ] role_name | PUBLIC } [, ...]
62           [ CASCADE | RESTRICT ]
63
64       REVOKE [ GRANT OPTION FOR ]
65           { USAGE | CREATE | ALL [ PRIVILEGES ] }
66           ON SCHEMAS
67           FROM { [ GROUP ] role_name | PUBLIC } [, ...]
68           [ CASCADE | RESTRICT ]
69

DESCRIPTION

71       ALTER DEFAULT PRIVILEGES allows you to set the privileges that will be
72       applied to objects created in the future. (It does not affect
73       privileges assigned to already-existing objects.) Currently, only the
74       privileges for schemas, tables (including views and foreign tables),
75       sequences, functions, and types (including domains) can be altered.
76
77       You can change default privileges only for objects that will be created
78       by yourself or by roles that you are a member of. The privileges can be
79       set globally (i.e., for all objects created in the current database),
80       or just for objects created in specified schemas. Default privileges
81       that are specified per-schema are added to whatever the global default
82       privileges are for the particular object type.
83
84       As explained under GRANT(7), the default privileges for any object type
85       normally grant all grantable permissions to the object owner, and may
86       grant some privileges to PUBLIC as well. However, this behavior can be
87       changed by altering the global default privileges with ALTER DEFAULT
88       PRIVILEGES.
89
90   Parameters
91       target_role
92           The name of an existing role of which the current role is a member.
93           If FOR ROLE is omitted, the current role is assumed.
94
95       schema_name
96           The name of an existing schema. If specified, the default
97           privileges are altered for objects later created in that schema. If
98           IN SCHEMA is omitted, the global default privileges are altered.
99           IN SCHEMA is not allowed when using ON SCHEMAS as schemas can't be
100           nested.
101
102       role_name
103           The name of an existing role to grant or revoke privileges for.
104           This parameter, and all the other parameters in
105           abbreviated_grant_or_revoke, act as described under GRANT(7) or
106           REVOKE(7), except that one is setting permissions for a whole class
107           of objects rather than specific named objects.
108

NOTES

110       Use psql(1)'s \ddp command to obtain information about existing
111       assignments of default privileges. The meaning of the privilege values
112       is the same as explained for \dp under GRANT(7).
113
114       If you wish to drop a role for which the default privileges have been
115       altered, it is necessary to reverse the changes in its default
116       privileges or use DROP OWNED BY to get rid of the default privileges
117       entry for the role.
118

EXAMPLES

120       Grant SELECT privilege to everyone for all tables (and views) you
121       subsequently create in schema myschema, and allow role webuser to
122       INSERT into them too:
123
124           ALTER DEFAULT PRIVILEGES IN SCHEMA myschema GRANT SELECT ON TABLES TO PUBLIC;
125           ALTER DEFAULT PRIVILEGES IN SCHEMA myschema GRANT INSERT ON TABLES TO webuser;
126
127       Undo the above, so that subsequently-created tables won't have any more
128       permissions than normal:
129
130           ALTER DEFAULT PRIVILEGES IN SCHEMA myschema REVOKE SELECT ON TABLES FROM PUBLIC;
131           ALTER DEFAULT PRIVILEGES IN SCHEMA myschema REVOKE INSERT ON TABLES FROM webuser;
132
133       Remove the public EXECUTE permission that is normally granted on
134       functions, for all functions subsequently created by role admin:
135
136           ALTER DEFAULT PRIVILEGES FOR ROLE admin REVOKE EXECUTE ON FUNCTIONS FROM PUBLIC;
137

COMPATIBILITY

139       There is no ALTER DEFAULT PRIVILEGES statement in the SQL standard.
140

SEE ALSO

142       GRANT(7), REVOKE(7)
143
144
145
146PostgreSQL 10.7                      2019          ALTER DEFAULT PRIVILEGES(7)
Impressum