gooderp18绿色标准版
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

182 líneas
17KB

  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>createuser</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="app-createdb.html" title="createdb" /><link rel="next" href="app-dropdb.html" title="dropdb" /></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"><span xmlns="http://www.w3.org/1999/xhtml" class="application">createuser</span></th></tr><tr><td width="10%" align="left"><a accesskey="p" href="app-createdb.html" title="createdb">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="reference-client.html" title="PostgreSQL Client Applications">Up</a></td><th width="60%" align="center">PostgreSQL Client Applications</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="app-dropdb.html" title="dropdb">Next</a></td></tr></table><hr></hr></div><div class="refentry" id="APP-CREATEUSER"><div class="titlepage"></div><a id="id-1.9.4.5.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle"><span class="application">createuser</span></span></h2><p>createuser — define a new <span class="productname">PostgreSQL</span> user account</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis"><p id="id-1.9.4.5.4.1"><code class="command">createuser</code> [<em class="replaceable"><code>connection-option</code></em>...] [<em class="replaceable"><code>option</code></em>...] [<em class="replaceable"><code>username</code></em>]</p></div></div><div class="refsect1" id="id-1.9.4.5.5"><h2>Description</h2><p>
  3. <span class="application">createuser</span> creates a
  4. new <span class="productname">PostgreSQL</span> user (or more precisely, a role).
  5. Only superusers and users with <code class="literal">CREATEROLE</code> privilege can create
  6. new users, so <span class="application">createuser</span> must be
  7. invoked by someone who can connect as a superuser or a user with
  8. <code class="literal">CREATEROLE</code> privilege.
  9. </p><p>
  10. If you wish to create a new superuser, you must connect as a
  11. superuser, not merely with <code class="literal">CREATEROLE</code> privilege.
  12. Being a superuser implies the ability to bypass all access permission
  13. checks within the database, so superuserdom should not be granted lightly.
  14. </p><p>
  15. <span class="application">createuser</span> is a wrapper around the
  16. <acronym class="acronym">SQL</acronym> command <a class="xref" href="sql-createrole.html" title="CREATE ROLE"><span class="refentrytitle">CREATE ROLE</span></a>.
  17. There is no effective difference between creating users via
  18. this utility and via other methods for accessing the server.
  19. </p></div><div class="refsect1" id="id-1.9.4.5.6"><h2>Options</h2><p>
  20. <span class="application">createuser</span> accepts the following command-line arguments:
  21. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="replaceable"><code>username</code></em></span></dt><dd><p>
  22. Specifies the name of the <span class="productname">PostgreSQL</span> user
  23. to be created.
  24. This name must be different from all existing roles in this
  25. <span class="productname">PostgreSQL</span> installation.
  26. </p></dd><dt><span class="term"><code class="option">-c <em class="replaceable"><code>number</code></em></code><br /></span><span class="term"><code class="option">--connection-limit=<em class="replaceable"><code>number</code></em></code></span></dt><dd><p>
  27. Set a maximum number of connections for the new user.
  28. The default is to set no limit.
  29. </p></dd><dt><span class="term"><code class="option">-d</code><br /></span><span class="term"><code class="option">--createdb</code></span></dt><dd><p>
  30. The new user will be allowed to create databases.
  31. </p></dd><dt><span class="term"><code class="option">-D</code><br /></span><span class="term"><code class="option">--no-createdb</code></span></dt><dd><p>
  32. The new user will not be allowed to create databases. This is the
  33. default.
  34. </p></dd><dt><span class="term"><code class="option">-e</code><br /></span><span class="term"><code class="option">--echo</code></span></dt><dd><p>
  35. Echo the commands that <span class="application">createuser</span> generates
  36. and sends to the server.
  37. </p></dd><dt><span class="term"><code class="option">-E</code><br /></span><span class="term"><code class="option">--encrypted</code></span></dt><dd><p>
  38. This option is obsolete but still accepted for backward
  39. compatibility.
  40. </p></dd><dt><span class="term"><code class="option">-g <em class="replaceable"><code>role</code></em></code><br /></span><span class="term"><code class="option">--role=<em class="replaceable"><code>role</code></em></code></span></dt><dd><p>
  41. Indicates role to which this role will be added immediately as a new
  42. member. Multiple roles to which this role will be added as a member
  43. can be specified by writing multiple
  44. <code class="option">-g</code> switches.
  45. </p></dd><dt><span class="term"><code class="option">-i</code><br /></span><span class="term"><code class="option">--inherit</code></span></dt><dd><p>
  46. The new role will automatically inherit privileges of roles
  47. it is a member of.
  48. This is the default.
  49. </p></dd><dt><span class="term"><code class="option">-I</code><br /></span><span class="term"><code class="option">--no-inherit</code></span></dt><dd><p>
  50. The new role will not automatically inherit privileges of roles
  51. it is a member of.
  52. </p></dd><dt><span class="term"><code class="option">--interactive</code></span></dt><dd><p>
  53. Prompt for the user name if none is specified on the command line, and
  54. also prompt for whichever of the options
  55. <code class="option">-d</code>/<code class="option">-D</code>,
  56. <code class="option">-r</code>/<code class="option">-R</code>,
  57. <code class="option">-s</code>/<code class="option">-S</code> is not specified on the command
  58. line. (This was the default behavior up to PostgreSQL 9.1.)
  59. </p></dd><dt><span class="term"><code class="option">-l</code><br /></span><span class="term"><code class="option">--login</code></span></dt><dd><p>
  60. The new user will be allowed to log in (that is, the user name
  61. can be used as the initial session user identifier).
  62. This is the default.
  63. </p></dd><dt><span class="term"><code class="option">-L</code><br /></span><span class="term"><code class="option">--no-login</code></span></dt><dd><p>
  64. The new user will not be allowed to log in.
  65. (A role without login privilege is still useful as a means of
  66. managing database permissions.)
  67. </p></dd><dt><span class="term"><code class="option">-P</code><br /></span><span class="term"><code class="option">--pwprompt</code></span></dt><dd><p>
  68. If given, <span class="application">createuser</span> will issue a prompt for
  69. the password of the new user. This is not necessary if you do not plan
  70. on using password authentication.
  71. </p></dd><dt><span class="term"><code class="option">-r</code><br /></span><span class="term"><code class="option">--createrole</code></span></dt><dd><p>
  72. The new user will be allowed to create new roles (that is,
  73. this user will have <code class="literal">CREATEROLE</code> privilege).
  74. </p></dd><dt><span class="term"><code class="option">-R</code><br /></span><span class="term"><code class="option">--no-createrole</code></span></dt><dd><p>
  75. The new user will not be allowed to create new roles. This is the
  76. default.
  77. </p></dd><dt><span class="term"><code class="option">-s</code><br /></span><span class="term"><code class="option">--superuser</code></span></dt><dd><p>
  78. The new user will be a superuser.
  79. </p></dd><dt><span class="term"><code class="option">-S</code><br /></span><span class="term"><code class="option">--no-superuser</code></span></dt><dd><p>
  80. The new user will not be a superuser. This is the default.
  81. </p></dd><dt><span class="term"><code class="option">-V</code><br /></span><span class="term"><code class="option">--version</code></span></dt><dd><p>
  82. Print the <span class="application">createuser</span> version and exit.
  83. </p></dd><dt><span class="term"><code class="option">--replication</code></span></dt><dd><p>
  84. The new user will have the <code class="literal">REPLICATION</code> privilege,
  85. which is described more fully in the documentation for <a class="xref" href="sql-createrole.html" title="CREATE ROLE"><span class="refentrytitle">CREATE ROLE</span></a>.
  86. </p></dd><dt><span class="term"><code class="option">--no-replication</code></span></dt><dd><p>
  87. The new user will not have the <code class="literal">REPLICATION</code>
  88. privilege, which is described more fully in the documentation for <a class="xref" href="sql-createrole.html" title="CREATE ROLE"><span class="refentrytitle">CREATE ROLE</span></a>.
  89. </p></dd><dt><span class="term"><code class="option">-?</code><br /></span><span class="term"><code class="option">--help</code></span></dt><dd><p>
  90. Show help about <span class="application">createuser</span> command line
  91. arguments, and exit.
  92. </p></dd></dl></div><p>
  93. </p><p>
  94. <span class="application">createuser</span> also accepts the following
  95. command-line arguments for connection parameters:
  96. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-h <em class="replaceable"><code>host</code></em></code><br /></span><span class="term"><code class="option">--host=<em class="replaceable"><code>host</code></em></code></span></dt><dd><p>
  97. Specifies the host name of the machine on which the
  98. server
  99. is running. If the value begins with a slash, it is used
  100. as the directory for the Unix domain socket.
  101. </p></dd><dt><span class="term"><code class="option">-p <em class="replaceable"><code>port</code></em></code><br /></span><span class="term"><code class="option">--port=<em class="replaceable"><code>port</code></em></code></span></dt><dd><p>
  102. Specifies the TCP port or local Unix domain socket file
  103. extension on which the server
  104. is listening for connections.
  105. </p></dd><dt><span class="term"><code class="option">-U <em class="replaceable"><code>username</code></em></code><br /></span><span class="term"><code class="option">--username=<em class="replaceable"><code>username</code></em></code></span></dt><dd><p>
  106. User name to connect as (not the user name to create).
  107. </p></dd><dt><span class="term"><code class="option">-w</code><br /></span><span class="term"><code class="option">--no-password</code></span></dt><dd><p>
  108. Never issue a password prompt. If the server requires
  109. password authentication and a password is not available by
  110. other means such as a <code class="filename">.pgpass</code> file, the
  111. connection attempt will fail. This option can be useful in
  112. batch jobs and scripts where no user is present to enter a
  113. password.
  114. </p></dd><dt><span class="term"><code class="option">-W</code><br /></span><span class="term"><code class="option">--password</code></span></dt><dd><p>
  115. Force <span class="application">createuser</span> to prompt for a
  116. password (for connecting to the server, not for the
  117. password of the new user).
  118. </p><p>
  119. This option is never essential, since
  120. <span class="application">createuser</span> will automatically prompt
  121. for a password if the server demands password authentication.
  122. However, <span class="application">createuser</span> will waste a
  123. connection attempt finding out that the server wants a password.
  124. In some cases it is worth typing <code class="option">-W</code> to avoid the extra
  125. connection attempt.
  126. </p></dd></dl></div><p>
  127. </p></div><div class="refsect1" id="id-1.9.4.5.7"><h2>Environment</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="envar">PGHOST</code><br /></span><span class="term"><code class="envar">PGPORT</code><br /></span><span class="term"><code class="envar">PGUSER</code></span></dt><dd><p>
  128. Default connection parameters
  129. </p></dd><dt><span class="term"><code class="envar">PG_COLOR</code></span></dt><dd><p>
  130. Specifies whether to use color in diagnostic messages. Possible values
  131. are <code class="literal">always</code>, <code class="literal">auto</code> and
  132. <code class="literal">never</code>.
  133. </p></dd></dl></div><p>
  134. This utility, like most other <span class="productname">PostgreSQL</span> utilities,
  135. also uses the environment variables supported by <span class="application">libpq</span>
  136. (see <a class="xref" href="libpq-envars.html" title="33.14. Environment Variables">Section 33.14</a>).
  137. </p></div><div class="refsect1" id="id-1.9.4.5.8"><h2>Diagnostics</h2><p>
  138. In case of difficulty, see <a class="xref" href="sql-createrole.html" title="CREATE ROLE"><span class="refentrytitle">CREATE ROLE</span></a>
  139. and <a class="xref" href="app-psql.html" title="psql"><span class="refentrytitle"><span class="application">psql</span></span></a> for
  140. discussions of potential problems and error messages.
  141. The database server must be running at the
  142. targeted host. Also, any default connection settings and environment
  143. variables used by the <span class="application">libpq</span> front-end
  144. library will apply.
  145. </p></div><div class="refsect1" id="id-1.9.4.5.9"><h2>Examples</h2><p>
  146. To create a user <code class="literal">joe</code> on the default database
  147. server:
  148. </p><pre class="screen">
  149. <code class="prompt">$ </code><strong class="userinput"><code>createuser joe</code></strong>
  150. </pre><p>
  151. </p><p>
  152. To create a user <code class="literal">joe</code> on the default database
  153. server with prompting for some additional attributes:
  154. </p><pre class="screen">
  155. <code class="prompt">$ </code><strong class="userinput"><code>createuser --interactive joe</code></strong>
  156. <code class="computeroutput">Shall the new role be a superuser? (y/n) </code><strong class="userinput"><code>n</code></strong>
  157. <code class="computeroutput">Shall the new role be allowed to create databases? (y/n) </code><strong class="userinput"><code>n</code></strong>
  158. <code class="computeroutput">Shall the new role be allowed to create more new roles? (y/n) </code><strong class="userinput"><code>n</code></strong>
  159. </pre><p>
  160. </p><p>
  161. To create the same user <code class="literal">joe</code> using the
  162. server on host <code class="literal">eden</code>, port 5000, with attributes explicitly specified,
  163. taking a look at the underlying command:
  164. </p><pre class="screen">
  165. <code class="prompt">$ </code><strong class="userinput"><code>createuser -h eden -p 5000 -S -D -R -e joe</code></strong>
  166. <code class="computeroutput">CREATE ROLE joe NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;</code>
  167. </pre><p>
  168. </p><p>
  169. To create the user <code class="literal">joe</code> as a superuser,
  170. and assign a password immediately:
  171. </p><pre class="screen">
  172. <code class="prompt">$ </code><strong class="userinput"><code>createuser -P -s -e joe</code></strong>
  173. <code class="computeroutput">Enter password for new role: </code><strong class="userinput"><code>xyzzy</code></strong>
  174. <code class="computeroutput">Enter it again: </code><strong class="userinput"><code>xyzzy</code></strong>
  175. <code class="computeroutput">CREATE ROLE joe PASSWORD 'md5b5f5ba1a423792b526f799ae4eb3d59e' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;</code>
  176. </pre><p>
  177. In the above example, the new password isn't actually echoed when typed,
  178. but we show what was typed for clarity. As you see, the password is
  179. encrypted before it is sent to the client.
  180. </p></div><div class="refsect1" id="id-1.9.4.5.10"><h2>See Also</h2><span class="simplelist"><a class="xref" href="app-dropuser.html" title="dropuser"><span class="refentrytitle"><span class="application">dropuser</span></span></a>, <a class="xref" href="sql-createrole.html" title="CREATE ROLE"><span class="refentrytitle">CREATE ROLE</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="app-createdb.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="reference-client.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="app-dropdb.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="application">createdb</span> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> <span class="application">dropdb</span></td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1