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.

159 lines
16KB

  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_resetwal</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-ctl.html" title="pg_ctl" /><link rel="next" href="app-pgrewind.html" title="pg_rewind" /></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">pg_resetwal</span></th></tr><tr><td width="10%" align="left"><a accesskey="p" href="app-pg-ctl.html" title="pg_ctl">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-pgrewind.html" title="pg_rewind">Next</a></td></tr></table><hr></hr></div><div class="refentry" id="APP-PGRESETWAL"><div class="titlepage"></div><a id="id-1.9.5.8.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle"><span class="application">pg_resetwal</span></span></h2><p>pg_resetwal — reset the write-ahead log and other control information of a <span class="productname">PostgreSQL</span> database cluster</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis"><p id="id-1.9.5.8.4.1"><code class="command">pg_resetwal</code> [ <code class="option">--force</code> | <code class="option">-f</code> ] [ <code class="option">--dry-run</code> | <code class="option">-n</code> ] [<em class="replaceable"><code>option</code></em>...] [ <code class="option">--pgdata</code> | <code class="option">-D</code> ]<em class="replaceable"><code> datadir</code></em> </p></div></div><div class="refsect1" id="R1-APP-PGRESETWAL-1"><h2>Description</h2><p>
  3. <code class="command">pg_resetwal</code> clears the write-ahead log (WAL) and
  4. optionally resets some other control information stored in the
  5. <code class="filename">pg_control</code> file. This function is sometimes needed
  6. if these files have become corrupted. It should be used only as a
  7. last resort, when the server will not start due to such corruption.
  8. </p><p>
  9. After running this command, it should be possible to start the server,
  10. but bear in mind that the database might contain inconsistent data due to
  11. partially-committed transactions. You should immediately dump your data,
  12. run <code class="command">initdb</code>, and reload. After reload, check for
  13. inconsistencies and repair as needed.
  14. </p><p>
  15. This utility can only be run by the user who installed the server, because
  16. it requires read/write access to the data directory.
  17. For safety reasons, you must specify the data directory on the command line.
  18. <code class="command">pg_resetwal</code> does not use the environment variable
  19. <code class="envar">PGDATA</code>.
  20. </p><p>
  21. If <code class="command">pg_resetwal</code> complains that it cannot determine
  22. valid data for <code class="filename">pg_control</code>, you can force it to proceed anyway
  23. by specifying the <code class="option">-f</code> (force) option. In this case plausible
  24. values will be substituted for the missing data. Most of the fields can be
  25. expected to match, but manual assistance might be needed for the next OID,
  26. next transaction ID and epoch, next multitransaction ID and offset, and
  27. WAL starting location fields. These fields can be set using the options
  28. discussed below. If you are not able to determine correct values for all
  29. these fields, <code class="option">-f</code> can still be used, but
  30. the recovered database must be treated with even more suspicion than
  31. usual: an immediate dump and reload is imperative. <span class="emphasis"><em>Do not</em></span>
  32. execute any data-modifying operations in the database before you dump,
  33. as any such action is likely to make the corruption worse.
  34. </p></div><div class="refsect1" id="id-1.9.5.8.6"><h2>Options</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-f</code><br /></span><span class="term"><code class="option">--force</code></span></dt><dd><p>
  35. Force <code class="command">pg_resetwal</code> to proceed even if it cannot determine
  36. valid data for <code class="filename">pg_control</code>, as explained above.
  37. </p></dd><dt><span class="term"><code class="option">-n</code><br /></span><span class="term"><code class="option">--dry-run</code></span></dt><dd><p>
  38. The <code class="option">-n</code>/<code class="option">--dry-run</code> option instructs
  39. <code class="command">pg_resetwal</code> to print the values reconstructed from
  40. <code class="filename">pg_control</code> and values about to be changed, and then exit
  41. without modifying anything. This is mainly a debugging tool, but can be
  42. useful as a sanity check before allowing <code class="command">pg_resetwal</code>
  43. to proceed for real.
  44. </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>Display version information, then exit.</p></dd><dt><span class="term"><code class="option">-?</code><br /></span><span class="term"><code class="option">--help</code></span></dt><dd><p>Show help, then exit.</p></dd></dl></div><p>
  45. The following options are only needed when
  46. <code class="command">pg_resetwal</code> is unable to determine appropriate values
  47. by reading <code class="filename">pg_control</code>. Safe values can be determined as
  48. described below. For values that take numeric arguments, hexadecimal
  49. values can be specified by using the prefix <code class="literal">0x</code>.
  50. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-c <em class="replaceable"><code>xid</code></em>,<em class="replaceable"><code>xid</code></em></code><br /></span><span class="term"><code class="option">--commit-timestamp-ids=<em class="replaceable"><code>xid</code></em>,<em class="replaceable"><code>xid</code></em></code></span></dt><dd><p>
  51. Manually set the oldest and newest transaction IDs for which the commit
  52. time can be retrieved.
  53. </p><p>
  54. A safe value for the oldest transaction ID for which the commit time can
  55. be retrieved (first part) can be determined by looking
  56. for the numerically smallest file name in the directory
  57. <code class="filename">pg_commit_ts</code> under the data directory. Conversely, a safe
  58. value for the newest transaction ID for which the commit time can be
  59. retrieved (second part) can be determined by looking for the numerically
  60. greatest file name in the same directory. The file names are in
  61. hexadecimal.
  62. </p></dd><dt><span class="term"><code class="option">-e <em class="replaceable"><code>xid_epoch</code></em></code><br /></span><span class="term"><code class="option">--epoch=<em class="replaceable"><code>xid_epoch</code></em></code></span></dt><dd><p>
  63. Manually set the next transaction ID's epoch.
  64. </p><p>
  65. The transaction ID epoch is not actually stored anywhere in the database
  66. except in the field that is set by <code class="command">pg_resetwal</code>,
  67. so any value will work so far as the database itself is concerned.
  68. You might need to adjust this value to ensure that replication
  69. systems such as <span class="application">Slony-I</span> and
  70. <span class="application">Skytools</span> work correctly —
  71. if so, an appropriate value should be obtainable from the state of
  72. the downstream replicated database.
  73. </p></dd><dt><span class="term"><code class="option">-l <em class="replaceable"><code>walfile</code></em></code><br /></span><span class="term"><code class="option">--next-wal-file=<em class="replaceable"><code>walfile</code></em></code></span></dt><dd><p>
  74. Manually set the WAL starting location by specifying the name of the
  75. next WAL segment file.
  76. </p><p>
  77. The name of next WAL segment file should be
  78. larger than any WAL segment file name currently existing in
  79. the directory <code class="filename">pg_wal</code> under the data directory.
  80. These names are also in hexadecimal and have three parts. The first
  81. part is the <span class="quote">“<span class="quote">timeline ID</span>”</span> and should usually be kept the same.
  82. For example, if <code class="filename">00000001000000320000004A</code> is the
  83. largest entry in <code class="filename">pg_wal</code>, use <code class="literal">-l 00000001000000320000004B</code> or higher.
  84. </p><p>
  85. Note that when using nondefault WAL segment sizes, the numbers in the WAL
  86. file names are different from the LSNs that are reported by system
  87. functions and system views. This option takes a WAL file name, not an
  88. LSN.
  89. </p><div class="note"><h3 class="title">Note</h3><p>
  90. <code class="command">pg_resetwal</code> itself looks at the files in
  91. <code class="filename">pg_wal</code> and chooses a default <code class="option">-l</code> setting
  92. beyond the last existing file name. Therefore, manual adjustment of
  93. <code class="option">-l</code> should only be needed if you are aware of WAL segment
  94. files that are not currently present in <code class="filename">pg_wal</code>, such as
  95. entries in an offline archive; or if the contents of
  96. <code class="filename">pg_wal</code> have been lost entirely.
  97. </p></div></dd><dt><span class="term"><code class="option">-m <em class="replaceable"><code>mxid</code></em>,<em class="replaceable"><code>mxid</code></em></code><br /></span><span class="term"><code class="option">--multixact-ids=<em class="replaceable"><code>mxid</code></em>,<em class="replaceable"><code>mxid</code></em></code></span></dt><dd><p>
  98. Manually set the next and oldest multitransaction ID.
  99. </p><p>
  100. A safe value for the next multitransaction ID (first part) can be
  101. determined by looking for the numerically largest file name in the
  102. directory <code class="filename">pg_multixact/offsets</code> under the data directory,
  103. adding one, and then multiplying by 65536 (0x10000). Conversely, a safe
  104. value for the oldest multitransaction ID (second part of
  105. <code class="option">-m</code>) can be determined by looking for the numerically smallest
  106. file name in the same directory and multiplying by 65536. The file
  107. names are in hexadecimal, so the easiest way to do this is to specify
  108. the option value in hexadecimal and append four zeroes.
  109. </p></dd><dt><span class="term"><code class="option">-o <em class="replaceable"><code>oid</code></em></code><br /></span><span class="term"><code class="option">--next-oid=<em class="replaceable"><code>oid</code></em></code></span></dt><dd><p>
  110. Manually set the next OID.
  111. </p><p>
  112. There is no comparably easy way to determine a next OID that's beyond
  113. the largest one in the database, but fortunately it is not critical to
  114. get the next-OID setting right.
  115. </p></dd><dt><span class="term"><code class="option">-O <em class="replaceable"><code>mxoff</code></em></code><br /></span><span class="term"><code class="option">--multixact-offset=<em class="replaceable"><code>mxoff</code></em></code></span></dt><dd><p>
  116. Manually set the next multitransaction offset.
  117. </p><p>
  118. A safe value can be determined by looking for the numerically largest
  119. file name in the directory <code class="filename">pg_multixact/members</code> under the
  120. data directory, adding one, and then multiplying by 52352 (0xCC80).
  121. The file names are in hexadecimal. There is no simple recipe such as
  122. the ones for other options of appending zeroes.
  123. </p></dd><dt><span class="term"><code class="option">--wal-segsize=<em class="replaceable"><code>wal_segment_size</code></em></code></span></dt><dd><p>
  124. Set the new WAL segment size, in megabytes. The value must be set to a
  125. power of 2 between 1 and 1024 (megabytes). See the same option of <a class="xref" href="app-initdb.html" title="initdb"><span class="refentrytitle">initdb</span></a> for more information.
  126. </p><div class="note"><h3 class="title">Note</h3><p>
  127. While <code class="command">pg_resetwal</code> will set the WAL starting address
  128. beyond the latest existing WAL segment file, some segment size changes
  129. can cause previous WAL file names to be reused. It is recommended to
  130. use <code class="option">-l</code> together with this option to manually set the
  131. WAL starting address if WAL file name overlap will cause problems with
  132. your archiving strategy.
  133. </p></div></dd><dt><span class="term"><code class="option">-x <em class="replaceable"><code>xid</code></em></code><br /></span><span class="term"><code class="option">--next-transaction-id=<em class="replaceable"><code>xid</code></em></code></span></dt><dd><p>
  134. Manually set the next transaction ID.
  135. </p><p>
  136. A safe value can be determined by looking for the numerically largest
  137. file name in the directory <code class="filename">pg_xact</code> under the data directory,
  138. adding one,
  139. and then multiplying by 1048576 (0x100000). Note that the file names are in
  140. hexadecimal. It is usually easiest to specify the option value in
  141. hexadecimal too. For example, if <code class="filename">0011</code> is the largest entry
  142. in <code class="filename">pg_xact</code>, <code class="literal">-x 0x1200000</code> will work (five
  143. trailing zeroes provide the proper multiplier).
  144. </p></dd></dl></div></div><div class="refsect1" id="id-1.9.5.8.7"><h2>Environment</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="envar">PG_COLOR</code></span></dt><dd><p>
  145. Specifies whether to use color in diagnostic messages. Possible values
  146. are <code class="literal">always</code>, <code class="literal">auto</code> and
  147. <code class="literal">never</code>.
  148. </p></dd></dl></div></div><div class="refsect1" id="id-1.9.5.8.8"><h2>Notes</h2><p>
  149. This command must not be used when the server is
  150. running. <code class="command">pg_resetwal</code> will refuse to start up if
  151. it finds a server lock file in the data directory. If the
  152. server crashed then a lock file might have been left
  153. behind; in that case you can remove the lock file to allow
  154. <code class="command">pg_resetwal</code> to run. But before you do
  155. so, make doubly certain that there is no server process still alive.
  156. </p><p>
  157. <code class="command">pg_resetwal</code> works only with servers of the same
  158. major version.
  159. </p></div><div class="refsect1" id="id-1.9.5.8.9"><h2>See Also</h2><span class="simplelist"><a class="xref" href="app-pgcontroldata.html" title="pg_controldata"><span class="refentrytitle"><span class="application">pg_controldata</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="app-pg-ctl.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-pgrewind.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="application">pg_ctl</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_rewind</span></td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1