2 doc/src/sgml/ref/alter_default_privileges.sgml
3 PostgreSQL documentation
6 <refentry id="SQL-ALTERDEFAULTPRIVILEGES">
8 <refentrytitle>ALTER DEFAULT PRIVILEGES</refentrytitle>
9 <manvolnum>7</manvolnum>
10 <refmiscinfo>SQL - Language Statements</refmiscinfo>
14 <refname>ALTER DEFAULT PRIVILEGES</refname>
15 <refpurpose>define default access privileges</refpurpose>
18 <indexterm zone="sql-alterdefaultprivileges">
19 <primary>ALTER DEFAULT PRIVILEGES</primary>
24 ALTER DEFAULT PRIVILEGES
25 [ FOR { ROLE | USER } <replaceable>target_role</replaceable> [, ...] ]
26 [ IN SCHEMA <replaceable>schema_name</replaceable> [, ...] ]
27 <replaceable class="parameter">abbreviated_grant_or_revoke</replaceable>
29 <phrase>where <replaceable class="parameter">abbreviated_grant_or_revoke</replaceable> is one of:</phrase>
31 GRANT { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER }
32 [, ...] | ALL [ PRIVILEGES ] }
34 TO { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...] [ WITH GRANT OPTION ]
36 GRANT { { USAGE | SELECT | UPDATE }
37 [, ...] | ALL [ PRIVILEGES ] }
39 TO { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...] [ WITH GRANT OPTION ]
41 GRANT { EXECUTE | ALL [ PRIVILEGES ] }
43 TO { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...] [ WITH GRANT OPTION ]
45 REVOKE [ GRANT OPTION FOR ]
46 { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER }
47 [, ...] | ALL [ PRIVILEGES ] }
49 FROM { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...]
50 [ CASCADE | RESTRICT ]
52 REVOKE [ GRANT OPTION FOR ]
53 { { USAGE | SELECT | UPDATE }
54 [, ...] | ALL [ PRIVILEGES ] }
56 FROM { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...]
57 [ CASCADE | RESTRICT ]
59 REVOKE [ GRANT OPTION FOR ]
60 { EXECUTE | ALL [ PRIVILEGES ] }
62 FROM { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...]
63 [ CASCADE | RESTRICT ]
67 <refsect1 id="sql-alterdefaultprivileges-description">
68 <title>Description</title>
71 <command>ALTER DEFAULT PRIVILEGES</> allows you to set the privileges
72 that will be applied to objects created in the future. (It does not
73 affect privileges assigned to already-existing objects.) Currently,
74 only the privileges for tables (including views and foreign tables),
75 sequences, and functions can be altered.
79 You can change default privileges only for objects that will be created by
80 yourself or by roles that you are a member of. The privileges can be set
81 globally (i.e., for all objects created in the current database),
82 or just for objects created in specified schemas. Default privileges
83 that are specified per-schema are added to whatever the global default
84 privileges are for the particular object type.
88 As explained under <xref linkend="sql-grant">,
89 the default privileges for any object type normally grant all grantable
90 permissions to the object owner, and may grant some privileges to
91 <literal>PUBLIC</> as well. However, this behavior can be changed by
92 altering the global default privileges with
93 <command>ALTER DEFAULT PRIVILEGES</>.
97 <title>Parameters</title>
101 <term><replaceable>target_role</replaceable></term>
104 The name of an existing role of which the current role is a member.
105 If <literal>FOR ROLE</> is omitted, the current role is assumed.
111 <term><replaceable>schema_name</replaceable></term>
114 The name of an existing schema. Each <replaceable>target_role</>
115 must have <literal>CREATE</> privileges for each specified schema.
116 If <literal>IN SCHEMA</> is omitted, the global default privileges
123 <term><replaceable>role_name</replaceable></term>
126 The name of an existing role to grant or revoke privileges for.
127 This parameter, and all the other parameters in
128 <replaceable class="parameter">abbreviated_grant_or_revoke</>,
129 act as described under
130 <xref linkend="sql-grant"> or
131 <xref linkend="sql-revoke">,
132 except that one is setting permissions for a whole class of objects
133 rather than specific named objects.
141 <refsect1 id="sql-alterdefaultprivileges-notes">
145 Use <xref linkend="app-psql">'s <command>\ddp</command> command
146 to obtain information about existing assignments of default privileges.
147 The meaning of the privilege values is the same as explained for
148 <command>\dp</command> under
149 <xref linkend="sql-grant">.
153 If you wish to drop a role for which the default privileges have been
154 altered, it is necessary to reverse the changes in its default privileges
155 or use <command>DROP OWNED BY</> to get rid of the default privileges entry
160 <refsect1 id="sql-alterdefaultprivileges-examples">
161 <title>Examples</title>
164 Grant SELECT privilege to everyone for all tables (and views) you
165 subsequently create in schema <literal>myschema</literal>, and allow
166 role <literal>webuser</> to INSERT into them too:
169 ALTER DEFAULT PRIVILEGES IN SCHEMA myschema GRANT SELECT ON TABLES TO PUBLIC;
170 ALTER DEFAULT PRIVILEGES IN SCHEMA myschema GRANT INSERT ON TABLES TO webuser;
175 Undo the above, so that subsequently-created tables won't have any
176 more permissions than normal:
179 ALTER DEFAULT PRIVILEGES IN SCHEMA myschema REVOKE SELECT ON TABLES FROM PUBLIC;
180 ALTER DEFAULT PRIVILEGES IN SCHEMA myschema REVOKE INSERT ON TABLES FROM webuser;
185 Remove the public EXECUTE permission that is normally granted on functions,
186 for all functions subsequently created by role <literal>admin</>:
189 ALTER DEFAULT PRIVILEGES FOR ROLE admin REVOKE EXECUTE ON FUNCTIONS FROM PUBLIC;
190 </programlisting></para>
194 <title>Compatibility</title>
197 There is no <command>ALTER DEFAULT PRIVILEGES</command> statement in the SQL
203 <title>See Also</title>
205 <simplelist type="inline">
206 <member><xref linkend="sql-grant"></member>
207 <member><xref linkend="sql-revoke"></member>