gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

186 行
16KB

  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>ALTER ROLE</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-alterpublication.html" title="ALTER PUBLICATION" /><link rel="next" href="sql-alterroutine.html" title="ALTER ROUTINE" /></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">ALTER ROLE</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-alterpublication.html" title="ALTER PUBLICATION">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-alterroutine.html" title="ALTER ROUTINE">Next</a></td></tr></table><hr></hr></div><div class="refentry" id="SQL-ALTERROLE"><div class="titlepage"></div><a id="id-1.9.3.26.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">ALTER ROLE</span></h2><p>ALTER ROLE — change a database role</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
  3. ALTER ROLE <em class="replaceable"><code>role_specification</code></em> [ WITH ] <em class="replaceable"><code>option</code></em> [ ... ]
  4. <span class="phrase">where <em class="replaceable"><code>option</code></em> can be:</span>
  5. SUPERUSER | NOSUPERUSER
  6. | CREATEDB | NOCREATEDB
  7. | CREATEROLE | NOCREATEROLE
  8. | INHERIT | NOINHERIT
  9. | LOGIN | NOLOGIN
  10. | REPLICATION | NOREPLICATION
  11. | BYPASSRLS | NOBYPASSRLS
  12. | CONNECTION LIMIT <em class="replaceable"><code>connlimit</code></em>
  13. | [ ENCRYPTED ] PASSWORD '<em class="replaceable"><code>password</code></em>' | PASSWORD NULL
  14. | VALID UNTIL '<em class="replaceable"><code>timestamp</code></em>'
  15. ALTER ROLE <em class="replaceable"><code>name</code></em> RENAME TO <em class="replaceable"><code>new_name</code></em>
  16. ALTER ROLE { <em class="replaceable"><code>role_specification</code></em> | ALL } [ IN DATABASE <em class="replaceable"><code>database_name</code></em> ] SET <em class="replaceable"><code>configuration_parameter</code></em> { TO | = } { <em class="replaceable"><code>value</code></em> | DEFAULT }
  17. ALTER ROLE { <em class="replaceable"><code>role_specification</code></em> | ALL } [ IN DATABASE <em class="replaceable"><code>database_name</code></em> ] SET <em class="replaceable"><code>configuration_parameter</code></em> FROM CURRENT
  18. ALTER ROLE { <em class="replaceable"><code>role_specification</code></em> | ALL } [ IN DATABASE <em class="replaceable"><code>database_name</code></em> ] RESET <em class="replaceable"><code>configuration_parameter</code></em>
  19. ALTER ROLE { <em class="replaceable"><code>role_specification</code></em> | ALL } [ IN DATABASE <em class="replaceable"><code>database_name</code></em> ] RESET ALL
  20. <span class="phrase">where <em class="replaceable"><code>role_specification</code></em> can be:</span>
  21. <em class="replaceable"><code>role_name</code></em>
  22. | CURRENT_USER
  23. | SESSION_USER
  24. </pre></div><div class="refsect1" id="id-1.9.3.26.5"><h2>Description</h2><p>
  25. <code class="command">ALTER ROLE</code> changes the attributes of a
  26. <span class="productname">PostgreSQL</span> role.
  27. </p><p>
  28. The first variant of this command listed in the synopsis can change
  29. many of the role attributes that can be specified in
  30. <a class="xref" href="sql-createrole.html" title="CREATE ROLE"><span class="refentrytitle">CREATE ROLE</span></a>.
  31. (All the possible attributes are covered,
  32. except that there are no options for adding or removing memberships; use
  33. <a class="xref" href="sql-grant.html" title="GRANT"><span class="refentrytitle">GRANT</span></a> and
  34. <a class="xref" href="sql-revoke.html" title="REVOKE"><span class="refentrytitle">REVOKE</span></a> for that.)
  35. Attributes not mentioned in the command retain their previous settings.
  36. Database superusers can change any of these settings for any role.
  37. Roles having <code class="literal">CREATEROLE</code> privilege can change any of these
  38. settings, but only for non-superuser and non-replication roles.
  39. Ordinary roles can only change their own password.
  40. </p><p>
  41. The second variant changes the name of the role.
  42. Database superusers can rename any role.
  43. Roles having <code class="literal">CREATEROLE</code> privilege can rename non-superuser
  44. roles.
  45. The current session user cannot be renamed.
  46. (Connect as a different user if you need to do that.)
  47. Because <code class="literal">MD5</code>-encrypted passwords use the role name as
  48. cryptographic salt, renaming a role clears its password if the
  49. password is <code class="literal">MD5</code>-encrypted.
  50. </p><p>
  51. The remaining variants change a role's session default for a configuration
  52. variable, either for all databases or, when the <code class="literal">IN
  53. DATABASE</code> clause is specified, only for sessions in the named
  54. database. If <code class="literal">ALL</code> is specified instead of a role name,
  55. this changes the setting for all roles. Using <code class="literal">ALL</code>
  56. with <code class="literal">IN DATABASE</code> is effectively the same as using the
  57. command <code class="literal">ALTER DATABASE ... SET ...</code>.
  58. </p><p>
  59. Whenever the role subsequently
  60. starts a new session, the specified value becomes the session
  61. default, overriding whatever setting is present in
  62. <code class="filename">postgresql.conf</code> or has been received from the <code class="command">postgres</code>
  63. command line. This only happens at login time; executing
  64. <a class="xref" href="sql-set-role.html" title="SET ROLE"><span class="refentrytitle">SET ROLE</span></a> or
  65. <a class="xref" href="sql-set-session-authorization.html" title="SET SESSION AUTHORIZATION"><span class="refentrytitle">SET SESSION AUTHORIZATION</span></a> does not cause new
  66. configuration values to be set.
  67. Settings set for all databases are overridden by database-specific settings
  68. attached to a role. Settings for specific databases or specific roles override
  69. settings for all roles.
  70. </p><p>
  71. Superusers can change anyone's session defaults. Roles having
  72. <code class="literal">CREATEROLE</code> privilege can change defaults for non-superuser
  73. roles. Ordinary roles can only set defaults for themselves.
  74. Certain configuration variables cannot be set this way, or can only be
  75. set if a superuser issues the command. Only superusers can change a setting
  76. for all roles in all databases.
  77. </p></div><div class="refsect1" id="id-1.9.3.26.6"><h2>Parameters</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="replaceable"><code>name</code></em></span></dt><dd><p>
  78. The name of the role whose attributes are to be altered.
  79. </p></dd><dt><span class="term"><code class="literal">CURRENT_USER</code></span></dt><dd><p>
  80. Alter the current user instead of an explicitly identified role.
  81. </p></dd><dt><span class="term"><code class="literal">SESSION_USER</code></span></dt><dd><p>
  82. Alter the current session user instead of an explicitly identified
  83. role.
  84. </p></dd><dt><span class="term"><code class="literal">SUPERUSER</code><br /></span><span class="term"><code class="literal">NOSUPERUSER</code><br /></span><span class="term"><code class="literal">CREATEDB</code><br /></span><span class="term"><code class="literal">NOCREATEDB</code><br /></span><span class="term"><code class="literal">CREATEROLE</code><br /></span><span class="term"><code class="literal">NOCREATEROLE</code><br /></span><span class="term"><code class="literal">INHERIT</code><br /></span><span class="term"><code class="literal">NOINHERIT</code><br /></span><span class="term"><code class="literal">LOGIN</code><br /></span><span class="term"><code class="literal">NOLOGIN</code><br /></span><span class="term"><code class="literal">REPLICATION</code><br /></span><span class="term"><code class="literal">NOREPLICATION</code><br /></span><span class="term"><code class="literal">BYPASSRLS</code><br /></span><span class="term"><code class="literal">NOBYPASSRLS</code><br /></span><span class="term"><code class="literal">CONNECTION LIMIT</code> <em class="replaceable"><code>connlimit</code></em><br /></span><span class="term">[ <code class="literal">ENCRYPTED</code> ] <code class="literal">PASSWORD</code> '<em class="replaceable"><code>password</code></em>'<br /></span><span class="term"><code class="literal">PASSWORD NULL</code><br /></span><span class="term"><code class="literal">VALID UNTIL</code> '<em class="replaceable"><code>timestamp</code></em>'</span></dt><dd><p>
  85. These clauses alter attributes originally set by
  86. <a class="xref" href="sql-createrole.html" title="CREATE ROLE"><span class="refentrytitle">CREATE ROLE</span></a>. For more information, see the
  87. <code class="command">CREATE ROLE</code> reference page.
  88. </p></dd><dt><span class="term"><em class="replaceable"><code>new_name</code></em></span></dt><dd><p>
  89. The new name of the role.
  90. </p></dd><dt><span class="term"><em class="replaceable"><code>database_name</code></em></span></dt><dd><p>
  91. The name of the database the configuration variable should be set in.
  92. </p></dd><dt><span class="term"><em class="replaceable"><code>configuration_parameter</code></em><br /></span><span class="term"><em class="replaceable"><code>value</code></em></span></dt><dd><p>
  93. Set this role's session default for the specified configuration
  94. parameter to the given value. If
  95. <em class="replaceable"><code>value</code></em> is <code class="literal">DEFAULT</code>
  96. or, equivalently, <code class="literal">RESET</code> is used, the
  97. role-specific variable setting is removed, so the role will
  98. inherit the system-wide default setting in new sessions. Use
  99. <code class="literal">RESET ALL</code> to clear all role-specific settings.
  100. <code class="literal">SET FROM CURRENT</code> saves the session's current value of
  101. the parameter as the role-specific value.
  102. If <code class="literal">IN DATABASE</code> is specified, the configuration
  103. parameter is set or removed for the given role and database only.
  104. </p><p>
  105. Role-specific variable settings take effect only at login;
  106. <a class="xref" href="sql-set-role.html" title="SET ROLE"><span class="refentrytitle">SET ROLE</span></a> and
  107. <a class="xref" href="sql-set-session-authorization.html" title="SET SESSION AUTHORIZATION"><span class="refentrytitle">SET SESSION AUTHORIZATION</span></a>
  108. do not process role-specific variable settings.
  109. </p><p>
  110. See <a class="xref" href="sql-set.html" title="SET"><span class="refentrytitle">SET</span></a> and <a class="xref" href="runtime-config.html" title="Chapter 19. Server Configuration">Chapter 19</a> for more information about allowed
  111. parameter names and values.
  112. </p></dd></dl></div></div><div class="refsect1" id="id-1.9.3.26.7"><h2>Notes</h2><p>
  113. Use <a class="xref" href="sql-createrole.html" title="CREATE ROLE"><span class="refentrytitle">CREATE ROLE</span></a>
  114. to add new roles, and <a class="xref" href="sql-droprole.html" title="DROP ROLE"><span class="refentrytitle">DROP ROLE</span></a> to remove a role.
  115. </p><p>
  116. <code class="command">ALTER ROLE</code> cannot change a role's memberships.
  117. Use <a class="xref" href="sql-grant.html" title="GRANT"><span class="refentrytitle">GRANT</span></a> and
  118. <a class="xref" href="sql-revoke.html" title="REVOKE"><span class="refentrytitle">REVOKE</span></a>
  119. to do that.
  120. </p><p>
  121. Caution must be exercised when specifying an unencrypted password
  122. with this command. The password will be transmitted to the server
  123. in cleartext, and it might also be logged in the client's command
  124. history or the server log. <a class="xref" href="app-psql.html" title="psql"><span class="refentrytitle"><span class="application">psql</span></span></a>
  125. contains a command
  126. <code class="command">\password</code> that can be used to change a
  127. role's password without exposing the cleartext password.
  128. </p><p>
  129. It is also possible to tie a
  130. session default to a specific database rather than to a role; see
  131. <a class="xref" href="sql-alterdatabase.html" title="ALTER DATABASE"><span class="refentrytitle">ALTER DATABASE</span></a>.
  132. If there is a conflict, database-role-specific settings override role-specific
  133. ones, which in turn override database-specific ones.
  134. </p></div><div class="refsect1" id="id-1.9.3.26.8"><h2>Examples</h2><p>
  135. Change a role's password:
  136. </p><pre class="programlisting">
  137. ALTER ROLE davide WITH PASSWORD 'hu8jmn3';
  138. </pre><p>
  139. </p><p>
  140. Remove a role's password:
  141. </p><pre class="programlisting">
  142. ALTER ROLE davide WITH PASSWORD NULL;
  143. </pre><p>
  144. </p><p>
  145. Change a password expiration date, specifying that the password
  146. should expire at midday on 4th May 2015 using
  147. the time zone which is one hour ahead of <acronym class="acronym">UTC</acronym>:
  148. </p><pre class="programlisting">
  149. ALTER ROLE chris VALID UNTIL 'May 4 12:00:00 2015 +1';
  150. </pre><p>
  151. </p><p>
  152. Make a password valid forever:
  153. </p><pre class="programlisting">
  154. ALTER ROLE fred VALID UNTIL 'infinity';
  155. </pre><p>
  156. </p><p>
  157. Give a role the ability to create other roles and new databases:
  158. </p><pre class="programlisting">
  159. ALTER ROLE miriam CREATEROLE CREATEDB;
  160. </pre><p>
  161. </p><p>
  162. Give a role a non-default setting of the
  163. <a class="xref" href="runtime-config-resource.html#GUC-MAINTENANCE-WORK-MEM">maintenance_work_mem</a> parameter:
  164. </p><pre class="programlisting">
  165. ALTER ROLE worker_bee SET maintenance_work_mem = 100000;
  166. </pre><p>
  167. </p><p>
  168. Give a role a non-default, database-specific setting of the
  169. <a class="xref" href="runtime-config-client.html#GUC-CLIENT-MIN-MESSAGES">client_min_messages</a> parameter:
  170. </p><pre class="programlisting">
  171. ALTER ROLE fred IN DATABASE devel SET client_min_messages = DEBUG;
  172. </pre></div><div class="refsect1" id="id-1.9.3.26.9"><h2>Compatibility</h2><p>
  173. The <code class="command">ALTER ROLE</code> statement is a
  174. <span class="productname">PostgreSQL</span> extension.
  175. </p></div><div class="refsect1" id="id-1.9.3.26.10"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-createrole.html" title="CREATE ROLE"><span class="refentrytitle">CREATE ROLE</span></a>, <a class="xref" href="sql-droprole.html" title="DROP ROLE"><span class="refentrytitle">DROP ROLE</span></a>, <a class="xref" href="sql-alterdatabase.html" title="ALTER DATABASE"><span class="refentrytitle">ALTER DATABASE</span></a>, <a class="xref" href="sql-set.html" title="SET"><span class="refentrytitle">SET</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-alterpublication.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-alterroutine.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">ALTER PUBLICATION </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> ALTER ROUTINE</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1