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.

214 line
20KB

  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>initdb</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="reference-server.html" title="PostgreSQL Server Applications" /><link rel="next" href="pgarchivecleanup.html" title="pg_archivecleanup" /></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">initdb</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="reference-server.html" title="PostgreSQL Server Applications">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="reference-server.html" title="PostgreSQL Server Applications">Up</a></td><th width="60%" align="center">PostgreSQL Server 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="pgarchivecleanup.html" title="pg_archivecleanup">Next</a></td></tr></table><hr></hr></div><div class="refentry" id="APP-INITDB"><div class="titlepage"></div><a id="id-1.9.5.3.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">initdb</span></h2><p>initdb — create a new <span class="productname">PostgreSQL</span> database cluster</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis"><p id="id-1.9.5.3.4.1"><code class="command">initdb</code> [<em class="replaceable"><code>option</code></em>...] [ <code class="option">--pgdata</code> | <code class="option">-D</code> ]<em class="replaceable"><code> directory</code></em> </p></div></div><div class="refsect1" id="R1-APP-INITDB-1"><h2>
  3. Description
  4. </h2><p>
  5. <code class="command">initdb</code> creates a new
  6. <span class="productname">PostgreSQL</span> database cluster. A database
  7. cluster is a collection of databases that are managed by a single
  8. server instance.
  9. </p><p>
  10. Creating a database cluster consists of creating the directories in
  11. which the database data will live, generating the shared catalog
  12. tables (tables that belong to the whole cluster rather than to any
  13. particular database), and creating the <code class="literal">template1</code>
  14. and <code class="literal">postgres</code> databases. When you later create a
  15. new database, everything in the <code class="literal">template1</code> database is
  16. copied. (Therefore, anything installed in <code class="literal">template1</code>
  17. is automatically copied into each database created later.)
  18. The <code class="literal">postgres</code> database is a default database meant
  19. for use by users, utilities and third party applications.
  20. </p><p>
  21. Although <code class="command">initdb</code> will attempt to create the
  22. specified data directory, it might not have permission if the parent
  23. directory of the desired data directory is root-owned. To initialize
  24. in such a setup, create an empty data directory as root, then use
  25. <code class="command">chown</code> to assign ownership of that directory to the
  26. database user account, then <code class="command">su</code> to become the
  27. database user to run <code class="command">initdb</code>.
  28. </p><p>
  29. <code class="command">initdb</code> must be run as the user that will own the
  30. server process, because the server needs to have access to the
  31. files and directories that <code class="command">initdb</code> creates.
  32. Since the server cannot be run as root, you must not run
  33. <code class="command">initdb</code> as root either. (It will in fact refuse
  34. to do so.)
  35. </p><p>
  36. For security reasons the new cluster created by <code class="command">initdb</code>
  37. will only be accessible by the cluster owner by default. The
  38. <code class="option">--allow-group-access</code> option allows any user in the same
  39. group as the cluster owner to read files in the cluster. This is useful
  40. for performing backups as a non-privileged user.
  41. </p><p>
  42. <code class="command">initdb</code> initializes the database cluster's default
  43. locale and character set encoding. The character set encoding,
  44. collation order (<code class="literal">LC_COLLATE</code>) and character set classes
  45. (<code class="literal">LC_CTYPE</code>, e.g. upper, lower, digit) can be set separately
  46. for a database when it is created. <code class="command">initdb</code> determines
  47. those settings for the <code class="literal">template1</code> database, which will
  48. serve as the default for all other databases.
  49. </p><p>
  50. To alter the default collation order or character set classes, use the
  51. <code class="option">--lc-collate</code> and <code class="option">--lc-ctype</code> options.
  52. Collation orders other than <code class="literal">C</code> or <code class="literal">POSIX</code> also have
  53. a performance penalty. For these reasons it is important to choose the
  54. right locale when running <code class="command">initdb</code>.
  55. </p><p>
  56. The remaining locale categories can be changed later when the server
  57. is started. You can also use <code class="option">--locale</code> to set the
  58. default for all locale categories, including collation order and
  59. character set classes. All server locale values (<code class="literal">lc_*</code>) can
  60. be displayed via <code class="command">SHOW ALL</code>.
  61. More details can be found in <a class="xref" href="locale.html" title="23.1. Locale Support">Section 23.1</a>.
  62. </p><p>
  63. To alter the default encoding, use the <code class="option">--encoding</code>.
  64. More details can be found in <a class="xref" href="multibyte.html" title="23.3. Character Set Support">Section 23.3</a>.
  65. </p></div><div class="refsect1" id="id-1.9.5.3.6"><h2>Options</h2><p>
  66. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-A <em class="replaceable"><code>authmethod</code></em></code><br /></span><span class="term"><code class="option">--auth=<em class="replaceable"><code>authmethod</code></em></code></span></dt><dd><p>
  67. This option specifies the default authentication method for local
  68. users used in <code class="filename">pg_hba.conf</code> (<code class="literal">host</code>
  69. and <code class="literal">local</code> lines). <code class="command">initdb</code> will
  70. prepopulate <code class="filename">pg_hba.conf</code> entries using the
  71. specified authentication method for non-replication as well as
  72. replication connections.
  73. </p><p>
  74. Do not use <code class="literal">trust</code> unless you trust all local users on your
  75. system. <code class="literal">trust</code> is the default for ease of installation.
  76. </p></dd><dt><span class="term"><code class="option">--auth-host=<em class="replaceable"><code>authmethod</code></em></code></span></dt><dd><p>
  77. This option specifies the authentication method for local users via
  78. TCP/IP connections used in <code class="filename">pg_hba.conf</code>
  79. (<code class="literal">host</code> lines).
  80. </p></dd><dt><span class="term"><code class="option">--auth-local=<em class="replaceable"><code>authmethod</code></em></code></span></dt><dd><p>
  81. This option specifies the authentication method for local users via
  82. Unix-domain socket connections used in <code class="filename">pg_hba.conf</code>
  83. (<code class="literal">local</code> lines).
  84. </p></dd><dt><span class="term"><code class="option">-D <em class="replaceable"><code>directory</code></em></code><br /></span><span class="term"><code class="option">--pgdata=<em class="replaceable"><code>directory</code></em></code></span></dt><dd><p>
  85. This option specifies the directory where the database cluster
  86. should be stored. This is the only information required by
  87. <code class="command">initdb</code>, but you can avoid writing it by
  88. setting the <code class="envar">PGDATA</code> environment variable, which
  89. can be convenient since the database server
  90. (<code class="command">postgres</code>) can find the database
  91. directory later by the same variable.
  92. </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>
  93. Selects the encoding of the template database. This will also
  94. be the default encoding of any database you create later,
  95. unless you override it there. The default is derived from the locale, or
  96. <code class="literal">SQL_ASCII</code> if that does not work. The character sets supported by
  97. the <span class="productname">PostgreSQL</span> server are described
  98. in <a class="xref" href="multibyte.html#MULTIBYTE-CHARSET-SUPPORTED" title="23.3.1. Supported Character Sets">Section 23.3.1</a>.
  99. </p></dd><dt id="APP-INITDB-ALLOW-GROUP-ACCESS"><span class="term"><code class="option">-g</code><br /></span><span class="term"><code class="option">--allow-group-access</code></span></dt><dd><p>
  100. Allows users in the same group as the cluster owner to read all cluster
  101. files created by <code class="command">initdb</code>. This option is ignored
  102. on <span class="productname">Windows</span> as it does not support
  103. <acronym class="acronym">POSIX</acronym>-style group permissions.
  104. </p></dd><dt id="APP-INITDB-DATA-CHECKSUMS"><span class="term"><code class="option">-k</code><br /></span><span class="term"><code class="option">--data-checksums</code></span></dt><dd><p>
  105. Use checksums on data pages to help detect corruption by the
  106. I/O system that would otherwise be silent. Enabling checksums
  107. may incur a noticeable performance penalty. If set, checksums
  108. are calculated for all objects, in all databases. All checksum
  109. failures will be reported in the
  110. <a class="xref" href="monitoring-stats.html#PG-STAT-DATABASE-VIEW" title="Table 27.12. pg_stat_database View">pg_stat_database</a> view.
  111. </p></dd><dt><span class="term"><code class="option">--locale=<em class="replaceable"><code>locale</code></em></code></span></dt><dd><p>
  112. Sets the default locale for the database cluster. If this
  113. option is not specified, the locale is inherited from the
  114. environment that <code class="command">initdb</code> runs in. Locale
  115. support is described in <a class="xref" href="locale.html" title="23.1. Locale Support">Section 23.1</a>.
  116. </p></dd><dt><span class="term"><code class="option">--lc-collate=<em class="replaceable"><code>locale</code></em></code><br /></span><span class="term"><code class="option">--lc-ctype=<em class="replaceable"><code>locale</code></em></code><br /></span><span class="term"><code class="option">--lc-messages=<em class="replaceable"><code>locale</code></em></code><br /></span><span class="term"><code class="option">--lc-monetary=<em class="replaceable"><code>locale</code></em></code><br /></span><span class="term"><code class="option">--lc-numeric=<em class="replaceable"><code>locale</code></em></code><br /></span><span class="term"><code class="option">--lc-time=<em class="replaceable"><code>locale</code></em></code></span></dt><dd><p>
  117. Like <code class="option">--locale</code>, but only sets the locale in
  118. the specified category.
  119. </p></dd><dt><span class="term"><code class="option">--no-locale</code></span></dt><dd><p>
  120. Equivalent to <code class="option">--locale=C</code>.
  121. </p></dd><dt><span class="term"><code class="option">-N</code><br /></span><span class="term"><code class="option">--no-sync</code></span></dt><dd><p>
  122. By default, <code class="command">initdb</code> will wait for all files to be
  123. written safely to disk. This option causes <code class="command">initdb</code>
  124. to return without waiting, which is faster, but means that a
  125. subsequent operating system crash can leave the data directory
  126. corrupt. Generally, this option is useful for testing, but should not
  127. be used when creating a production installation.
  128. </p></dd><dt><span class="term"><code class="option">--pwfile=<em class="replaceable"><code>filename</code></em></code></span></dt><dd><p>
  129. Makes <code class="command">initdb</code> read the database superuser's password
  130. from a file. The first line of the file is taken as the password.
  131. </p></dd><dt><span class="term"><code class="option">-S</code><br /></span><span class="term"><code class="option">--sync-only</code></span></dt><dd><p>
  132. Safely write all database files to disk and exit. This does not
  133. perform any of the normal <span class="application">initdb</span> operations.
  134. </p></dd><dt><span class="term"><code class="option">-T <em class="replaceable"><code>config</code></em></code><br /></span><span class="term"><code class="option">--text-search-config=<em class="replaceable"><code>config</code></em></code></span></dt><dd><p>
  135. Sets the default text search configuration.
  136. See <a class="xref" href="runtime-config-client.html#GUC-DEFAULT-TEXT-SEARCH-CONFIG">default_text_search_config</a> for further information.
  137. </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>
  138. Selects the user name of the database superuser. This defaults
  139. to the name of the effective user running
  140. <code class="command">initdb</code>. It is really not important what the
  141. superuser's name is, but one might choose to keep the
  142. customary name <span class="systemitem">postgres</span>, even if the operating
  143. system user's name is different.
  144. </p></dd><dt><span class="term"><code class="option">-W</code><br /></span><span class="term"><code class="option">--pwprompt</code></span></dt><dd><p>
  145. Makes <code class="command">initdb</code> prompt for a password
  146. to give the database superuser. If you don't plan on using password
  147. authentication, this is not important. Otherwise you won't be
  148. able to use password authentication until you have a password
  149. set up.
  150. </p></dd><dt><span class="term"><code class="option">-X <em class="replaceable"><code>directory</code></em></code><br /></span><span class="term"><code class="option">--waldir=<em class="replaceable"><code>directory</code></em></code></span></dt><dd><p>
  151. This option specifies the directory where the write-ahead log
  152. should be stored.
  153. </p></dd><dt><span class="term"><code class="option">--wal-segsize=<em class="replaceable"><code>size</code></em></code></span></dt><dd><p>
  154. Set the <em class="firstterm">WAL segment size</em>, in megabytes. This
  155. is the size of each individual file in the WAL log. The default size
  156. is 16 megabytes. The value must be a power of 2 between 1 and 1024
  157. (megabytes). This option can only be set during initialization, and
  158. cannot be changed later.
  159. </p><p>
  160. It may be useful to adjust this size to control the granularity of
  161. WAL log shipping or archiving. Also, in databases with a high volume
  162. of WAL, the sheer number of WAL files per directory can become a
  163. performance and management problem. Increasing the WAL file size
  164. will reduce the number of WAL files.
  165. </p></dd></dl></div><p>
  166. </p><p>
  167. Other, less commonly used, options are also available:
  168. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-d</code><br /></span><span class="term"><code class="option">--debug</code></span></dt><dd><p>
  169. Print debugging output from the bootstrap backend and a few other
  170. messages of lesser interest for the general public.
  171. The bootstrap backend is the program <code class="command">initdb</code>
  172. uses to create the catalog tables. This option generates a tremendous
  173. amount of extremely boring output.
  174. </p></dd><dt><span class="term"><code class="option">-L <em class="replaceable"><code>directory</code></em></code></span></dt><dd><p>
  175. Specifies where <code class="command">initdb</code> should find
  176. its input files to initialize the database cluster. This is
  177. normally not necessary. You will be told if you need to
  178. specify their location explicitly.
  179. </p></dd><dt><span class="term"><code class="option">-n</code><br /></span><span class="term"><code class="option">--no-clean</code></span></dt><dd><p>
  180. By default, when <code class="command">initdb</code>
  181. determines that an error prevented it from completely creating the database
  182. cluster, it removes any files it might have created before discovering
  183. that it cannot finish the job. This option inhibits tidying-up and is
  184. thus useful for debugging.
  185. </p></dd></dl></div><p>
  186. </p><p>
  187. Other options:
  188. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-V</code><br /></span><span class="term"><code class="option">--version</code></span></dt><dd><p>
  189. Print the <span class="application">initdb</span> version and exit.
  190. </p></dd><dt><span class="term"><code class="option">-?</code><br /></span><span class="term"><code class="option">--help</code></span></dt><dd><p>
  191. Show help about <span class="application">initdb</span> command line
  192. arguments, and exit.
  193. </p></dd></dl></div><p>
  194. </p></div><div class="refsect1" id="id-1.9.5.3.7"><h2>Environment</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="envar">PGDATA</code></span></dt><dd><p>
  195. Specifies the directory where the database cluster is to be
  196. stored; can be overridden using the <code class="option">-D</code> option.
  197. </p></dd><dt><span class="term"><code class="envar">PG_COLOR</code></span></dt><dd><p>
  198. Specifies whether to use color in diagnostic messages. Possible values
  199. are <code class="literal">always</code>, <code class="literal">auto</code> and
  200. <code class="literal">never</code>.
  201. </p></dd><dt><span class="term"><code class="envar">TZ</code></span></dt><dd><p>
  202. Specifies the default time zone of the created database cluster. The
  203. value should be a full time zone name
  204. (see <a class="xref" href="datatype-datetime.html#DATATYPE-TIMEZONES" title="8.5.3. Time Zones">Section 8.5.3</a>).
  205. </p></dd></dl></div><p>
  206. This utility, like most other <span class="productname">PostgreSQL</span> utilities,
  207. also uses the environment variables supported by <span class="application">libpq</span>
  208. (see <a class="xref" href="libpq-envars.html" title="33.14. Environment Variables">Section 33.14</a>).
  209. </p></div><div class="refsect1" id="id-1.9.5.3.8"><h2>Notes</h2><p>
  210. <code class="command">initdb</code> can also be invoked via
  211. <code class="command">pg_ctl initdb</code>.
  212. </p></div><div class="refsect1" id="id-1.9.5.3.9"><h2>See Also</h2><span class="simplelist"><a class="xref" href="app-pg-ctl.html" title="pg_ctl"><span class="refentrytitle"><span class="application">pg_ctl</span></span></a>, <a class="xref" href="app-postgres.html" title="postgres"><span class="refentrytitle"><span class="application">postgres</span></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="reference-server.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="reference-server.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="pgarchivecleanup.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">PostgreSQL Server Applications </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">pg_archivecleanup</span></td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1