gooderp18绿色标准版
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

140 lines
14KB

  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>createdb</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-clusterdb.html" title="clusterdb" /><link rel="next" href="app-createuser.html" title="createuser" /></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">createdb</span></th></tr><tr><td width="10%" align="left"><a accesskey="p" href="app-clusterdb.html" title="clusterdb">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-createuser.html" title="createuser">Next</a></td></tr></table><hr></hr></div><div class="refentry" id="APP-CREATEDB"><div class="titlepage"></div><a id="id-1.9.4.4.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle"><span class="application">createdb</span></span></h2><p>createdb — create a new <span class="productname">PostgreSQL</span> database</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis"><p id="id-1.9.4.4.4.1"><code class="command">createdb</code> [<em class="replaceable"><code>connection-option</code></em>...] [<em class="replaceable"><code>option</code></em>...] [<em class="replaceable"><code>dbname</code></em>
  3. [<em class="replaceable"><code>description</code></em>]]</p></div></div><div class="refsect1" id="R1-APP-CREATEDB-1"><h2>
  4. Description
  5. </h2><p>
  6. <span class="application">createdb</span> creates a new <span class="productname">PostgreSQL</span>
  7. database.
  8. </p><p>
  9. Normally, the database user who executes this command becomes the owner of
  10. the new database.
  11. However, a different owner can be specified via the <code class="option">-O</code>
  12. option, if the executing user has appropriate privileges.
  13. </p><p>
  14. <span class="application">createdb</span> is a wrapper around the
  15. <acronym class="acronym">SQL</acronym> command <a class="xref" href="sql-createdatabase.html" title="CREATE DATABASE"><span class="refentrytitle">CREATE DATABASE</span></a>.
  16. There is no effective difference between creating databases via
  17. this utility and via other methods for accessing the server.
  18. </p></div><div class="refsect1" id="id-1.9.4.4.6"><h2>Options</h2><p>
  19. <span class="application">createdb</span> accepts the following command-line arguments:
  20. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="replaceable"><code>dbname</code></em></span></dt><dd><p>
  21. Specifies the name of the database to be created. The name must be
  22. unique among all <span class="productname">PostgreSQL</span> databases in this cluster.
  23. The default is to create a database with the same name as the
  24. current system user.
  25. </p></dd><dt><span class="term"><em class="replaceable"><code>description</code></em></span></dt><dd><p>
  26. Specifies a comment to be associated with the newly created
  27. database.
  28. </p></dd><dt><span class="term"><code class="option">-D <em class="replaceable"><code>tablespace</code></em></code><br /></span><span class="term"><code class="option">--tablespace=<em class="replaceable"><code>tablespace</code></em></code></span></dt><dd><p>
  29. Specifies the default tablespace for the database. (This name
  30. is processed as a double-quoted identifier.)
  31. </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>
  32. Echo the commands that <span class="application">createdb</span> generates
  33. and sends to the server.
  34. </p></dd><dt><span class="term"><code class="option">-E <em class="replaceable"><code>encoding</code></em></code><br /></span><span class="term"><code class="option">--encoding=<em class="replaceable"><code>encoding</code></em></code></span></dt><dd><p>
  35. Specifies the character encoding scheme to be used in this
  36. database. The character sets supported by the
  37. <span class="productname">PostgreSQL</span> server are described in
  38. <a class="xref" href="multibyte.html#MULTIBYTE-CHARSET-SUPPORTED" title="23.3.1. Supported Character Sets">Section 23.3.1</a>.
  39. </p></dd><dt><span class="term"><code class="option">-l <em class="replaceable"><code>locale</code></em></code><br /></span><span class="term"><code class="option">--locale=<em class="replaceable"><code>locale</code></em></code></span></dt><dd><p>
  40. Specifies the locale to be used in this database. This is equivalent
  41. to specifying both <code class="option">--lc-collate</code> and <code class="option">--lc-ctype</code>.
  42. </p></dd><dt><span class="term"><code class="option">--lc-collate=<em class="replaceable"><code>locale</code></em></code></span></dt><dd><p>
  43. Specifies the LC_COLLATE setting to be used in this database.
  44. </p></dd><dt><span class="term"><code class="option">--lc-ctype=<em class="replaceable"><code>locale</code></em></code></span></dt><dd><p>
  45. Specifies the LC_CTYPE setting to be used in this database.
  46. </p></dd><dt><span class="term"><code class="option">-O <em class="replaceable"><code>owner</code></em></code><br /></span><span class="term"><code class="option">--owner=<em class="replaceable"><code>owner</code></em></code></span></dt><dd><p>
  47. Specifies the database user who will own the new database.
  48. (This name is processed as a double-quoted identifier.)
  49. </p></dd><dt><span class="term"><code class="option">-T <em class="replaceable"><code>template</code></em></code><br /></span><span class="term"><code class="option">--template=<em class="replaceable"><code>template</code></em></code></span></dt><dd><p>
  50. Specifies the template database from which to build this
  51. database. (This name is processed as a double-quoted identifier.)
  52. </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>
  53. Print the <span class="application">createdb</span> version and exit.
  54. </p></dd><dt><span class="term"><code class="option">-?</code><br /></span><span class="term"><code class="option">--help</code></span></dt><dd><p>
  55. Show help about <span class="application">createdb</span> command line
  56. arguments, and exit.
  57. </p></dd></dl></div><p>
  58. </p><p>
  59. The options <code class="option">-D</code>, <code class="option">-l</code>, <code class="option">-E</code>,
  60. <code class="option">-O</code>, and
  61. <code class="option">-T</code> correspond to options of the underlying
  62. SQL command <a class="xref" href="sql-createdatabase.html" title="CREATE DATABASE"><span class="refentrytitle">CREATE DATABASE</span></a>; see there for more information
  63. about them.
  64. </p><p>
  65. <span class="application">createdb</span> also accepts the following
  66. command-line arguments for connection parameters:
  67. </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>
  68. Specifies the host name of the machine on which the
  69. server is running. If the value begins with a slash, it is used
  70. as the directory for the Unix domain socket.
  71. </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>
  72. Specifies the TCP port or the local Unix domain socket file
  73. extension on which the server is listening for connections.
  74. </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>
  75. User name to connect as.
  76. </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>
  77. Never issue a password prompt. If the server requires
  78. password authentication and a password is not available by
  79. other means such as a <code class="filename">.pgpass</code> file, the
  80. connection attempt will fail. This option can be useful in
  81. batch jobs and scripts where no user is present to enter a
  82. password.
  83. </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>
  84. Force <span class="application">createdb</span> to prompt for a
  85. password before connecting to a database.
  86. </p><p>
  87. This option is never essential, since
  88. <span class="application">createdb</span> will automatically prompt
  89. for a password if the server demands password authentication.
  90. However, <span class="application">createdb</span> will waste a
  91. connection attempt finding out that the server wants a password.
  92. In some cases it is worth typing <code class="option">-W</code> to avoid the extra
  93. connection attempt.
  94. </p></dd><dt><span class="term"><code class="option">--maintenance-db=<em class="replaceable"><code>dbname</code></em></code></span></dt><dd><p>
  95. Specifies the name of the database to connect to when creating the
  96. new database. If not specified, the <code class="literal">postgres</code>
  97. database will be used; if that does not exist (or if it is the name
  98. of the new database being created), <code class="literal">template1</code> will
  99. be used.
  100. </p></dd></dl></div><p>
  101. </p></div><div class="refsect1" id="id-1.9.4.4.7"><h2>Environment</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="envar">PGDATABASE</code></span></dt><dd><p>
  102. If set, the name of the database to create, unless overridden on
  103. the command line.
  104. </p></dd><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>
  105. Default connection parameters. <code class="envar">PGUSER</code> also
  106. determines the name of the database to create, if it is not
  107. specified on the command line or by <code class="envar">PGDATABASE</code>.
  108. </p></dd><dt><span class="term"><code class="envar">PG_COLOR</code></span></dt><dd><p>
  109. Specifies whether to use color in diagnostic messages. Possible values
  110. are <code class="literal">always</code>, <code class="literal">auto</code> and
  111. <code class="literal">never</code>.
  112. </p></dd></dl></div><p>
  113. This utility, like most other <span class="productname">PostgreSQL</span> utilities,
  114. also uses the environment variables supported by <span class="application">libpq</span>
  115. (see <a class="xref" href="libpq-envars.html" title="33.14. Environment Variables">Section 33.14</a>).
  116. </p></div><div class="refsect1" id="id-1.9.4.4.8"><h2>Diagnostics</h2><p>
  117. In case of difficulty, see <a class="xref" href="sql-createdatabase.html" title="CREATE DATABASE"><span class="refentrytitle">CREATE DATABASE</span></a>
  118. and <a class="xref" href="app-psql.html" title="psql"><span class="refentrytitle"><span class="application">psql</span></span></a> for
  119. discussions of potential problems and error messages.
  120. The database server must be running at the
  121. targeted host. Also, any default connection settings and environment
  122. variables used by the <span class="application">libpq</span> front-end
  123. library will apply.
  124. </p></div><div class="refsect1" id="id-1.9.4.4.9"><h2>Examples</h2><p>
  125. To create the database <code class="literal">demo</code> using the default
  126. database server:
  127. </p><pre class="screen">
  128. <code class="prompt">$ </code><strong class="userinput"><code>createdb demo</code></strong>
  129. </pre><p>
  130. </p><p>
  131. To create the database <code class="literal">demo</code> using the
  132. server on host <code class="literal">eden</code>, port 5000, using the
  133. <code class="literal">template0</code> template database, here is the
  134. command-line command and the underlying SQL command:
  135. </p><pre class="screen">
  136. <code class="prompt">$ </code><strong class="userinput"><code>createdb -p 5000 -h eden -T template0 -e demo</code></strong>
  137. <code class="computeroutput">CREATE DATABASE demo TEMPLATE template0;</code>
  138. </pre></div><div class="refsect1" id="id-1.9.4.4.10"><h2>See Also</h2><span class="simplelist"><a class="xref" href="app-dropdb.html" title="dropdb"><span class="refentrytitle"><span class="application">dropdb</span></span></a>, <a class="xref" href="sql-createdatabase.html" title="CREATE DATABASE"><span class="refentrytitle">CREATE DATABASE</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-clusterdb.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-createuser.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="application">clusterdb</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">createuser</span></td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1