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.

87 lines
8.2KB

  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>21.2. Role Attributes</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="database-roles.html" title="21.1. Database Roles" /><link rel="next" href="role-membership.html" title="21.3. Role Membership" /></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">21.2. Role Attributes</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="database-roles.html" title="21.1. Database Roles">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="user-manag.html" title="Chapter 21. Database Roles">Up</a></td><th width="60%" align="center">Chapter 21. Database Roles</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="role-membership.html" title="21.3. Role Membership">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="ROLE-ATTRIBUTES"><div class="titlepage"><div><div><h2 class="title" style="clear: both">21.2. Role Attributes</h2></div></div></div><p>
  3. A database role can have a number of attributes that define its
  4. privileges and interact with the client authentication system.
  5. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">login privilege<a id="id-1.6.8.6.2.1.1.1.1" class="indexterm"></a></span></dt><dd><p>
  6. Only roles that have the <code class="literal">LOGIN</code> attribute can be used
  7. as the initial role name for a database connection. A role with
  8. the <code class="literal">LOGIN</code> attribute can be considered the same
  9. as a <span class="quote">“<span class="quote">database user</span>”</span>. To create a role with login privilege,
  10. use either:
  11. </p><pre class="programlisting">
  12. CREATE ROLE <em class="replaceable"><code>name</code></em> LOGIN;
  13. CREATE USER <em class="replaceable"><code>name</code></em>;
  14. </pre><p>
  15. (<code class="command">CREATE USER</code> is equivalent to <code class="command">CREATE ROLE</code>
  16. except that <code class="command">CREATE USER</code> includes <code class="literal">LOGIN</code> by
  17. default, while <code class="command">CREATE ROLE</code> does not.)
  18. </p></dd><dt><span class="term">superuser status<a id="id-1.6.8.6.2.1.2.1.1" class="indexterm"></a></span></dt><dd><p>
  19. A database superuser bypasses all permission checks, except the right
  20. to log in. This is a dangerous privilege and should not be used
  21. carelessly; it is best to do most of your work as a role that is not a
  22. superuser. To create a new database superuser, use <code class="literal">CREATE
  23. ROLE <em class="replaceable"><code>name</code></em> SUPERUSER</code>. You must do
  24. this as a role that is already a superuser.
  25. </p></dd><dt><span class="term">database creation<a id="id-1.6.8.6.2.1.3.1.1" class="indexterm"></a></span></dt><dd><p>
  26. A role must be explicitly given permission to create databases
  27. (except for superusers, since those bypass all permission
  28. checks). To create such a role, use <code class="literal">CREATE ROLE
  29. <em class="replaceable"><code>name</code></em> CREATEDB</code>.
  30. </p></dd><dt><span class="term">role creation<a id="id-1.6.8.6.2.1.4.1.1" class="indexterm"></a></span></dt><dd><p>
  31. A role must be explicitly given permission to create more roles
  32. (except for superusers, since those bypass all permission
  33. checks). To create such a role, use <code class="literal">CREATE ROLE
  34. <em class="replaceable"><code>name</code></em> CREATEROLE</code>.
  35. A role with <code class="literal">CREATEROLE</code> privilege can alter and drop
  36. other roles, too, as well as grant or revoke membership in them.
  37. However, to create, alter, drop, or change membership of a
  38. superuser role, superuser status is required;
  39. <code class="literal">CREATEROLE</code> is insufficient for that.
  40. </p></dd><dt><span class="term">initiating replication<a id="id-1.6.8.6.2.1.5.1.1" class="indexterm"></a></span></dt><dd><p>
  41. A role must explicitly be given permission to initiate streaming
  42. replication (except for superusers, since those bypass all permission
  43. checks). A role used for streaming replication must
  44. have <code class="literal">LOGIN</code> permission as well. To create such a role, use
  45. <code class="literal">CREATE ROLE <em class="replaceable"><code>name</code></em> REPLICATION
  46. LOGIN</code>.
  47. </p></dd><dt><span class="term">password<a id="id-1.6.8.6.2.1.6.1.1" class="indexterm"></a></span></dt><dd><p>
  48. A password is only significant if the client authentication
  49. method requires the user to supply a password when connecting
  50. to the database. The <code class="option">password</code> and
  51. <code class="option">md5</code> authentication methods
  52. make use of passwords. Database passwords are separate from
  53. operating system passwords. Specify a password upon role
  54. creation with <code class="literal">CREATE ROLE
  55. <em class="replaceable"><code>name</code></em> PASSWORD '<em class="replaceable"><code>string</code></em>'</code>.
  56. </p></dd></dl></div><p>
  57. A role's attributes can be modified after creation with
  58. <code class="command">ALTER ROLE</code>.<a id="id-1.6.8.6.2.3" class="indexterm"></a>
  59. See the reference pages for the <a class="xref" href="sql-createrole.html" title="CREATE ROLE"><span class="refentrytitle">CREATE ROLE</span></a>
  60. and <a class="xref" href="sql-alterrole.html" title="ALTER ROLE"><span class="refentrytitle">ALTER ROLE</span></a> commands for details.
  61. </p><div class="tip"><h3 class="title">Tip</h3><p>
  62. It is good practice to create a role that has the <code class="literal">CREATEDB</code>
  63. and <code class="literal">CREATEROLE</code> privileges, but is not a superuser, and then
  64. use this role for all routine management of databases and roles. This
  65. approach avoids the dangers of operating as a superuser for tasks that
  66. do not really require it.
  67. </p></div><p>
  68. A role can also have role-specific defaults for many of the run-time
  69. configuration settings described in <a class="xref" href="runtime-config.html" title="Chapter 19. Server Configuration">Chapter 19</a>. For example, if for some reason you
  70. want to disable index scans (hint: not a good idea) anytime you
  71. connect, you can use:
  72. </p><pre class="programlisting">
  73. ALTER ROLE myname SET enable_indexscan TO off;
  74. </pre><p>
  75. This will save the setting (but not set it immediately). In
  76. subsequent connections by this role it will appear as though
  77. <code class="literal">SET enable_indexscan TO off</code> had been executed
  78. just before the session started.
  79. You can still alter this setting during the session; it will only
  80. be the default. To remove a role-specific default setting, use
  81. <code class="literal">ALTER ROLE <em class="replaceable"><code>rolename</code></em> RESET <em class="replaceable"><code>varname</code></em></code>.
  82. Note that role-specific defaults attached to roles without
  83. <code class="literal">LOGIN</code> privilege are fairly useless, since they will never
  84. be invoked.
  85. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="database-roles.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="user-manag.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="role-membership.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">21.1. Database Roles </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 21.3. Role Membership</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1