Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
app-pgresetwal.html169 linesDownload Raw Back to html
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 Vsnapshot" /><link rel="prev" href="app-pg-ctl.html" title="pg_ctl" /><link rel="next" href="app-pgrewind.html" title="pg_rewind" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center"><span 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 16.3 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 /></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">-f</code>  |   <code class="option">--force</code> ] [ <code class="option">-n</code>  |   <code class="option">--dry-run</code> ] [<em class="replaceable"><code>option</code></em>...]  [ <code class="option">-D</code>  |   <code class="option">--pgdata</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) and4   optionally resets some other control information stored in the5   <code class="filename">pg_control</code> file.  This function is sometimes needed6   if these files have become corrupted.  It should be used only as a7   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 to11   partially-committed transactions.  You should immediately dump your data,12   run <code class="command">initdb</code>, and restore.  After restore, check for13   inconsistencies and repair as needed.14  </p><p>15   This utility can only be run by the user who installed the server, because16   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 variable19   <code class="envar">PGDATA</code>.20  </p><p>21   If <code class="command">pg_resetwal</code> complains that it cannot determine22   valid data for <code class="filename">pg_control</code>, you can force it to proceed anyway23   by specifying the <code class="option">-f</code> (force) option.  In this case plausible24   values will be substituted for the missing data.  Most of the fields can be25   expected to match, but manual assistance might be needed for the next OID,26   next transaction ID and epoch, next multitransaction ID and offset, and27   WAL starting location fields. These fields can be set using the options28   discussed below. If you are not able to determine correct values for all29   these fields, <code class="option">-f</code> can still be used, but30   the recovered database must be treated with even more suspicion than31   usual: an immediate dump and restore 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 determine36      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 instructs39      <code class="command">pg_resetwal</code> to print the values reconstructed from40      <code class="filename">pg_control</code> and values about to be changed, and then exit41      without modifying anything. This is mainly a debugging tool, but can be42      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 when46   <code class="command">pg_resetwal</code> is unable to determine appropriate values47   by reading <code class="filename">pg_control</code>.  Safe values can be determined as48   described below.  For values that take numeric arguments, hexadecimal49   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 commit52      time can be retrieved.53     </p><p>54      A safe value for the oldest transaction ID for which the commit time can55      be retrieved (first part) can be determined by looking56      for the numerically smallest file name in the directory57      <code class="filename">pg_commit_ts</code> under the data directory.  Conversely, a safe58      value for the newest transaction ID for which the commit time can be59      retrieved (second part) can be determined by looking for the numerically60      greatest file name in the same directory.  The file names are in61      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 database66      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 replication69      systems such as <span class="application">Slony-I</span> and70      <span class="application">Skytools</span> work correctly —71      if so, an appropriate value should be obtainable from the state of72      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 the75      next WAL segment file.76     </p><p>77      The name of next WAL segment file should be78      larger than any WAL segment file name currently existing in79      the directory <code class="filename">pg_wal</code> under the data directory.80      These names are also in hexadecimal and have three parts.  The first81      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 the83      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 WAL86      file names are different from the LSNs that are reported by system87      functions and system views.  This option takes a WAL file name, not an88      LSN.89     </p><div class="note"><h3 class="title">Note</h3><p>90       <code class="command">pg_resetwal</code> itself looks at the files in91       <code class="filename">pg_wal</code> and chooses a default <code class="option">-l</code> setting92       beyond the last existing file name.  Therefore, manual adjustment of93       <code class="option">-l</code> should only be needed if you are aware of WAL segment94       files that are not currently present in <code class="filename">pg_wal</code>, such as95       entries in an offline archive; or if the contents of96       <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 be101      determined by looking for the numerically largest file name in the102      directory <code class="filename">pg_multixact/offsets</code> under the data directory,103      adding one, and then multiplying by 65536 (0x10000).  Conversely, a safe104      value for the oldest multitransaction ID (second part of105      <code class="option">-m</code>) can be determined by looking for the numerically smallest106      file name in the same directory and multiplying by 65536.  The file107      names are in hexadecimal, so the easiest way to do this is to specify108      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 beyond113      the largest one in the database, but fortunately it is not critical to114      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 largest119      file name in the directory <code class="filename">pg_multixact/members</code> under the120      data directory, adding one, and then multiplying by 52352 (0xCC80).121      The file names are in hexadecimal.  There is no simple recipe such as122      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 a125      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"><span class="application">initdb</span></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 address128       beyond the latest existing WAL segment file, some segment size changes129       can cause previous WAL file names to be reused.  It is recommended to130       use <code class="option">-l</code> together with this option to manually set the131       WAL starting address if WAL file name overlap will cause problems with132       your archiving strategy.133      </p></div></dd><dt><span class="term"><code class="option">-u <em class="replaceable"><code>xid</code></em></code><br /></span><span class="term"><code class="option">--oldest-transaction-id=<em class="replaceable"><code>xid</code></em></code></span></dt><dd><p>134      Manually set the oldest unfrozen transaction ID.135     </p><p>136      A safe value can be determined by looking for the numerically smallest137      file name in the directory <code class="filename">pg_xact</code> under the data directory138      and then multiplying by 1048576 (0x100000).  Note that the file names are in139      hexadecimal.  It is usually easiest to specify the option value in140      hexadecimal too. For example, if <code class="filename">0007</code> is the smallest entry141      in <code class="filename">pg_xact</code>, <code class="literal">-u 0x700000</code> will work (five142      trailing zeroes provide the proper multiplier).143     </p></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>144      Manually set the next transaction ID.145     </p><p>146      A safe value can be determined by looking for the numerically largest147      file name in the directory <code class="filename">pg_xact</code> under the data directory,148      adding one,149      and then multiplying by 1048576 (0x100000).  Note that the file names are in150      hexadecimal.  It is usually easiest to specify the option value in151      hexadecimal too. For example, if <code class="filename">0011</code> is the largest entry152      in <code class="filename">pg_xact</code>, <code class="literal">-x 0x1200000</code> will work (five153      trailing zeroes provide the proper multiplier).154     </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>155      Specifies whether to use color in diagnostic messages. Possible values156      are <code class="literal">always</code>, <code class="literal">auto</code> and157      <code class="literal">never</code>.158     </p></dd></dl></div></div><div class="refsect1" id="id-1.9.5.8.8"><h2>Notes</h2><p>159   This command must not be used when the server is160   running.  <code class="command">pg_resetwal</code> will refuse to start up if161   it finds a server lock file in the data directory.  If the162   server crashed then a lock file might have been left163   behind; in that case you can remove the lock file to allow164   <code class="command">pg_resetwal</code> to run.  But before you do165   so, make doubly certain that there is no server process still alive.166  </p><p>167   <code class="command">pg_resetwal</code> works only with servers of the same168   major version.169  </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" title="pg_ctl">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="reference-server.html" title="PostgreSQL Server Applications">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="app-pgrewind.html" title="pg_rewind">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" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> <span class="application">pg_rewind</span></td></tr></table></div></body></html>
codekingpro/portable-devtools · Team Ai