Home Explore Blog CI



postgresql

2nd chunk of `doc/src/sgml/ref/pg_rewind.sgml`
98621a60a8e84ac4ae735b74aac8350ebaf85ba2da2851690000000100000fa1
 the <filename>pg_wal</filename> directory, or run
   <application>pg_rewind</application> with the <literal>-c</literal> option to
   automatically retrieve them from the WAL archive. The use of
   <application>pg_rewind</application> is not limited to failover, e.g.,  a standby
   server can be promoted, run some write transactions, and then rewound
   to become a standby again.
  </para>

  <para>
   After running <application>pg_rewind</application>, WAL replay needs to
   complete for the data directory to be in a consistent state. When the
   target server is started again it will enter archive recovery and replay
   all WAL generated in the source server from the last checkpoint before
   the point of divergence. If some of the WAL was no longer available in the
   source server when <application>pg_rewind</application> was run, and
   therefore could not be copied by the <application>pg_rewind</application>
   session, it must be made available when the target server is started.
   This can be done by creating a <filename>recovery.signal</filename> file
   in the target data directory and by configuring a suitable
   <xref linkend="guc-restore-command"/> in
   <filename>postgresql.conf</filename>.
  </para>

  <para>
   <application>pg_rewind</application> requires that the target server either has
   the <xref linkend="guc-wal-log-hints"/> option enabled
   in <filename>postgresql.conf</filename> or data checksums enabled when
   the cluster was initialized with <application>initdb</application>.  Neither of these
   are currently on by default.  <xref linkend="guc-full-page-writes"/>
   must also be set to <literal>on</literal>, but is enabled by default.
  </para>

  <warning>
   <title>Warning: Failures While Rewinding</title>
   <para>
    If <application>pg_rewind</application> fails while processing, then
    the data folder of the target is likely not in a state that can be
    recovered.  In such a case, taking a new fresh backup is recommended.
   </para>

   <para>
    As <application>pg_rewind</application> copies configuration files
    entirely from the source, it may be required to correct the configuration
    used for recovery before restarting the target server, especially if
    the target is reintroduced as a standby of the source. If you restart
    the server after the rewind operation has finished but without configuring
    recovery, the target may again diverge from the primary.
   </para>

   <para>
    <application>pg_rewind</application> will fail immediately if it finds
    files it cannot write directly to.  This can happen for example when
    the source and the target server use the same file mapping for read-only
    SSL keys and certificates.  If such files are present on the target server
    it is recommended to remove them before running
    <application>pg_rewind</application>.  After doing the rewind, some of
    those files may have been copied from the source, in which case it may
    be necessary to remove the data copied and restore back the set of links
    used before the rewind.
   </para>
  </warning>
 </refsect1>

 <refsect1>
  <title>Options</title>

   <para>
    <application>pg_rewind</application> accepts the following command-line
    arguments:

    <variablelist>
     <varlistentry>
      <term><option>-D <replaceable class="parameter">directory</replaceable></option></term>
      <term><option>--target-pgdata=<replaceable class="parameter">directory</replaceable></option></term>
      <listitem>
       <para>
        This option specifies the target data directory that is synchronized
        with the source. The target server must be shut down cleanly before
        running <application>pg_rewind</application>
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>--source-pgdata=<replaceable class="parameter">directory</replaceable></option></term>
      <listitem>
       <para>
        Specifies the file system path to the

Title: pg_rewind: WAL Availability, Requirements, and Options
Summary
pg_rewind can retrieve missing WAL files automatically using the -c option. After running pg_rewind, WAL replay must complete, potentially requiring a recovery.signal file and a restore_command in postgresql.conf. pg_rewind requires wal_log_hints or data checksums to be enabled and full_page_writes set to on. Failures during rewinding may leave the target data folder in an unrecoverable state, recommending a fresh backup. Configuration files are copied from the source, so recovery configuration may need correction. pg_rewind fails if it cannot write to files, which can happen with read-only SSL keys and certificates.