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.

439 lines
34KB

  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>postgres</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="pgwaldump.html" title="pg_waldump" /><link rel="next" href="app-postmaster.html" title="postmaster" /></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">postgres</span></th></tr><tr><td width="10%" align="left"><a accesskey="p" href="pgwaldump.html" title="pg_waldump">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="app-postmaster.html" title="postmaster">Next</a></td></tr></table><hr></hr></div><div class="refentry" id="APP-POSTGRES"><div class="titlepage"></div><a id="id-1.9.5.14.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle"><span class="application">postgres</span></span></h2><p>postgres — <span class="productname">PostgreSQL</span> database server</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis"><p id="id-1.9.5.14.4.1"><code class="command">postgres</code> [<em class="replaceable"><code>option</code></em>...]</p></div></div><div class="refsect1" id="id-1.9.5.14.5"><h2>Description</h2><p>
  3. <code class="command">postgres</code> is the
  4. <span class="productname">PostgreSQL</span> database server. In order
  5. for a client application to access a database it connects (over a
  6. network or locally) to a running <code class="command">postgres</code> instance.
  7. The <code class="command">postgres</code> instance then starts a separate server
  8. process to handle the connection.
  9. </p><p>
  10. One <code class="command">postgres</code> instance always manages the data of
  11. exactly one database cluster. A database cluster is a collection
  12. of databases that is stored at a common file system location (the
  13. <span class="quote">“<span class="quote">data area</span>”</span>). More than one
  14. <code class="command">postgres</code> instance can run on a system at one
  15. time, so long as they use different data areas and different
  16. communication ports (see below). When
  17. <code class="command">postgres</code> starts it needs to know the location
  18. of the data area. The location must be specified by the
  19. <code class="option">-D</code> option or the <code class="envar">PGDATA</code> environment
  20. variable; there is no default. Typically, <code class="option">-D</code> or
  21. <code class="envar">PGDATA</code> points directly to the data area directory
  22. created by <a class="xref" href="app-initdb.html" title="initdb"><span class="refentrytitle">initdb</span></a>. Other possible file layouts are
  23. discussed in <a class="xref" href="runtime-config-file-locations.html" title="19.2. File Locations">Section 19.2</a>.
  24. </p><p>
  25. By default <code class="command">postgres</code> starts in the
  26. foreground and prints log messages to the standard error stream. In
  27. practical applications <code class="command">postgres</code>
  28. should be started as a background process, perhaps at boot time.
  29. </p><p>
  30. The <code class="command">postgres</code> command can also be called in
  31. single-user mode. The primary use for this mode is during
  32. bootstrapping by <a class="xref" href="app-initdb.html" title="initdb"><span class="refentrytitle">initdb</span></a>. Sometimes it is used
  33. for debugging or disaster recovery; note that running a single-user
  34. server is not truly suitable for debugging the server, since no
  35. realistic interprocess communication and locking will happen.
  36. When invoked in single-user
  37. mode from the shell, the user can enter queries and the results
  38. will be printed to the screen, but in a form that is more useful
  39. for developers than end users. In the single-user mode,
  40. the session user will be set to the user with ID 1, and implicit
  41. superuser powers are granted to this user.
  42. This user does not actually have to exist, so the single-user mode
  43. can be used to manually recover from certain
  44. kinds of accidental damage to the system catalogs.
  45. </p></div><div class="refsect1" id="APP-POSTGRES-OPTIONS"><h2>Options</h2><p>
  46. <code class="command">postgres</code> accepts the following command-line
  47. arguments. For a detailed discussion of the options consult <a class="xref" href="runtime-config.html" title="Chapter 19. Server Configuration">Chapter 19</a>. You can save typing most of these
  48. options by setting up a configuration file. Some (safe) options
  49. can also be set from the connecting client in an
  50. application-dependent way to apply only for that session. For
  51. example, if the environment variable <code class="envar">PGOPTIONS</code> is
  52. set, then <span class="application">libpq</span>-based clients will pass that
  53. string to the server, which will interpret it as
  54. <code class="command">postgres</code> command-line options.
  55. </p><div class="refsect2" id="id-1.9.5.14.6.3"><h3>General Purpose</h3><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-B <em class="replaceable"><code>nbuffers</code></em></code></span></dt><dd><p>
  56. Sets the number of shared buffers for use by the server
  57. processes. The default value of this parameter is chosen
  58. automatically by <span class="application">initdb</span>.
  59. Specifying this option is equivalent to setting the
  60. <a class="xref" href="runtime-config-resource.html#GUC-SHARED-BUFFERS">shared_buffers</a> configuration parameter.
  61. </p></dd><dt><span class="term"><code class="option">-c <em class="replaceable"><code>name</code></em>=<em class="replaceable"><code>value</code></em></code></span></dt><dd><p>
  62. Sets a named run-time parameter. The configuration parameters
  63. supported by <span class="productname">PostgreSQL</span> are
  64. described in <a class="xref" href="runtime-config.html" title="Chapter 19. Server Configuration">Chapter 19</a>. Most of the
  65. other command line options are in fact short forms of such a
  66. parameter assignment. <code class="option">-c</code> can appear multiple times
  67. to set multiple parameters.
  68. </p></dd><dt><span class="term"><code class="option">-C <em class="replaceable"><code>name</code></em></code></span></dt><dd><p>
  69. Prints the value of the named run-time parameter, and exits.
  70. (See the <code class="option">-c</code> option above for details.) This can
  71. be used on a running server, and returns values from
  72. <code class="filename">postgresql.conf</code>, modified by any parameters
  73. supplied in this invocation. It does not reflect parameters
  74. supplied when the cluster was started.
  75. </p><p>
  76. This option is meant for other programs that interact with a server
  77. instance, such as <a class="xref" href="app-pg-ctl.html" title="pg_ctl"><span class="refentrytitle"><span class="application">pg_ctl</span></span></a>, to query configuration
  78. parameter values. User-facing applications should instead use <a class="xref" href="sql-show.html" title="SHOW"><span class="refentrytitle">SHOW</span></a> or the <code class="structname">pg_settings</code> view.
  79. </p></dd><dt><span class="term"><code class="option">-d <em class="replaceable"><code>debug-level</code></em></code></span></dt><dd><p>
  80. Sets the debug level. The higher this value is set, the more
  81. debugging output is written to the server log. Values are
  82. from 1 to 5. It is also possible to pass <code class="literal">-d
  83. 0</code> for a specific session, which will prevent the
  84. server log level of the parent <code class="command">postgres</code> process from being
  85. propagated to this session.
  86. </p></dd><dt><span class="term"><code class="option">-D <em class="replaceable"><code>datadir</code></em></code></span></dt><dd><p>
  87. Specifies the file system location of the database
  88. configuration files. See
  89. <a class="xref" href="runtime-config-file-locations.html" title="19.2. File Locations">Section 19.2</a> for details.
  90. </p></dd><dt><span class="term"><code class="option">-e</code></span></dt><dd><p>
  91. Sets the default date style to <span class="quote">“<span class="quote">European</span>”</span>, that is
  92. <code class="literal">DMY</code> ordering of input date fields. This also causes
  93. the day to be printed before the month in certain date output formats.
  94. See <a class="xref" href="datatype-datetime.html" title="8.5. Date/Time Types">Section 8.5</a> for more information.
  95. </p></dd><dt><span class="term"><code class="option">-F</code></span></dt><dd><p>
  96. Disables <code class="function">fsync</code> calls for improved
  97. performance, at the risk of data corruption in the event of a
  98. system crash. Specifying this option is equivalent to
  99. disabling the <a class="xref" href="runtime-config-wal.html#GUC-FSYNC">fsync</a> configuration
  100. parameter. Read the detailed documentation before using this!
  101. </p></dd><dt><span class="term"><code class="option">-h <em class="replaceable"><code>hostname</code></em></code></span></dt><dd><p>
  102. Specifies the IP host name or address on which
  103. <code class="command">postgres</code> is to listen for TCP/IP
  104. connections from client applications. The value can also be a
  105. comma-separated list of addresses, or <code class="literal">*</code> to specify
  106. listening on all available interfaces. An empty value
  107. specifies not listening on any IP addresses, in which case
  108. only Unix-domain sockets can be used to connect to the
  109. server. Defaults to listening only on
  110. <span class="systemitem">localhost</span>.
  111. Specifying this option is equivalent to setting the <a class="xref" href="runtime-config-connection.html#GUC-LISTEN-ADDRESSES">listen_addresses</a> configuration parameter.
  112. </p></dd><dt><span class="term"><code class="option">-i</code></span></dt><dd><p>
  113. Allows remote clients to connect via TCP/IP (Internet domain)
  114. connections. Without this option, only local connections are
  115. accepted. This option is equivalent to setting
  116. <code class="varname">listen_addresses</code> to <code class="literal">*</code> in
  117. <code class="filename">postgresql.conf</code> or via <code class="option">-h</code>.
  118. </p><p>
  119. This option is deprecated since it does not allow access to the
  120. full functionality of <a class="xref" href="runtime-config-connection.html#GUC-LISTEN-ADDRESSES">listen_addresses</a>.
  121. It's usually better to set <code class="varname">listen_addresses</code> directly.
  122. </p></dd><dt><span class="term"><code class="option">-k <em class="replaceable"><code>directory</code></em></code></span></dt><dd><p>
  123. Specifies the directory of the Unix-domain socket on which
  124. <code class="command">postgres</code> is to listen for
  125. connections from client applications. The value can also be a
  126. comma-separated list of directories. An empty value
  127. specifies not listening on any Unix-domain sockets, in which case
  128. only TCP/IP sockets can be used to connect to the server.
  129. The default value is normally
  130. <code class="filename">/tmp</code>, but that can be changed at build time.
  131. Specifying this option is equivalent to setting the <a class="xref" href="runtime-config-connection.html#GUC-UNIX-SOCKET-DIRECTORIES">unix_socket_directories</a> configuration parameter.
  132. </p></dd><dt><span class="term"><code class="option">-l</code></span></dt><dd><p>
  133. Enables secure connections using <acronym class="acronym">SSL</acronym>.
  134. <span class="productname">PostgreSQL</span> must have been compiled with
  135. support for <acronym class="acronym">SSL</acronym> for this option to be
  136. available. For more information on using <acronym class="acronym">SSL</acronym>,
  137. refer to <a class="xref" href="ssl-tcp.html" title="18.9. Secure TCP/IP Connections with SSL">Section 18.9</a>.
  138. </p></dd><dt><span class="term"><code class="option">-N <em class="replaceable"><code>max-connections</code></em></code></span></dt><dd><p>
  139. Sets the maximum number of client connections that this
  140. server will accept. The default value of this parameter is chosen
  141. automatically by <span class="application">initdb</span>.
  142. Specifying this option is equivalent to setting the
  143. <a class="xref" href="runtime-config-connection.html#GUC-MAX-CONNECTIONS">max_connections</a> configuration parameter.
  144. </p></dd><dt><span class="term"><code class="option">-o <em class="replaceable"><code>extra-options</code></em></code></span></dt><dd><p>
  145. The command-line-style arguments specified in <em class="replaceable"><code>extra-options</code></em> are passed to
  146. all server processes started by this
  147. <code class="command">postgres</code> process.
  148. </p><p>
  149. Spaces within <em class="replaceable"><code>extra-options</code></em> are
  150. considered to separate arguments, unless escaped with a backslash
  151. (<code class="literal">\</code>); write <code class="literal">\\</code> to represent a literal
  152. backslash. Multiple arguments can also be specified via multiple
  153. uses of <code class="option">-o</code>.
  154. </p><p>
  155. The use of this option is obsolete; all command-line options
  156. for server processes can be specified directly on the
  157. <code class="command">postgres</code> command line.
  158. </p></dd><dt><span class="term"><code class="option">-p <em class="replaceable"><code>port</code></em></code></span></dt><dd><p>
  159. Specifies the TCP/IP port or local Unix domain socket file
  160. extension on which <code class="command">postgres</code>
  161. is to listen for connections from client applications.
  162. Defaults to the value of the <code class="envar">PGPORT</code> environment
  163. variable, or if <code class="envar">PGPORT</code> is not set, then
  164. defaults to the value established during compilation (normally
  165. 5432). If you specify a port other than the default port,
  166. then all client applications must specify the same port using
  167. either command-line options or <code class="envar">PGPORT</code>.
  168. </p></dd><dt><span class="term"><code class="option">-s</code></span></dt><dd><p>
  169. Print time information and other statistics at the end of each command.
  170. This is useful for benchmarking or for use in tuning the number of
  171. buffers.
  172. </p></dd><dt><span class="term"><code class="option">-S</code> <em class="replaceable"><code>work-mem</code></em></span></dt><dd><p>
  173. Specifies the amount of memory to be used by internal sorts and hashes
  174. before resorting to temporary disk files. See the description of the
  175. <code class="varname">work_mem</code> configuration parameter in <a class="xref" href="runtime-config-resource.html#RUNTIME-CONFIG-RESOURCE-MEMORY" title="19.4.1. Memory">Section 19.4.1</a>.
  176. </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>
  177. Print the <span class="application">postgres</span> version and exit.
  178. </p></dd><dt><span class="term"><code class="option">--<em class="replaceable"><code>name</code></em>=<em class="replaceable"><code>value</code></em></code></span></dt><dd><p>
  179. Sets a named run-time parameter; a shorter form of
  180. <code class="option">-c</code>.
  181. </p></dd><dt><span class="term"><code class="option">--describe-config</code></span></dt><dd><p>
  182. This option dumps out the server's internal configuration variables,
  183. descriptions, and defaults in tab-delimited <code class="command">COPY</code> format.
  184. It is designed primarily for use by administration tools.
  185. </p></dd><dt><span class="term"><code class="option">-?</code><br /></span><span class="term"><code class="option">--help</code></span></dt><dd><p>
  186. Show help about <span class="application">postgres</span> command line
  187. arguments, and exit.
  188. </p></dd></dl></div></div><div class="refsect2" id="id-1.9.5.14.6.4"><h3>Semi-Internal Options</h3><p>
  189. The options described here are used
  190. mainly for debugging purposes, and in some cases to assist with
  191. recovery of severely damaged databases. There should be no reason
  192. to use them in a production database setup. They are listed
  193. here only for use by <span class="productname">PostgreSQL</span>
  194. system developers. Furthermore, these options might
  195. change or be removed in a future release without notice.
  196. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-f</code> <code class="literal">{ s | i | o | b | t | n | m | h }</code></span></dt><dd><p>
  197. Forbids the use of particular scan and join methods:
  198. <code class="literal">s</code> and <code class="literal">i</code>
  199. disable sequential and index scans respectively,
  200. <code class="literal">o</code>, <code class="literal">b</code> and <code class="literal">t</code>
  201. disable index-only scans, bitmap index scans, and TID scans
  202. respectively, while
  203. <code class="literal">n</code>, <code class="literal">m</code>, and <code class="literal">h</code>
  204. disable nested-loop, merge and hash joins respectively.
  205. </p><p>
  206. Neither sequential scans nor nested-loop joins can be disabled
  207. completely; the <code class="literal">-fs</code> and
  208. <code class="literal">-fn</code> options simply discourage the optimizer
  209. from using those plan types if it has any other alternative.
  210. </p></dd><dt><span class="term"><code class="option">-n</code></span></dt><dd><p>
  211. This option is for debugging problems that cause a server
  212. process to die abnormally. The ordinary strategy in this
  213. situation is to notify all other server processes that they
  214. must terminate and then reinitialize the shared memory and
  215. semaphores. This is because an errant server process could
  216. have corrupted some shared state before terminating. This
  217. option specifies that <code class="command">postgres</code> will
  218. not reinitialize shared data structures. A knowledgeable
  219. system programmer can then use a debugger to examine shared
  220. memory and semaphore state.
  221. </p></dd><dt><span class="term"><code class="option">-O</code></span></dt><dd><p>
  222. Allows the structure of system tables to be modified. This is
  223. used by <code class="command">initdb</code>.
  224. </p></dd><dt><span class="term"><code class="option">-P</code></span></dt><dd><p>
  225. Ignore system indexes when reading system tables, but still update
  226. the indexes when modifying the tables. This is useful when
  227. recovering from damaged system indexes.
  228. </p></dd><dt><span class="term"><code class="option">-t</code> <code class="literal">pa[rser] | pl[anner] | e[xecutor]</code></span></dt><dd><p>
  229. Print timing statistics for each query relating to each of the
  230. major system modules. This option cannot be used together
  231. with the <code class="option">-s</code> option.
  232. </p></dd><dt><span class="term"><code class="option">-T</code></span></dt><dd><p>
  233. This option is for debugging problems that cause a server
  234. process to die abnormally. The ordinary strategy in this
  235. situation is to notify all other server processes that they
  236. must terminate and then reinitialize the shared memory and
  237. semaphores. This is because an errant server process could
  238. have corrupted some shared state before terminating. This
  239. option specifies that <code class="command">postgres</code> will
  240. stop all other server processes by sending the signal
  241. <code class="literal">SIGSTOP</code>, but will not cause them to
  242. terminate. This permits system programmers to collect core
  243. dumps from all server processes by hand.
  244. </p></dd><dt><span class="term"><code class="option">-v</code> <em class="replaceable"><code>protocol</code></em></span></dt><dd><p>
  245. Specifies the version number of the frontend/backend protocol
  246. to be used for a particular session. This option is for
  247. internal use only.
  248. </p></dd><dt><span class="term"><code class="option">-W</code> <em class="replaceable"><code>seconds</code></em></span></dt><dd><p>
  249. A delay of this many seconds occurs when a new server process
  250. is started, after it conducts the authentication procedure.
  251. This is intended to give an opportunity to attach to the
  252. server process with a debugger.
  253. </p></dd></dl></div></div><div class="refsect2" id="id-1.9.5.14.6.5"><h3>Options for Single-User Mode</h3><a id="id-1.9.5.14.6.5.2" class="indexterm"></a><p>
  254. The following options only apply to the single-user mode
  255. (see <a class="xref" href="app-postgres.html#APP-POSTGRES-SINGLE-USER" title="Single-User Mode">Single-User Mode</a>).
  256. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">--single</code></span></dt><dd><p>
  257. Selects the single-user mode. This must be the first argument
  258. on the command line.
  259. </p></dd><dt><span class="term"><em class="replaceable"><code>database</code></em></span></dt><dd><p>
  260. Specifies the name of the database to be accessed. This must be
  261. the last argument on the command line. If it is
  262. omitted it defaults to the user name.
  263. </p></dd><dt><span class="term"><code class="option">-E</code></span></dt><dd><p>
  264. Echo all commands to standard output before executing them.
  265. </p></dd><dt><span class="term"><code class="option">-j</code></span></dt><dd><p>
  266. Use semicolon followed by two newlines, rather than just newline,
  267. as the command entry terminator.
  268. </p></dd><dt><span class="term"><code class="option">-r</code> <em class="replaceable"><code>filename</code></em></span></dt><dd><p>
  269. Send all server log output to <em class="replaceable"><code>filename</code></em>. This option is only
  270. honored when supplied as a command-line option.
  271. </p></dd></dl></div></div></div><div class="refsect1" id="id-1.9.5.14.7"><h2>Environment</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="envar">PGCLIENTENCODING</code></span></dt><dd><p>
  272. Default character encoding used by clients. (The clients can
  273. override this individually.) This value can also be set in the
  274. configuration file.
  275. </p></dd><dt><span class="term"><code class="envar">PGDATA</code></span></dt><dd><p>
  276. Default data directory location
  277. </p></dd><dt><span class="term"><code class="envar">PGDATESTYLE</code></span></dt><dd><p>
  278. Default value of the <a class="xref" href="runtime-config-client.html#GUC-DATESTYLE">DateStyle</a> run-time
  279. parameter. (The use of this environment variable is deprecated.)
  280. </p></dd><dt><span class="term"><code class="envar">PGPORT</code></span></dt><dd><p>
  281. Default port number (preferably set in the configuration file)
  282. </p></dd></dl></div></div><div class="refsect1" id="id-1.9.5.14.8"><h2>Diagnostics</h2><p>
  283. A failure message mentioning <code class="literal">semget</code> or
  284. <code class="literal">shmget</code> probably indicates you need to configure your
  285. kernel to provide adequate shared memory and semaphores. For more
  286. discussion see <a class="xref" href="kernel-resources.html" title="18.4. Managing Kernel Resources">Section 18.4</a>. You might be able
  287. to postpone reconfiguring your kernel by decreasing <a class="xref" href="runtime-config-resource.html#GUC-SHARED-BUFFERS">shared_buffers</a> to reduce the shared memory
  288. consumption of <span class="productname">PostgreSQL</span>, and/or by reducing
  289. <a class="xref" href="runtime-config-connection.html#GUC-MAX-CONNECTIONS">max_connections</a> to reduce the semaphore
  290. consumption.
  291. </p><p>
  292. A failure message suggesting that another server is already running
  293. should be checked carefully, for example by using the command
  294. </p><pre class="screen">
  295. <code class="prompt">$</code> <strong class="userinput"><code>ps ax | grep postgres</code></strong>
  296. </pre><p>
  297. or
  298. </p><pre class="screen">
  299. <code class="prompt">$</code> <strong class="userinput"><code>ps -ef | grep postgres</code></strong>
  300. </pre><p>
  301. depending on your system. If you are certain that no conflicting
  302. server is running, you can remove the lock file mentioned in the
  303. message and try again.
  304. </p><p>
  305. A failure message indicating inability to bind to a port might
  306. indicate that that port is already in use by some
  307. non-<span class="productname">PostgreSQL</span> process. You might also
  308. get this error if you terminate <code class="command">postgres</code>
  309. and immediately restart it using the same port; in this case, you
  310. must simply wait a few seconds until the operating system closes
  311. the port before trying again. Finally, you might get this error if
  312. you specify a port number that your operating system considers to
  313. be reserved. For example, many versions of Unix consider port
  314. numbers under 1024 to be <span class="quote">“<span class="quote">trusted</span>”</span> and only permit
  315. the Unix superuser to access them.
  316. </p></div><div class="refsect1" id="id-1.9.5.14.9"><h2>Notes</h2><p>
  317. The utility command <a class="xref" href="app-pg-ctl.html" title="pg_ctl"><span class="refentrytitle"><span class="application">pg_ctl</span></span></a> can be used to
  318. start and shut down the <code class="command">postgres</code> server
  319. safely and comfortably.
  320. </p><p>
  321. If at all possible, <span class="emphasis"><em>do not</em></span> use
  322. <code class="literal">SIGKILL</code> to kill the main
  323. <code class="command">postgres</code> server. Doing so will prevent
  324. <code class="command">postgres</code> from freeing the system
  325. resources (e.g., shared memory and semaphores) that it holds before
  326. terminating. This might cause problems for starting a fresh
  327. <code class="command">postgres</code> run.
  328. </p><p>
  329. To terminate the <code class="command">postgres</code> server normally, the
  330. signals <code class="literal">SIGTERM</code>, <code class="literal">SIGINT</code>, or
  331. <code class="literal">SIGQUIT</code> can be used. The first will wait for
  332. all clients to terminate before quitting, the second will
  333. forcefully disconnect all clients, and the third will quit
  334. immediately without proper shutdown, resulting in a recovery run
  335. during restart.
  336. </p><p>
  337. The <code class="literal">SIGHUP</code> signal will reload
  338. the server configuration files. It is also possible to send
  339. <code class="literal">SIGHUP</code> to an individual server process, but that
  340. is usually not sensible.
  341. </p><p>
  342. To cancel a running query, send the <code class="literal">SIGINT</code> signal
  343. to the process running that command. To terminate a backend process
  344. cleanly, send <code class="literal">SIGTERM</code> to that process. See
  345. also <code class="function">pg_cancel_backend</code> and <code class="function">pg_terminate_backend</code>
  346. in <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-SIGNAL" title="9.26.2. Server Signaling Functions">Section 9.26.2</a> for the SQL-callable equivalents
  347. of these two actions.
  348. </p><p>
  349. The <code class="command">postgres</code> server uses <code class="literal">SIGQUIT</code>
  350. to tell subordinate server processes to terminate without normal
  351. cleanup.
  352. This signal <span class="emphasis"><em>should not</em></span> be used by users. It
  353. is also unwise to send <code class="literal">SIGKILL</code> to a server
  354. process — the main <code class="command">postgres</code> process will
  355. interpret this as a crash and will force all the sibling processes
  356. to quit as part of its standard crash-recovery procedure.
  357. </p></div><div class="refsect1" id="APP-POSTGRES-BUGS"><h2>Bugs</h2><p>
  358. The <code class="option">--</code> options will not work on <span class="systemitem">FreeBSD</span> or <span class="systemitem">OpenBSD</span>.
  359. Use <code class="option">-c</code> instead. This is a bug in the affected operating
  360. systems; a future release of <span class="productname">PostgreSQL</span>
  361. will provide a workaround if this is not fixed.
  362. </p></div><div class="refsect1" id="APP-POSTGRES-SINGLE-USER"><h2>Single-User Mode</h2><p>
  363. To start a single-user mode server, use a command like
  364. </p><pre class="screen">
  365. <strong class="userinput"><code>postgres --single -D /usr/local/pgsql/data <em class="replaceable"><code>other-options</code></em> my_database</code></strong>
  366. </pre><p>
  367. Provide the correct path to the database directory with <code class="option">-D</code>, or
  368. make sure that the environment variable <code class="envar">PGDATA</code> is set.
  369. Also specify the name of the particular database you want to work in.
  370. </p><p>
  371. Normally, the single-user mode server treats newline as the command
  372. entry terminator; there is no intelligence about semicolons,
  373. as there is in <span class="application">psql</span>. To continue a command
  374. across multiple lines, you must type backslash just before each
  375. newline except the last one. The backslash and adjacent newline are
  376. both dropped from the input command. Note that this will happen even
  377. when within a string literal or comment.
  378. </p><p>
  379. But if you use the <code class="option">-j</code> command line switch, a single newline
  380. does not terminate command entry; instead, the sequence
  381. semicolon-newline-newline does. That is, type a semicolon immediately
  382. followed by a completely empty line. Backslash-newline is not
  383. treated specially in this mode. Again, there is no intelligence about
  384. such a sequence appearing within a string literal or comment.
  385. </p><p>
  386. In either input mode, if you type a semicolon that is not just before or
  387. part of a command entry terminator, it is considered a command separator.
  388. When you do type a command entry terminator, the multiple statements
  389. you've entered will be executed as a single transaction.
  390. </p><p>
  391. To quit the session, type <acronym class="acronym">EOF</acronym>
  392. (<span class="keycap"><strong>Control</strong></span>+<span class="keycap"><strong>D</strong></span>, usually).
  393. If you've entered any text since the last command entry terminator,
  394. then <acronym class="acronym">EOF</acronym> will be taken as a command entry terminator,
  395. and another <acronym class="acronym">EOF</acronym> will be needed to exit.
  396. </p><p>
  397. Note that the single-user mode server does not provide sophisticated
  398. line-editing features (no command history, for example).
  399. Single-user mode also does not do any background processing, such as
  400. automatic checkpoints or replication.
  401. </p></div><div class="refsect1" id="APP-POSTGRES-EXAMPLES"><h2>Examples</h2><p>
  402. To start <code class="command">postgres</code> in the background
  403. using default values, type:
  404. </p><pre class="screen">
  405. <code class="prompt">$</code> <strong class="userinput"><code>nohup postgres &gt;logfile 2&gt;&amp;1 &lt;/dev/null &amp;</code></strong>
  406. </pre><p>
  407. </p><p>
  408. To start <code class="command">postgres</code> with a specific
  409. port, e.g. 1234:
  410. </p><pre class="screen">
  411. <code class="prompt">$</code> <strong class="userinput"><code>postgres -p 1234</code></strong>
  412. </pre><p>
  413. To connect to this server using <span class="application">psql</span>, specify this port with the -p option:
  414. </p><pre class="screen">
  415. <code class="prompt">$</code> <strong class="userinput"><code>psql -p 1234</code></strong>
  416. </pre><p>
  417. or set the environment variable <code class="envar">PGPORT</code>:
  418. </p><pre class="screen">
  419. <code class="prompt">$</code> <strong class="userinput"><code>export PGPORT=1234</code></strong>
  420. <code class="prompt">$</code> <strong class="userinput"><code>psql</code></strong>
  421. </pre><p>
  422. </p><p>
  423. Named run-time parameters can be set in either of these styles:
  424. </p><pre class="screen">
  425. <code class="prompt">$</code> <strong class="userinput"><code>postgres -c work_mem=1234</code></strong>
  426. <code class="prompt">$</code> <strong class="userinput"><code>postgres --work-mem=1234</code></strong>
  427. </pre><p>
  428. Either form overrides whatever setting might exist for
  429. <code class="varname">work_mem</code> in <code class="filename">postgresql.conf</code>. Notice that
  430. underscores in parameter names can be written as either underscore
  431. or dash on the command line. Except for short-term experiments,
  432. it's probably better practice to edit the setting in
  433. <code class="filename">postgresql.conf</code> than to rely on a command-line switch
  434. to set a parameter.
  435. </p></div><div class="refsect1" id="id-1.9.5.14.13"><h2>See Also</h2><p>
  436. <a class="xref" href="app-initdb.html" title="initdb"><span class="refentrytitle">initdb</span></a>,
  437. <a class="xref" href="app-pg-ctl.html" title="pg_ctl"><span class="refentrytitle"><span class="application">pg_ctl</span></span></a>
  438. </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="pgwaldump.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="app-postmaster.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="application">pg_waldump</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">postmaster</span></td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1