]> granicus.if.org Git - postgresql/blob - doc/src/sgml/ref/alter_default_privileges.sgml
Create a "sort support" interface API for faster sorting.
[postgresql] / doc / src / sgml / ref / alter_default_privileges.sgml
1 <!--
2 doc/src/sgml/ref/alter_default_privileges.sgml
3 PostgreSQL documentation
4 -->
5
6 <refentry id="SQL-ALTERDEFAULTPRIVILEGES">
7  <refmeta>
8   <refentrytitle>ALTER DEFAULT PRIVILEGES</refentrytitle>
9   <manvolnum>7</manvolnum>
10   <refmiscinfo>SQL - Language Statements</refmiscinfo>
11  </refmeta>
12
13  <refnamediv>
14   <refname>ALTER DEFAULT PRIVILEGES</refname>
15   <refpurpose>define default access privileges</refpurpose>
16  </refnamediv>
17
18  <indexterm zone="sql-alterdefaultprivileges">
19   <primary>ALTER DEFAULT PRIVILEGES</primary>
20  </indexterm>
21
22  <refsynopsisdiv>
23 <synopsis>
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>
28
29 <phrase>where <replaceable class="parameter">abbreviated_grant_or_revoke</replaceable> is one of:</phrase>
30
31 GRANT { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER }
32     [, ...] | ALL [ PRIVILEGES ] }
33     ON TABLES
34     TO { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...] [ WITH GRANT OPTION ]
35
36 GRANT { { USAGE | SELECT | UPDATE }
37     [, ...] | ALL [ PRIVILEGES ] }
38     ON SEQUENCES
39     TO { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...] [ WITH GRANT OPTION ]
40
41 GRANT { EXECUTE | ALL [ PRIVILEGES ] }
42     ON FUNCTIONS
43     TO { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...] [ WITH GRANT OPTION ]
44
45 REVOKE [ GRANT OPTION FOR ]
46     { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER }
47     [, ...] | ALL [ PRIVILEGES ] }
48     ON TABLES
49     FROM { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...]
50     [ CASCADE | RESTRICT ]
51
52 REVOKE [ GRANT OPTION FOR ]
53     { { USAGE | SELECT | UPDATE }
54     [, ...] | ALL [ PRIVILEGES ] }
55     ON SEQUENCES
56     FROM { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...]
57     [ CASCADE | RESTRICT ]
58
59 REVOKE [ GRANT OPTION FOR ]
60     { EXECUTE | ALL [ PRIVILEGES ] }
61     ON FUNCTIONS
62     FROM { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...]
63     [ CASCADE | RESTRICT ]
64 </synopsis>
65  </refsynopsisdiv>
66
67  <refsect1 id="sql-alterdefaultprivileges-description">
68   <title>Description</title>
69
70   <para>
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.
76   </para>
77
78   <para>
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.
85   </para>
86
87   <para>
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</>.
94   </para>
95
96  <refsect2>
97   <title>Parameters</title>
98
99   <variablelist>
100    <varlistentry>
101     <term><replaceable>target_role</replaceable></term>
102     <listitem>
103      <para>
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.
106      </para>
107     </listitem>
108    </varlistentry>
109
110    <varlistentry>
111     <term><replaceable>schema_name</replaceable></term>
112     <listitem>
113      <para>
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
117       are altered.
118      </para>
119     </listitem>
120    </varlistentry>
121
122    <varlistentry>
123     <term><replaceable>role_name</replaceable></term>
124     <listitem>
125      <para>
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.
134      </para>
135     </listitem>
136    </varlistentry>
137   </variablelist>
138  </refsect2>
139  </refsect1>
140
141  <refsect1 id="sql-alterdefaultprivileges-notes">
142   <title>Notes</title>
143
144   <para>
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">.
150   </para>
151
152   <para>
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
156    for the role.
157   </para>
158  </refsect1>
159
160  <refsect1 id="sql-alterdefaultprivileges-examples">
161   <title>Examples</title>
162
163   <para>
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:
167
168 <programlisting>
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;
171 </programlisting>
172   </para>
173
174   <para>
175    Undo the above, so that subsequently-created tables won't have any
176    more permissions than normal:
177
178 <programlisting>
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;
181 </programlisting>
182   </para>
183
184   <para>
185    Remove the public EXECUTE permission that is normally granted on functions,
186    for all functions subsequently created by role <literal>admin</>:
187
188 <programlisting>
189 ALTER DEFAULT PRIVILEGES FOR ROLE admin REVOKE EXECUTE ON FUNCTIONS FROM PUBLIC;
190 </programlisting></para>
191  </refsect1>
192
193  <refsect1>
194   <title>Compatibility</title>
195
196   <para>
197    There is no <command>ALTER DEFAULT PRIVILEGES</command> statement in the SQL
198    standard.
199   </para>
200  </refsect1>
201
202  <refsect1>
203   <title>See Also</title>
204
205   <simplelist type="inline">
206    <member><xref linkend="sql-grant"></member>
207    <member><xref linkend="sql-revoke"></member>
208   </simplelist>
209  </refsect1>
210
211 </refentry>