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.

70 lines
6.5KB

  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.1. Database Roles</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="user-manag.html" title="Chapter 21. Database Roles" /><link rel="next" href="role-attributes.html" title="21.2. Role Attributes" /></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.1. Database Roles</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="user-manag.html" title="Chapter 21. 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-attributes.html" title="21.2. Role Attributes">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="DATABASE-ROLES"><div class="titlepage"><div><div><h2 class="title" style="clear: both">21.1. Database Roles</h2></div></div></div><a id="id-1.6.8.5.2" class="indexterm"></a><a id="id-1.6.8.5.3" class="indexterm"></a><a id="id-1.6.8.5.4" class="indexterm"></a><a id="id-1.6.8.5.5" class="indexterm"></a><p>
  3. Database roles are conceptually completely separate from
  4. operating system users. In practice it might be convenient to
  5. maintain a correspondence, but this is not required. Database roles
  6. are global across a database cluster installation (and not
  7. per individual database). To create a role use the <a class="xref" href="sql-createrole.html" title="CREATE ROLE"><span class="refentrytitle">CREATE ROLE</span></a> SQL command:
  8. </p><pre class="synopsis">
  9. CREATE ROLE <em class="replaceable"><code>name</code></em>;
  10. </pre><p>
  11. <em class="replaceable"><code>name</code></em> follows the rules for SQL
  12. identifiers: either unadorned without special characters, or
  13. double-quoted. (In practice, you will usually want to add additional
  14. options, such as <code class="literal">LOGIN</code>, to the command. More details appear
  15. below.) To remove an existing role, use the analogous
  16. <a class="xref" href="sql-droprole.html" title="DROP ROLE"><span class="refentrytitle">DROP ROLE</span></a> command:
  17. </p><pre class="synopsis">
  18. DROP ROLE <em class="replaceable"><code>name</code></em>;
  19. </pre><p>
  20. </p><a id="id-1.6.8.5.7" class="indexterm"></a><a id="id-1.6.8.5.8" class="indexterm"></a><p>
  21. For convenience, the programs <a class="xref" href="app-createuser.html" title="createuser"><span class="refentrytitle"><span class="application">createuser</span></span></a>
  22. and <a class="xref" href="app-dropuser.html" title="dropuser"><span class="refentrytitle"><span class="application">dropuser</span></span></a> are provided as wrappers
  23. around these SQL commands that can be called from the shell command
  24. line:
  25. </p><pre class="synopsis">
  26. createuser <em class="replaceable"><code>name</code></em>
  27. dropuser <em class="replaceable"><code>name</code></em>
  28. </pre><p>
  29. </p><p>
  30. To determine the set of existing roles, examine the <code class="structname">pg_roles</code>
  31. system catalog, for example
  32. </p><pre class="synopsis">
  33. SELECT rolname FROM pg_roles;
  34. </pre><p>
  35. The <a class="xref" href="app-psql.html" title="psql"><span class="refentrytitle"><span class="application">psql</span></span></a> program's <code class="literal">\du</code> meta-command
  36. is also useful for listing the existing roles.
  37. </p><p>
  38. In order to bootstrap the database system, a freshly initialized
  39. system always contains one predefined role. This role is always
  40. a <span class="quote">“<span class="quote">superuser</span>”</span>, and by default (unless altered when running
  41. <code class="command">initdb</code>) it will have the same name as the
  42. operating system user that initialized the database
  43. cluster. Customarily, this role will be named
  44. <code class="literal">postgres</code>. In order to create more roles you
  45. first have to connect as this initial role.
  46. </p><p>
  47. Every connection to the database server is made using the name of some
  48. particular role, and this role determines the initial access privileges for
  49. commands issued in that connection.
  50. The role name to use for a particular database
  51. connection is indicated by the client that is initiating the
  52. connection request in an application-specific fashion. For example,
  53. the <code class="command">psql</code> program uses the
  54. <code class="option">-U</code> command line option to indicate the role to
  55. connect as. Many applications assume the name of the current
  56. operating system user by default (including
  57. <code class="command">createuser</code> and <code class="command">psql</code>). Therefore it
  58. is often convenient to maintain a naming correspondence between
  59. roles and operating system users.
  60. </p><p>
  61. The set of database roles a given client connection can connect as
  62. is determined by the client authentication setup, as explained in
  63. <a class="xref" href="client-authentication.html" title="Chapter 20. Client Authentication">Chapter 20</a>. (Thus, a client is not
  64. limited to connect as the role matching
  65. its operating system user, just as a person's login name
  66. need not match his or her real name.) Since the role
  67. identity determines the set of privileges available to a connected
  68. client, it is important to carefully configure privileges when setting up
  69. a multiuser environment.
  70. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="user-manag.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-attributes.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 21. 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.2. Role Attributes</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1