]> begriffs open source - ai-pg/blob - full-docs/src/sgml/html/sql-revoke.html
WIP: toc builder
[ai-pg] / full-docs / src / sgml / html / sql-revoke.html
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>REVOKE</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="sql-reset.html" title="RESET" /><link rel="next" href="sql-rollback.html" title="ROLLBACK" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">REVOKE</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-reset.html" title="RESET">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><th width="60%" align="center">SQL Commands</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="sql-rollback.html" title="ROLLBACK">Next</a></td></tr></table><hr /></div><div class="refentry" id="SQL-REVOKE"><div class="titlepage"></div><a id="id-1.9.3.166.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">REVOKE</span></h2><p>REVOKE — remove access privileges</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
3 REVOKE [ GRANT OPTION FOR ]
4     { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER | MAINTAIN }
5     [, ...] | ALL [ PRIVILEGES ] }
6     ON { [ TABLE ] <em class="replaceable"><code>table_name</code></em> [, ...]
7          | ALL TABLES IN SCHEMA <em class="replaceable"><code>schema_name</code></em> [, ...] }
8     FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
9     [ GRANTED BY <em class="replaceable"><code>role_specification</code></em> ]
10     [ CASCADE | RESTRICT ]
11
12 REVOKE [ GRANT OPTION FOR ]
13     { { SELECT | INSERT | UPDATE | REFERENCES } ( <em class="replaceable"><code>column_name</code></em> [, ...] )
14     [, ...] | ALL [ PRIVILEGES ] ( <em class="replaceable"><code>column_name</code></em> [, ...] ) }
15     ON [ TABLE ] <em class="replaceable"><code>table_name</code></em> [, ...]
16     FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
17     [ GRANTED BY <em class="replaceable"><code>role_specification</code></em> ]
18     [ CASCADE | RESTRICT ]
19
20 REVOKE [ GRANT OPTION FOR ]
21     { { USAGE | SELECT | UPDATE }
22     [, ...] | ALL [ PRIVILEGES ] }
23     ON { SEQUENCE <em class="replaceable"><code>sequence_name</code></em> [, ...]
24          | ALL SEQUENCES IN SCHEMA <em class="replaceable"><code>schema_name</code></em> [, ...] }
25     FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
26     [ GRANTED BY <em class="replaceable"><code>role_specification</code></em> ]
27     [ CASCADE | RESTRICT ]
28
29 REVOKE [ GRANT OPTION FOR ]
30     { { CREATE | CONNECT | TEMPORARY | TEMP } [, ...] | ALL [ PRIVILEGES ] }
31     ON DATABASE <em class="replaceable"><code>database_name</code></em> [, ...]
32     FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
33     [ GRANTED BY <em class="replaceable"><code>role_specification</code></em> ]
34     [ CASCADE | RESTRICT ]
35
36 REVOKE [ GRANT OPTION FOR ]
37     { USAGE | ALL [ PRIVILEGES ] }
38     ON DOMAIN <em class="replaceable"><code>domain_name</code></em> [, ...]
39     FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
40     [ GRANTED BY <em class="replaceable"><code>role_specification</code></em> ]
41     [ CASCADE | RESTRICT ]
42
43 REVOKE [ GRANT OPTION FOR ]
44     { USAGE | ALL [ PRIVILEGES ] }
45     ON FOREIGN DATA WRAPPER <em class="replaceable"><code>fdw_name</code></em> [, ...]
46     FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
47     [ GRANTED BY <em class="replaceable"><code>role_specification</code></em> ]
48     [ CASCADE | RESTRICT ]
49
50 REVOKE [ GRANT OPTION FOR ]
51     { USAGE | ALL [ PRIVILEGES ] }
52     ON FOREIGN SERVER <em class="replaceable"><code>server_name</code></em> [, ...]
53     FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
54     [ GRANTED BY <em class="replaceable"><code>role_specification</code></em> ]
55     [ CASCADE | RESTRICT ]
56
57 REVOKE [ GRANT OPTION FOR ]
58     { EXECUTE | ALL [ PRIVILEGES ] }
59     ON { { FUNCTION | PROCEDURE | ROUTINE } <em class="replaceable"><code>function_name</code></em> [ ( [ [ <em class="replaceable"><code>argmode</code></em> ] [ <em class="replaceable"><code>arg_name</code></em> ] <em class="replaceable"><code>arg_type</code></em> [, ...] ] ) ] [, ...]
60          | ALL { FUNCTIONS | PROCEDURES | ROUTINES } IN SCHEMA <em class="replaceable"><code>schema_name</code></em> [, ...] }
61     FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
62     [ GRANTED BY <em class="replaceable"><code>role_specification</code></em> ]
63     [ CASCADE | RESTRICT ]
64
65 REVOKE [ GRANT OPTION FOR ]
66     { USAGE | ALL [ PRIVILEGES ] }
67     ON LANGUAGE <em class="replaceable"><code>lang_name</code></em> [, ...]
68     FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
69     [ GRANTED BY <em class="replaceable"><code>role_specification</code></em> ]
70     [ CASCADE | RESTRICT ]
71
72 REVOKE [ GRANT OPTION FOR ]
73     { { SELECT | UPDATE } [, ...] | ALL [ PRIVILEGES ] }
74     ON LARGE OBJECT <em class="replaceable"><code>loid</code></em> [, ...]
75     FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
76     [ GRANTED BY <em class="replaceable"><code>role_specification</code></em> ]
77     [ CASCADE | RESTRICT ]
78
79 REVOKE [ GRANT OPTION FOR ]
80     { { SET | ALTER SYSTEM } [, ...] | ALL [ PRIVILEGES ] }
81     ON PARAMETER <em class="replaceable"><code>configuration_parameter</code></em> [, ...]
82     FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
83     [ GRANTED BY <em class="replaceable"><code>role_specification</code></em> ]
84     [ CASCADE | RESTRICT ]
85
86 REVOKE [ GRANT OPTION FOR ]
87     { { CREATE | USAGE } [, ...] | ALL [ PRIVILEGES ] }
88     ON SCHEMA <em class="replaceable"><code>schema_name</code></em> [, ...]
89     FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
90     [ GRANTED BY <em class="replaceable"><code>role_specification</code></em> ]
91     [ CASCADE | RESTRICT ]
92
93 REVOKE [ GRANT OPTION FOR ]
94     { CREATE | ALL [ PRIVILEGES ] }
95     ON TABLESPACE <em class="replaceable"><code>tablespace_name</code></em> [, ...]
96     FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
97     [ GRANTED BY <em class="replaceable"><code>role_specification</code></em> ]
98     [ CASCADE | RESTRICT ]
99
100 REVOKE [ GRANT OPTION FOR ]
101     { USAGE | ALL [ PRIVILEGES ] }
102     ON TYPE <em class="replaceable"><code>type_name</code></em> [, ...]
103     FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
104     [ GRANTED BY <em class="replaceable"><code>role_specification</code></em> ]
105     [ CASCADE | RESTRICT ]
106
107 REVOKE [ { ADMIN | INHERIT | SET } OPTION FOR ]
108     <em class="replaceable"><code>role_name</code></em> [, ...] FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
109     [ GRANTED BY <em class="replaceable"><code>role_specification</code></em> ]
110     [ CASCADE | RESTRICT ]
111
112 <span class="phrase">where <em class="replaceable"><code>role_specification</code></em> can be:</span>
113
114     [ GROUP ] <em class="replaceable"><code>role_name</code></em>
115   | PUBLIC
116   | CURRENT_ROLE
117   | CURRENT_USER
118   | SESSION_USER
119 </pre></div><div class="refsect1" id="SQL-REVOKE-DESCRIPTION"><h2>Description</h2><p>
120    The <code class="command">REVOKE</code> command revokes previously granted
121    privileges from one or more roles.  The key word
122    <code class="literal">PUBLIC</code> refers to the implicitly defined group of
123    all roles.
124   </p><p>
125    See the description of the <a class="link" href="sql-grant.html" title="GRANT"><code class="command">GRANT</code></a> command for
126    the meaning of the privilege types.
127   </p><p>
128    Note that any particular role will have the sum
129    of privileges granted directly to it, privileges granted to any role it
130    is presently a member of, and privileges granted to
131    <code class="literal">PUBLIC</code>.  Thus, for example, revoking <code class="literal">SELECT</code> privilege
132    from <code class="literal">PUBLIC</code> does not necessarily mean that all roles
133    have lost <code class="literal">SELECT</code> privilege on the object: those who have it granted
134    directly or via another role will still have it.  Similarly, revoking
135    <code class="literal">SELECT</code> from a user might not prevent that user from using
136    <code class="literal">SELECT</code> if <code class="literal">PUBLIC</code> or another membership
137    role still has <code class="literal">SELECT</code> rights.
138   </p><p>
139    If <code class="literal">GRANT OPTION FOR</code> is specified, only the grant
140    option for the privilege is revoked, not the privilege itself.
141    Otherwise, both the privilege and the grant option are revoked.
142   </p><p>
143    If a user holds a privilege with grant option and has granted it to
144    other users then the privileges held by those other users are
145    called dependent privileges. If the privilege or the grant option
146    held by the first user is being revoked and dependent privileges
147    exist, those dependent privileges are also revoked if
148    <code class="literal">CASCADE</code> is specified; if it is not, the revoke action
149    will fail.  This recursive revocation only affects privileges that
150    were granted through a chain of users that is traceable to the user
151    that is the subject of this <code class="literal">REVOKE</code> command.
152    Thus, the affected users might effectively keep the privilege if it
153    was also granted through other users.
154   </p><p>
155    When revoking privileges on a table, the corresponding column privileges
156    (if any) are automatically revoked on each column of the table, as well.
157    On the other hand, if a role has been granted privileges on a table, then
158    revoking the same privileges from individual columns will have no effect.
159   </p><p>
160    When revoking membership in a role, <code class="literal">GRANT OPTION</code> is instead
161    called <code class="literal">ADMIN OPTION</code>, but the behavior is similar.
162    Note that, in releases prior to <span class="productname">PostgreSQL</span> 16,
163    dependent privileges were not tracked for grants of role membership,
164    and thus <code class="literal">CASCADE</code> had no effect for role membership.
165    This is no longer the case.
166    Note also that this form of the command does not
167    allow the noise word <code class="literal">GROUP</code>
168    in <em class="replaceable"><code>role_specification</code></em>.
169   </p><p>
170    Just as <code class="literal">ADMIN OPTION</code> can be removed from an existing
171    role grant, it is also possible to revoke <code class="literal">INHERIT OPTION</code>
172    or <code class="literal">SET OPTION</code>.  This is equivalent to setting the value
173    of the corresponding option to <code class="literal">FALSE</code>.
174   </p></div><div class="refsect1" id="SQL-REVOKE-NOTES"><h2>Notes</h2><p>
175    A user can only revoke privileges that were granted directly by
176    that user.  If, for example, user A has granted a privilege with
177    grant option to user B, and user B has in turn granted it to user
178    C, then user A cannot revoke the privilege directly from C.
179    Instead, user A could revoke the grant option from user B and use
180    the <code class="literal">CASCADE</code> option so that the privilege is
181    in turn revoked from user C.  For another example, if both A and B
182    have granted the same privilege to C, A can revoke their own grant
183    but not B's grant, so C will still effectively have the privilege.
184   </p><p>
185     When a non-owner of an object attempts to <code class="command">REVOKE</code> privileges
186     on the object, the command will fail outright if the user has no
187     privileges whatsoever on the object.  As long as some privilege is
188     available, the command will proceed, but it will revoke only those
189     privileges for which the user has grant options.  The <code class="command">REVOKE ALL
190     PRIVILEGES</code> forms will issue a warning message if no grant options are
191     held, while the other forms will issue a warning if grant options for
192     any of the privileges specifically named in the command are not held.
193     (In principle these statements apply to the object owner as well, but
194     since the owner is always treated as holding all grant options, the
195     cases can never occur.)
196    </p><p>
197     If a superuser chooses to issue a <code class="command">GRANT</code> or <code class="command">REVOKE</code>
198     command, the command is performed as though it were issued by the
199     owner of the affected object.  (Since roles do not have owners, in the
200     case of a <code class="command">GRANT</code> of role membership, the command is
201     performed as though it were issued by the bootstrap superuser.)
202     Since all privileges ultimately come
203     from the object owner (possibly indirectly via chains of grant options),
204     it is possible for a superuser to revoke all privileges, but this might
205     require use of <code class="literal">CASCADE</code> as stated above.
206    </p><p>
207     <code class="command">REVOKE</code> can also be done by a role
208     that is not the owner of the affected object, but is a member of the role
209     that owns the object, or is a member of a role that holds privileges
210     <code class="literal">WITH GRANT OPTION</code> on the object.  In this case the
211     command is performed as though it were issued by the containing role that
212     actually owns the object or holds the privileges
213     <code class="literal">WITH GRANT OPTION</code>.  For example, if table
214     <code class="literal">t1</code> is owned by role <code class="literal">g1</code>, of which role
215     <code class="literal">u1</code> is a member, then <code class="literal">u1</code> can revoke privileges
216     on <code class="literal">t1</code> that are recorded as being granted by <code class="literal">g1</code>.
217     This would include grants made by <code class="literal">u1</code> as well as by other
218     members of role <code class="literal">g1</code>.
219    </p><p>
220     If the role executing <code class="command">REVOKE</code> holds privileges
221     indirectly via more than one role membership path, it is unspecified
222     which containing role will be used to perform the command.  In such cases
223     it is best practice to use <code class="command">SET ROLE</code> to become the specific
224     role you want to do the <code class="command">REVOKE</code> as.  Failure to do so might
225     lead to revoking privileges other than the ones you intended, or not
226     revoking anything at all.
227    </p><p>
228     See <a class="xref" href="ddl-priv.html" title="5.8. Privileges">Section 5.8</a> for more information about specific
229     privilege types, as well as how to inspect objects' privileges.
230    </p></div><div class="refsect1" id="SQL-REVOKE-EXAMPLES"><h2>Examples</h2><p>
231    Revoke insert privilege for the public on table
232    <code class="literal">films</code>:
233
234 </p><pre class="programlisting">
235 REVOKE INSERT ON films FROM PUBLIC;
236 </pre><p>
237   </p><p>
238    Revoke all privileges from user <code class="literal">manuel</code> on view
239    <code class="literal">kinds</code>:
240
241 </p><pre class="programlisting">
242 REVOKE ALL PRIVILEGES ON kinds FROM manuel;
243 </pre><p>
244
245    Note that this actually means <span class="quote">“<span class="quote">revoke all privileges that I
246    granted</span>”</span>.
247   </p><p>
248    Revoke membership in role <code class="literal">admins</code> from user <code class="literal">joe</code>:
249
250 </p><pre class="programlisting">
251 REVOKE admins FROM joe;
252 </pre></div><div class="refsect1" id="SQL-REVOKE-COMPATIBILITY"><h2>Compatibility</h2><p>
253     The compatibility notes of the <a class="link" href="sql-grant.html" title="GRANT"><code class="command">GRANT</code></a> command
254     apply analogously to <code class="command">REVOKE</code>.
255     The keyword <code class="literal">RESTRICT</code> or <code class="literal">CASCADE</code>
256     is required according to the standard, but <span class="productname">PostgreSQL</span>
257     assumes <code class="literal">RESTRICT</code> by default.
258    </p></div><div class="refsect1" id="id-1.9.3.166.9"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-grant.html" title="GRANT"><span class="refentrytitle">GRANT</span></a>, <a class="xref" href="sql-alterdefaultprivileges.html" title="ALTER DEFAULT PRIVILEGES"><span class="refentrytitle">ALTER DEFAULT PRIVILEGES</span></a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sql-reset.html" title="RESET">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-rollback.html" title="ROLLBACK">Next</a></td></tr><tr><td width="40%" align="left" valign="top">RESET </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> ROLLBACK</td></tr></table></div></body></html>