]> granicus.if.org Git - postgresql/blob - doc/src/sgml/ref/alter_default_privileges.sgml
Add support for piping COPY to/from an external program.
[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 GRANT { USAGE | ALL [ PRIVILEGES ] }
46     ON TYPES
47     TO { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...] [ WITH GRANT OPTION ]
48
49 REVOKE [ GRANT OPTION FOR ]
50     { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER }
51     [, ...] | ALL [ PRIVILEGES ] }
52     ON TABLES
53     FROM { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...]
54     [ CASCADE | RESTRICT ]
55
56 REVOKE [ GRANT OPTION FOR ]
57     { { USAGE | SELECT | UPDATE }
58     [, ...] | ALL [ PRIVILEGES ] }
59     ON SEQUENCES
60     FROM { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...]
61     [ CASCADE | RESTRICT ]
62
63 REVOKE [ GRANT OPTION FOR ]
64     { EXECUTE | ALL [ PRIVILEGES ] }
65     ON FUNCTIONS
66     FROM { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...]
67     [ CASCADE | RESTRICT ]
68
69 REVOKE [ GRANT OPTION FOR ]
70     { USAGE | ALL [ PRIVILEGES ] }
71     ON TYPES
72     FROM { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...]
73     [ CASCADE | RESTRICT ]
74 </synopsis>
75  </refsynopsisdiv>
76
77  <refsect1 id="sql-alterdefaultprivileges-description">
78   <title>Description</title>
79
80   <para>
81    <command>ALTER DEFAULT PRIVILEGES</> allows you to set the privileges
82    that will be applied to objects created in the future.  (It does not
83    affect privileges assigned to already-existing objects.)  Currently,
84    only the privileges for tables (including views and foreign tables),
85    sequences, functions, and types (including domains) can be altered.
86   </para>
87
88   <para>
89    You can change default privileges only for objects that will be created by
90    yourself or by roles that you are a member of.  The privileges can be set
91    globally (i.e., for all objects created in the current database),
92    or just for objects created in specified schemas.  Default privileges
93    that are specified per-schema are added to whatever the global default
94    privileges are for the particular object type.
95   </para>
96
97   <para>
98    As explained under <xref linkend="sql-grant">,
99    the default privileges for any object type normally grant all grantable
100    permissions to the object owner, and may grant some privileges to
101    <literal>PUBLIC</> as well.  However, this behavior can be changed by
102    altering the global default privileges with
103    <command>ALTER DEFAULT PRIVILEGES</>.
104   </para>
105
106  <refsect2>
107   <title>Parameters</title>
108
109   <variablelist>
110    <varlistentry>
111     <term><replaceable>target_role</replaceable></term>
112     <listitem>
113      <para>
114       The name of an existing role of which the current role is a member.
115       If <literal>FOR ROLE</> is omitted, the current role is assumed.
116      </para>
117     </listitem>
118    </varlistentry>
119
120    <varlistentry>
121     <term><replaceable>schema_name</replaceable></term>
122     <listitem>
123      <para>
124       The name of an existing schema.  Each <replaceable>target_role</>
125       must have <literal>CREATE</> privileges for each specified schema.
126       If <literal>IN SCHEMA</> is omitted, the global default privileges
127       are altered.
128      </para>
129     </listitem>
130    </varlistentry>
131
132    <varlistentry>
133     <term><replaceable>role_name</replaceable></term>
134     <listitem>
135      <para>
136       The name of an existing role to grant or revoke privileges for.
137       This parameter, and all the other parameters in
138       <replaceable class="parameter">abbreviated_grant_or_revoke</>,
139       act as described under
140       <xref linkend="sql-grant"> or
141       <xref linkend="sql-revoke">,
142       except that one is setting permissions for a whole class of objects
143       rather than specific named objects.
144      </para>
145     </listitem>
146    </varlistentry>
147   </variablelist>
148  </refsect2>
149  </refsect1>
150
151  <refsect1 id="sql-alterdefaultprivileges-notes">
152   <title>Notes</title>
153
154   <para>
155    Use <xref linkend="app-psql">'s <command>\ddp</command> command
156    to obtain information about existing assignments of default privileges.
157    The meaning of the privilege values is the same as explained for
158    <command>\dp</command> under
159    <xref linkend="sql-grant">.
160   </para>
161
162   <para>
163    If you wish to drop a role for which the default privileges have been
164    altered, it is necessary to reverse the changes in its default privileges
165    or use <command>DROP OWNED BY</> to get rid of the default privileges entry
166    for the role.
167   </para>
168  </refsect1>
169
170  <refsect1 id="sql-alterdefaultprivileges-examples">
171   <title>Examples</title>
172
173   <para>
174    Grant SELECT privilege to everyone for all tables (and views) you
175    subsequently create in schema <literal>myschema</literal>, and allow
176    role <literal>webuser</> to INSERT into them too:
177
178 <programlisting>
179 ALTER DEFAULT PRIVILEGES IN SCHEMA myschema GRANT SELECT ON TABLES TO PUBLIC;
180 ALTER DEFAULT PRIVILEGES IN SCHEMA myschema GRANT INSERT ON TABLES TO webuser;
181 </programlisting>
182   </para>
183
184   <para>
185    Undo the above, so that subsequently-created tables won't have any
186    more permissions than normal:
187
188 <programlisting>
189 ALTER DEFAULT PRIVILEGES IN SCHEMA myschema REVOKE SELECT ON TABLES FROM PUBLIC;
190 ALTER DEFAULT PRIVILEGES IN SCHEMA myschema REVOKE INSERT ON TABLES FROM webuser;
191 </programlisting>
192   </para>
193
194   <para>
195    Remove the public EXECUTE permission that is normally granted on functions,
196    for all functions subsequently created by role <literal>admin</>:
197
198 <programlisting>
199 ALTER DEFAULT PRIVILEGES FOR ROLE admin REVOKE EXECUTE ON FUNCTIONS FROM PUBLIC;
200 </programlisting></para>
201  </refsect1>
202
203  <refsect1>
204   <title>Compatibility</title>
205
206   <para>
207    There is no <command>ALTER DEFAULT PRIVILEGES</command> statement in the SQL
208    standard.
209   </para>
210  </refsect1>
211
212  <refsect1>
213   <title>See Also</title>
214
215   <simplelist type="inline">
216    <member><xref linkend="sql-grant"></member>
217    <member><xref linkend="sql-revoke"></member>
218   </simplelist>
219  </refsect1>
220
221 </refentry>