gooderp18绿色标准版
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

211 linhas
19KB

  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>pg_receivewal</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-pg-isready.html" title="pg_isready" /><link rel="next" href="app-pgrecvlogical.html" title="pg_recvlogical" /></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">pg_receivewal</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="app-pg-isready.html" title="pg_isready">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-pgrecvlogical.html" title="pg_recvlogical">Next</a></td></tr></table><hr></hr></div><div class="refentry" id="APP-PGRECEIVEWAL"><div class="titlepage"></div><a id="id-1.9.4.15.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">pg_receivewal</span></h2><p>pg_receivewal — stream write-ahead logs from a <span class="productname">PostgreSQL</span> server</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis"><p id="id-1.9.4.15.4.1"><code class="command">pg_receivewal</code> [<em class="replaceable"><code>option</code></em>...]</p></div></div><div class="refsect1" id="id-1.9.4.15.5"><h2>
  3. Description
  4. </h2><p>
  5. <span class="application">pg_receivewal</span> is used to stream the write-ahead log
  6. from a running <span class="productname">PostgreSQL</span> cluster. The write-ahead
  7. log is streamed using the streaming replication protocol, and is written
  8. to a local directory of files. This directory can be used as the archive
  9. location for doing a restore using point-in-time recovery (see
  10. <a class="xref" href="continuous-archiving.html" title="25.3. Continuous Archiving and Point-in-Time Recovery (PITR)">Section 25.3</a>).
  11. </p><p>
  12. <span class="application">pg_receivewal</span> streams the write-ahead
  13. log in real time as it's being generated on the server, and does not wait
  14. for segments to complete like <a class="xref" href="runtime-config-wal.html#GUC-ARCHIVE-COMMAND">archive_command</a> does.
  15. For this reason, it is not necessary to set
  16. <a class="xref" href="runtime-config-wal.html#GUC-ARCHIVE-TIMEOUT">archive_timeout</a> when using
  17. <span class="application">pg_receivewal</span>.
  18. </p><p>
  19. Unlike the WAL receiver of a PostgreSQL standby server, <span class="application">pg_receivewal</span>
  20. by default flushes WAL data only when a WAL file is closed.
  21. The option <code class="option">--synchronous</code> must be specified to flush WAL data
  22. in real time. Since <span class="application">pg_receivewal</span> does not
  23. apply WAL, you should not allow it to become a synchronous standby when
  24. <a class="xref" href="runtime-config-wal.html#GUC-SYNCHRONOUS-COMMIT">synchronous_commit</a> equals
  25. <code class="literal">remote_apply</code>. If it does, it will appear to be a
  26. standby that never catches up, and will cause transaction commits to
  27. block. To avoid this, you should either configure an appropriate value
  28. for <a class="xref" href="runtime-config-replication.html#GUC-SYNCHRONOUS-STANDBY-NAMES">synchronous_standby_names</a>, or specify
  29. <code class="varname">application_name</code> for
  30. <span class="application">pg_receivewal</span> that does not match it, or
  31. change the value of <code class="varname">synchronous_commit</code> to
  32. something other than <code class="literal">remote_apply</code>.
  33. </p><p>
  34. The write-ahead log is streamed over a regular
  35. <span class="productname">PostgreSQL</span> connection and uses the replication
  36. protocol. The connection must be made with a superuser or a user
  37. having <code class="literal">REPLICATION</code> permissions (see
  38. <a class="xref" href="role-attributes.html" title="21.2. Role Attributes">Section 21.2</a>), and <code class="filename">pg_hba.conf</code>
  39. must permit the replication connection. The server must also be
  40. configured with <a class="xref" href="runtime-config-replication.html#GUC-MAX-WAL-SENDERS">max_wal_senders</a> set high enough to
  41. leave at least one session available for the stream.
  42. </p><p>
  43. If the connection is lost, or if it cannot be initially established,
  44. with a non-fatal error, <span class="application">pg_receivewal</span> will
  45. retry the connection indefinitely, and reestablish streaming as soon
  46. as possible. To avoid this behavior, use the <code class="literal">-n</code>
  47. parameter.
  48. </p><p>
  49. In the absence of fatal errors, <span class="application">pg_receivewal</span>
  50. will run until terminated by the <span class="systemitem">SIGINT</span> signal
  51. (<span class="keycap"><strong>Control</strong></span>+<span class="keycap"><strong>C</strong></span>).
  52. </p></div><div class="refsect1" id="id-1.9.4.15.6"><h2>Options</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-D <em class="replaceable"><code>directory</code></em></code><br /></span><span class="term"><code class="option">--directory=<em class="replaceable"><code>directory</code></em></code></span></dt><dd><p>
  53. Directory to write the output to.
  54. </p><p>
  55. This parameter is required.
  56. </p></dd><dt><span class="term"><code class="option">-E <em class="replaceable"><code>lsn</code></em></code><br /></span><span class="term"><code class="option">--endpos=<em class="replaceable"><code>lsn</code></em></code></span></dt><dd><p>
  57. Automatically stop replication and exit with normal exit status 0 when
  58. receiving reaches the specified LSN.
  59. </p><p>
  60. If there is a record with LSN exactly equal to <em class="replaceable"><code>lsn</code></em>,
  61. the record will be processed.
  62. </p></dd><dt><span class="term"><code class="option">--if-not-exists</code></span></dt><dd><p>
  63. Do not error out when <code class="option">--create-slot</code> is specified
  64. and a slot with the specified name already exists.
  65. </p></dd><dt><span class="term"><code class="option">-n</code><br /></span><span class="term"><code class="option">--no-loop</code></span></dt><dd><p>
  66. Don't loop on connection errors. Instead, exit right away with
  67. an error.
  68. </p></dd><dt><span class="term"><code class="option">--no-sync</code></span></dt><dd><p>
  69. This option causes <code class="command">pg_receivewal</code> to not force WAL
  70. data to be flushed to disk. This is faster, but means that a
  71. subsequent operating system crash can leave the WAL segments corrupt.
  72. Generally, this option is useful for testing but should not be used
  73. when doing WAL archiving on a production deployment.
  74. </p><p>
  75. This option is incompatible with <code class="literal">--synchronous</code>.
  76. </p></dd><dt><span class="term"><code class="option">-s <em class="replaceable"><code>interval</code></em></code><br /></span><span class="term"><code class="option">--status-interval=<em class="replaceable"><code>interval</code></em></code></span></dt><dd><p>
  77. Specifies the number of seconds between status packets sent back to the
  78. server. This allows for easier monitoring of the progress from server.
  79. A value of zero disables the periodic status updates completely,
  80. although an update will still be sent when requested by the server, to
  81. avoid timeout disconnect. The default value is 10 seconds.
  82. </p></dd><dt><span class="term"><code class="option">-S <em class="replaceable"><code>slotname</code></em></code><br /></span><span class="term"><code class="option">--slot=<em class="replaceable"><code>slotname</code></em></code></span></dt><dd><p>
  83. Require <span class="application">pg_receivewal</span> to use an existing
  84. replication slot (see <a class="xref" href="warm-standby.html#STREAMING-REPLICATION-SLOTS" title="26.2.6. Replication Slots">Section 26.2.6</a>).
  85. When this option is used, <span class="application">pg_receivewal</span> will report
  86. a flush position to the server, indicating when each segment has been
  87. synchronized to disk so that the server can remove that segment if it
  88. is not otherwise needed.
  89. </p><p>
  90. When the replication client
  91. of <span class="application">pg_receivewal</span> is configured on the
  92. server as a synchronous standby, then using a replication slot will
  93. report the flush position to the server, but only when a WAL file is
  94. closed. Therefore, that configuration will cause transactions on the
  95. primary to wait for a long time and effectively not work
  96. satisfactorily. The option <code class="literal">--synchronous</code> (see
  97. below) must be specified in addition to make this work correctly.
  98. </p></dd><dt><span class="term"><code class="option">--synchronous</code></span></dt><dd><p>
  99. Flush the WAL data to disk immediately after it has been received. Also
  100. send a status packet back to the server immediately after flushing,
  101. regardless of <code class="literal">--status-interval</code>.
  102. </p><p>
  103. This option should be specified if the replication client
  104. of <span class="application">pg_receivewal</span> is configured on the
  105. server as a synchronous standby, to ensure that timely feedback is
  106. sent to the server.
  107. </p></dd><dt><span class="term"><code class="option">-v</code><br /></span><span class="term"><code class="option">--verbose</code></span></dt><dd><p>
  108. Enables verbose mode.
  109. </p></dd><dt><span class="term"><code class="option">-Z <em class="replaceable"><code>level</code></em></code><br /></span><span class="term"><code class="option">--compress=<em class="replaceable"><code>level</code></em></code></span></dt><dd><p>
  110. Enables gzip compression of write-ahead logs, and specifies the
  111. compression level (0 through 9, 0 being no compression and 9 being best
  112. compression). The suffix <code class="filename">.gz</code> will
  113. automatically be added to all filenames.
  114. </p></dd></dl></div><p>
  115. The following command-line options control the database connection parameters.
  116. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-d <em class="replaceable"><code>connstr</code></em></code><br /></span><span class="term"><code class="option">--dbname=<em class="replaceable"><code>connstr</code></em></code></span></dt><dd><p>
  117. Specifies parameters used to connect to the server, as a connection
  118. string. See <a class="xref" href="libpq-connect.html#LIBPQ-CONNSTRING" title="33.1.1. Connection Strings">Section 33.1.1</a> for more information.
  119. </p><p>
  120. The option is called <code class="literal">--dbname</code> for consistency with other
  121. client applications, but because <span class="application">pg_receivewal</span>
  122. doesn't connect to any particular database in the cluster, database
  123. name in the connection string will be ignored.
  124. </p></dd><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>
  125. Specifies the host name of the machine on which the server is
  126. running. If the value begins with a slash, it is used as the
  127. directory for the Unix domain socket. The default is taken
  128. from the <code class="envar">PGHOST</code> environment variable, if set,
  129. else a Unix domain socket connection is attempted.
  130. </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>
  131. Specifies the TCP port or local Unix domain socket file
  132. extension on which the server is listening for connections.
  133. Defaults to the <code class="envar">PGPORT</code> environment variable, if
  134. set, or a compiled-in default.
  135. </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>
  136. User name to connect as.
  137. </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>
  138. Never issue a password prompt. If the server requires
  139. password authentication and a password is not available by
  140. other means such as a <code class="filename">.pgpass</code> file, the
  141. connection attempt will fail. This option can be useful in
  142. batch jobs and scripts where no user is present to enter a
  143. password.
  144. </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>
  145. Force <span class="application">pg_receivewal</span> to prompt for a
  146. password before connecting to a database.
  147. </p><p>
  148. This option is never essential, since
  149. <span class="application">pg_receivewal</span> will automatically prompt
  150. for a password if the server demands password authentication.
  151. However, <span class="application">pg_receivewal</span> will waste a
  152. connection attempt finding out that the server wants a password.
  153. In some cases it is worth typing <code class="option">-W</code> to avoid the extra
  154. connection attempt.
  155. </p></dd></dl></div><p>
  156. </p><p>
  157. <span class="application">pg_receivewal</span> can perform one of the two
  158. following actions in order to control physical replication slots:
  159. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">--create-slot</code></span></dt><dd><p>
  160. Create a new physical replication slot with the name specified in
  161. <code class="option">--slot</code>, then exit.
  162. </p></dd><dt><span class="term"><code class="option">--drop-slot</code></span></dt><dd><p>
  163. Drop the replication slot with the name specified in
  164. <code class="option">--slot</code>, then exit.
  165. </p></dd></dl></div><p>
  166. </p><p>
  167. Other options are also available:
  168. </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>
  169. Print the <span class="application">pg_receivewal</span> version and exit.
  170. </p></dd><dt><span class="term"><code class="option">-?</code><br /></span><span class="term"><code class="option">--help</code></span></dt><dd><p>
  171. Show help about <span class="application">pg_receivewal</span> command line
  172. arguments, and exit.
  173. </p></dd></dl></div><p>
  174. </p></div><div class="refsect1" id="id-1.9.4.15.7"><h2>Exit Status</h2><p>
  175. <span class="application">pg_receivewal</span> will exit with status 0 when
  176. terminated by the <span class="systemitem">SIGINT</span> signal. (That is the
  177. normal way to end it. Hence it is not an error.) For fatal errors or
  178. other signals, the exit status will be nonzero.
  179. </p></div><div class="refsect1" id="id-1.9.4.15.8"><h2>Environment</h2><p>
  180. This utility, like most other <span class="productname">PostgreSQL</span> utilities,
  181. uses the environment variables supported by <span class="application">libpq</span>
  182. (see <a class="xref" href="libpq-envars.html" title="33.14. Environment Variables">Section 33.14</a>).
  183. </p><p>
  184. The environment variable <code class="envar">PG_COLOR</code> specifies whether to use
  185. color in diagnostic messages. Possible values are
  186. <code class="literal">always</code>, <code class="literal">auto</code> and
  187. <code class="literal">never</code>.
  188. </p></div><div class="refsect1" id="id-1.9.4.15.9"><h2>Notes</h2><p>
  189. When using <span class="application">pg_receivewal</span> instead of
  190. <a class="xref" href="runtime-config-wal.html#GUC-ARCHIVE-COMMAND">archive_command</a> as the main WAL backup method, it is
  191. strongly recommended to use replication slots. Otherwise, the server is
  192. free to recycle or remove write-ahead log files before they are backed up,
  193. because it does not have any information, either
  194. from <a class="xref" href="runtime-config-wal.html#GUC-ARCHIVE-COMMAND">archive_command</a> or the replication slots, about
  195. how far the WAL stream has been archived. Note, however, that a
  196. replication slot will fill up the server's disk space if the receiver does
  197. not keep up with fetching the WAL data.
  198. </p><p>
  199. <span class="application">pg_receivewal</span> will preserve group permissions on
  200. the received WAL files if group permissions are enabled on the source
  201. cluster.
  202. </p></div><div class="refsect1" id="id-1.9.4.15.10"><h2>Examples</h2><p>
  203. To stream the write-ahead log from the server at
  204. <code class="literal">mydbserver</code> and store it in the local directory
  205. <code class="filename">/usr/local/pgsql/archive</code>:
  206. </p><pre class="screen">
  207. <code class="prompt">$</code> <strong class="userinput"><code>pg_receivewal -h mydbserver -D /usr/local/pgsql/archive</code></strong>
  208. </pre></div><div class="refsect1" id="id-1.9.4.15.11"><h2>See Also</h2><span class="simplelist"><a class="xref" href="app-pgbasebackup.html" title="pg_basebackup"><span class="refentrytitle">pg_basebackup</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-pg-isready.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-pgrecvlogical.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="application">pg_isready</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">pg_recvlogical</span></td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1