Home Explore Blog CI



postgresql

2nd chunk of `doc/src/sgml/ref/pg_receivewal.sgml`
c171c7453260048a37187eec2c7a1fca0a18cbe28c30ea040000000100000fa1
 configured with
   <xref linkend="guc-max-wal-senders"/> set high enough to leave at least
   one session available for the stream.
  </para>

  <para>
   The starting point of the write-ahead log streaming is calculated when
   <application>pg_receivewal</application> starts:
   <orderedlist>
    <listitem>
     <para>
      First, scan the directory where the WAL segment files are written and
      find the newest completed segment file, using as the starting point the
      beginning of the next WAL segment file.
     </para>
    </listitem>

    <listitem>
     <para>
      If a starting point cannot be calculated with the previous method,
      and if a replication slot is used, an extra
      <command>READ_REPLICATION_SLOT</command> command is issued to retrieve
      the slot's <literal>restart_lsn</literal> to use as the starting point.
      This option is only available when streaming write-ahead logs from
      <productname>PostgreSQL</productname> 15 and up.
     </para>
    </listitem>

    <listitem>
     <para>
      If a starting point cannot be calculated with the previous method,
      the latest WAL flush location is used as reported by the server from
      an <literal>IDENTIFY_SYSTEM</literal> command.
     </para>
    </listitem>
   </orderedlist>
  </para>

  <para>
   If the connection is lost, or if it cannot be initially established,
   with a non-fatal error, <application>pg_receivewal</application> will
   retry the connection indefinitely, and reestablish streaming as soon
   as possible. To avoid this behavior, use the <literal>-n</literal>
   parameter.
  </para>

  <para>
   In the absence of fatal errors, <application>pg_receivewal</application>
   will run until terminated by the <systemitem>SIGINT</systemitem>
   (<keycombo action="simul"><keycap>Control</keycap><keycap>C</keycap></keycombo>)
   or <systemitem>SIGTERM</systemitem> signal.
  </para>
 </refsect1>

 <refsect1>
  <title>Options</title>

    <variablelist>
     <varlistentry>
      <term><option>-D <replaceable class="parameter">directory</replaceable></option></term>
      <term><option>--directory=<replaceable class="parameter">directory</replaceable></option></term>
      <listitem>
       <para>
        Directory to write the output to.
       </para>
       <para>
        This parameter is required.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>-E <replaceable>lsn</replaceable></option></term>
      <term><option>--endpos=<replaceable>lsn</replaceable></option></term>
      <listitem>
       <para>
        Automatically stop replication and exit with normal exit status 0 when
        receiving reaches the specified LSN.
       </para>

       <para>
        If there is a record with LSN exactly equal to <replaceable>lsn</replaceable>,
        the record will be processed.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>--if-not-exists</option></term>
      <listitem>
       <para>
        Do not error out when <option>--create-slot</option> is specified
        and a slot with the specified name already exists.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>-n</option></term>
      <term><option>--no-loop</option></term>
      <listitem>
       <para>
        Don't loop on connection errors. Instead, exit right away with
        an error.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>--no-sync</option></term>
      <listitem>
       <para>
        This option causes <command>pg_receivewal</command> to not force WAL
        data to be flushed to disk.  This is faster, but means that a
        subsequent operating system crash can leave the WAL segments corrupt.
        Generally, this option is useful for testing but should not be used
        when doing WAL archiving on a production deployment.
       </para>

       <para>
        This

Title: pg_receivewal: Connection Handling, Termination, and Options
Summary
pg_receivewal calculates the WAL streaming start point by scanning for the newest completed segment file, using a replication slot's restart_lsn (PostgreSQL 15+), or using the server's latest WAL flush location. It retries connections indefinitely unless -n is used. It runs until terminated by SIGINT or SIGTERM. Key options include -D/--directory for the output directory (required), -E/--endpos to stop at a specific LSN, --if-not-exists to avoid errors when creating an existing slot, -n/--no-loop to exit on connection errors, and --no-sync to skip forcing WAL data to disk (faster but risky).