gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

228 line
15KB

  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 V1.79.1" /><link rel="prev" href="sql-reset.html" title="RESET" /><link rel="next" href="sql-rollback.html" title="ROLLBACK" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" 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 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="sql-rollback.html" title="ROLLBACK">Next</a></td></tr></table><hr></hr></div><div class="refentry" id="SQL-REVOKE"><div class="titlepage"></div><a id="id-1.9.3.165.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 }
  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. [ CASCADE | RESTRICT ]
  10. REVOKE [ GRANT OPTION FOR ]
  11. { { SELECT | INSERT | UPDATE | REFERENCES } ( <em class="replaceable"><code>column_name</code></em> [, ...] )
  12. [, ...] | ALL [ PRIVILEGES ] ( <em class="replaceable"><code>column_name</code></em> [, ...] ) }
  13. ON [ TABLE ] <em class="replaceable"><code>table_name</code></em> [, ...]
  14. FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
  15. [ CASCADE | RESTRICT ]
  16. REVOKE [ GRANT OPTION FOR ]
  17. { { USAGE | SELECT | UPDATE }
  18. [, ...] | ALL [ PRIVILEGES ] }
  19. ON { SEQUENCE <em class="replaceable"><code>sequence_name</code></em> [, ...]
  20. | ALL SEQUENCES IN SCHEMA <em class="replaceable"><code>schema_name</code></em> [, ...] }
  21. FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
  22. [ CASCADE | RESTRICT ]
  23. REVOKE [ GRANT OPTION FOR ]
  24. { { CREATE | CONNECT | TEMPORARY | TEMP } [, ...] | ALL [ PRIVILEGES ] }
  25. ON DATABASE <em class="replaceable"><code>database_name</code></em> [, ...]
  26. FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
  27. [ CASCADE | RESTRICT ]
  28. REVOKE [ GRANT OPTION FOR ]
  29. { USAGE | ALL [ PRIVILEGES ] }
  30. ON DOMAIN <em class="replaceable"><code>domain_name</code></em> [, ...]
  31. FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
  32. [ CASCADE | RESTRICT ]
  33. REVOKE [ GRANT OPTION FOR ]
  34. { USAGE | ALL [ PRIVILEGES ] }
  35. ON FOREIGN DATA WRAPPER <em class="replaceable"><code>fdw_name</code></em> [, ...]
  36. FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
  37. [ CASCADE | RESTRICT ]
  38. REVOKE [ GRANT OPTION FOR ]
  39. { USAGE | ALL [ PRIVILEGES ] }
  40. ON FOREIGN SERVER <em class="replaceable"><code>server_name</code></em> [, ...]
  41. FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
  42. [ CASCADE | RESTRICT ]
  43. REVOKE [ GRANT OPTION FOR ]
  44. { EXECUTE | ALL [ PRIVILEGES ] }
  45. 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> [, ...] ] ) ] [, ...]
  46. | ALL { FUNCTIONS | PROCEDURES | ROUTINES } IN SCHEMA <em class="replaceable"><code>schema_name</code></em> [, ...] }
  47. FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
  48. [ CASCADE | RESTRICT ]
  49. REVOKE [ GRANT OPTION FOR ]
  50. { USAGE | ALL [ PRIVILEGES ] }
  51. ON LANGUAGE <em class="replaceable"><code>lang_name</code></em> [, ...]
  52. FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
  53. [ CASCADE | RESTRICT ]
  54. REVOKE [ GRANT OPTION FOR ]
  55. { { SELECT | UPDATE } [, ...] | ALL [ PRIVILEGES ] }
  56. ON LARGE OBJECT <em class="replaceable"><code>loid</code></em> [, ...]
  57. FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
  58. [ CASCADE | RESTRICT ]
  59. REVOKE [ GRANT OPTION FOR ]
  60. { { CREATE | USAGE } [, ...] | ALL [ PRIVILEGES ] }
  61. ON SCHEMA <em class="replaceable"><code>schema_name</code></em> [, ...]
  62. FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
  63. [ CASCADE | RESTRICT ]
  64. REVOKE [ GRANT OPTION FOR ]
  65. { CREATE | ALL [ PRIVILEGES ] }
  66. ON TABLESPACE <em class="replaceable"><code>tablespace_name</code></em> [, ...]
  67. FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
  68. [ CASCADE | RESTRICT ]
  69. REVOKE [ GRANT OPTION FOR ]
  70. { USAGE | ALL [ PRIVILEGES ] }
  71. ON TYPE <em class="replaceable"><code>type_name</code></em> [, ...]
  72. FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
  73. [ CASCADE | RESTRICT ]
  74. REVOKE [ ADMIN OPTION FOR ]
  75. <em class="replaceable"><code>role_name</code></em> [, ...] FROM <em class="replaceable"><code>role_specification</code></em> [, ...]
  76. [ GRANTED BY <em class="replaceable"><code>role_specification</code></em> ]
  77. [ CASCADE | RESTRICT ]
  78. <span class="phrase">where <em class="replaceable"><code>role_specification</code></em> can be:</span>
  79. [ GROUP ] <em class="replaceable"><code>role_name</code></em>
  80. | PUBLIC
  81. | CURRENT_USER
  82. | SESSION_USER
  83. </pre></div><div class="refsect1" id="SQL-REVOKE-DESCRIPTION"><h2>Description</h2><p>
  84. The <code class="command">REVOKE</code> command revokes previously granted
  85. privileges from one or more roles. The key word
  86. <code class="literal">PUBLIC</code> refers to the implicitly defined group of
  87. all roles.
  88. </p><p>
  89. See the description of the <a class="xref" href="sql-grant.html" title="GRANT"><span class="refentrytitle">GRANT</span></a> command for
  90. the meaning of the privilege types.
  91. </p><p>
  92. Note that any particular role will have the sum
  93. of privileges granted directly to it, privileges granted to any role it
  94. is presently a member of, and privileges granted to
  95. <code class="literal">PUBLIC</code>. Thus, for example, revoking <code class="literal">SELECT</code> privilege
  96. from <code class="literal">PUBLIC</code> does not necessarily mean that all roles
  97. have lost <code class="literal">SELECT</code> privilege on the object: those who have it granted
  98. directly or via another role will still have it. Similarly, revoking
  99. <code class="literal">SELECT</code> from a user might not prevent that user from using
  100. <code class="literal">SELECT</code> if <code class="literal">PUBLIC</code> or another membership
  101. role still has <code class="literal">SELECT</code> rights.
  102. </p><p>
  103. If <code class="literal">GRANT OPTION FOR</code> is specified, only the grant
  104. option for the privilege is revoked, not the privilege itself.
  105. Otherwise, both the privilege and the grant option are revoked.
  106. </p><p>
  107. If a user holds a privilege with grant option and has granted it to
  108. other users then the privileges held by those other users are
  109. called dependent privileges. If the privilege or the grant option
  110. held by the first user is being revoked and dependent privileges
  111. exist, those dependent privileges are also revoked if
  112. <code class="literal">CASCADE</code> is specified; if it is not, the revoke action
  113. will fail. This recursive revocation only affects privileges that
  114. were granted through a chain of users that is traceable to the user
  115. that is the subject of this <code class="literal">REVOKE</code> command.
  116. Thus, the affected users might effectively keep the privilege if it
  117. was also granted through other users.
  118. </p><p>
  119. When revoking privileges on a table, the corresponding column privileges
  120. (if any) are automatically revoked on each column of the table, as well.
  121. On the other hand, if a role has been granted privileges on a table, then
  122. revoking the same privileges from individual columns will have no effect.
  123. </p><p>
  124. When revoking membership in a role, <code class="literal">GRANT OPTION</code> is instead
  125. called <code class="literal">ADMIN OPTION</code>, but the behavior is similar.
  126. This form of the command also allows a <code class="literal">GRANTED BY</code>
  127. option, but that option is currently ignored (except for checking
  128. the existence of the named role).
  129. Note also that this form of the command does not
  130. allow the noise word <code class="literal">GROUP</code>
  131. in <em class="replaceable"><code>role_specification</code></em>.
  132. </p></div><div class="refsect1" id="SQL-REVOKE-NOTES"><h2>Notes</h2><p>
  133. A user can only revoke privileges that were granted directly by
  134. that user. If, for example, user A has granted a privilege with
  135. grant option to user B, and user B has in turn granted it to user
  136. C, then user A cannot revoke the privilege directly from C.
  137. Instead, user A could revoke the grant option from user B and use
  138. the <code class="literal">CASCADE</code> option so that the privilege is
  139. in turn revoked from user C. For another example, if both A and B
  140. have granted the same privilege to C, A can revoke their own grant
  141. but not B's grant, so C will still effectively have the privilege.
  142. </p><p>
  143. When a non-owner of an object attempts to <code class="command">REVOKE</code> privileges
  144. on the object, the command will fail outright if the user has no
  145. privileges whatsoever on the object. As long as some privilege is
  146. available, the command will proceed, but it will revoke only those
  147. privileges for which the user has grant options. The <code class="command">REVOKE ALL
  148. PRIVILEGES</code> forms will issue a warning message if no grant options are
  149. held, while the other forms will issue a warning if grant options for
  150. any of the privileges specifically named in the command are not held.
  151. (In principle these statements apply to the object owner as well, but
  152. since the owner is always treated as holding all grant options, the
  153. cases can never occur.)
  154. </p><p>
  155. If a superuser chooses to issue a <code class="command">GRANT</code> or <code class="command">REVOKE</code>
  156. command, the command is performed as though it were issued by the
  157. owner of the affected object. Since all privileges ultimately come
  158. from the object owner (possibly indirectly via chains of grant options),
  159. it is possible for a superuser to revoke all privileges, but this might
  160. require use of <code class="literal">CASCADE</code> as stated above.
  161. </p><p>
  162. <code class="command">REVOKE</code> can also be done by a role
  163. that is not the owner of the affected object, but is a member of the role
  164. that owns the object, or is a member of a role that holds privileges
  165. <code class="literal">WITH GRANT OPTION</code> on the object. In this case the
  166. command is performed as though it were issued by the containing role that
  167. actually owns the object or holds the privileges
  168. <code class="literal">WITH GRANT OPTION</code>. For example, if table
  169. <code class="literal">t1</code> is owned by role <code class="literal">g1</code>, of which role
  170. <code class="literal">u1</code> is a member, then <code class="literal">u1</code> can revoke privileges
  171. on <code class="literal">t1</code> that are recorded as being granted by <code class="literal">g1</code>.
  172. This would include grants made by <code class="literal">u1</code> as well as by other
  173. members of role <code class="literal">g1</code>.
  174. </p><p>
  175. If the role executing <code class="command">REVOKE</code> holds privileges
  176. indirectly via more than one role membership path, it is unspecified
  177. which containing role will be used to perform the command. In such cases
  178. it is best practice to use <code class="command">SET ROLE</code> to become the specific
  179. role you want to do the <code class="command">REVOKE</code> as. Failure to do so might
  180. lead to revoking privileges other than the ones you intended, or not
  181. revoking anything at all.
  182. </p><p>
  183. See <a class="xref" href="ddl-priv.html" title="5.7. Privileges">Section 5.7</a> for more information about specific
  184. privilege types, as well as how to inspect objects' privileges.
  185. </p></div><div class="refsect1" id="SQL-REVOKE-EXAMPLES"><h2>Examples</h2><p>
  186. Revoke insert privilege for the public on table
  187. <code class="literal">films</code>:
  188. </p><pre class="programlisting">
  189. REVOKE INSERT ON films FROM PUBLIC;
  190. </pre><p>
  191. </p><p>
  192. Revoke all privileges from user <code class="literal">manuel</code> on view
  193. <code class="literal">kinds</code>:
  194. </p><pre class="programlisting">
  195. REVOKE ALL PRIVILEGES ON kinds FROM manuel;
  196. </pre><p>
  197. Note that this actually means <span class="quote">“<span class="quote">revoke all privileges that I
  198. granted</span>”</span>.
  199. </p><p>
  200. Revoke membership in role <code class="literal">admins</code> from user <code class="literal">joe</code>:
  201. </p><pre class="programlisting">
  202. REVOKE admins FROM joe;
  203. </pre></div><div class="refsect1" id="SQL-REVOKE-COMPATIBILITY"><h2>Compatibility</h2><p>
  204. The compatibility notes of the <a class="xref" href="sql-grant.html" title="GRANT"><span class="refentrytitle">GRANT</span></a> command
  205. apply analogously to <code class="command">REVOKE</code>.
  206. The keyword <code class="literal">RESTRICT</code> or <code class="literal">CASCADE</code>
  207. is required according to the standard, but <span class="productname">PostgreSQL</span>
  208. assumes <code class="literal">RESTRICT</code> by default.
  209. </p></div><div class="refsect1" id="id-1.9.3.165.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">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-rollback.html">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">Home</a></td><td width="40%" align="right" valign="top"> ROLLBACK</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1