Home Explore Blog CI



postgresql

2nd chunk of `doc/src/sgml/generic-wal.sgml`
079e7cf9a0f5ac506dcc5e6f4e6c5c4f47c15d3549f0a7b30000000100000f87
 <listitem>
     <para>
      Apply modifications to the page images obtained in the previous step.
     </para>
    </listitem>

    <listitem>
     <para>
      <function>GenericXLogFinish(state)</function> &mdash; apply the changes to
      the buffers and emit the generic WAL record.
     </para>
    </listitem>
   </orderedlist>
  </para>

  <para>
   WAL record construction can be canceled between any of the above steps by
   calling <function>GenericXLogAbort(state)</function>.  This will discard all
   changes to the page image copies.
  </para>

  <para>
   Please note the following points when using the generic WAL record
   facility:

   <itemizedlist>
    <listitem>
     <para>
      No direct modifications of buffers are allowed!  All modifications must
      be done in copies acquired from <function>GenericXLogRegisterBuffer()</function>.
      In other words, code that makes generic WAL records should never call
      <function>BufferGetPage()</function> for itself.  However, it remains the
      caller's responsibility to pin/unpin and lock/unlock the buffers at
      appropriate times.  Exclusive lock must be held on each target buffer
      from before <function>GenericXLogRegisterBuffer()</function> until after
      <function>GenericXLogFinish()</function>.
     </para>
    </listitem>

    <listitem>
     <para>
      Registrations of buffers (step 2) and modifications of page images
      (step 3) can be mixed freely, i.e., both steps may be repeated in any
      sequence.  Keep in mind that buffers should be registered in the same
      order in which locks are to be obtained on them during replay.
     </para>
    </listitem>

    <listitem>
     <para>
      The maximum number of buffers that can be registered for a generic WAL
      record is <literal>MAX_GENERIC_XLOG_PAGES</literal>.  An error will be thrown
      if this limit is exceeded.
     </para>
    </listitem>

    <listitem>
     <para>
      Generic WAL assumes that the pages to be modified have standard
      layout, and in particular that there is no useful data between
      <structfield>pd_lower</structfield> and <structfield>pd_upper</structfield>.
     </para>
    </listitem>

    <listitem>
     <para>
      Since you are modifying copies of buffer
      pages, <function>GenericXLogStart()</function> does not start a critical
      section.  Thus, you can safely do memory allocation, error throwing,
      etc. between <function>GenericXLogStart()</function> and
      <function>GenericXLogFinish()</function>.  The only actual critical section is
      present inside <function>GenericXLogFinish()</function>.  There is no need to
      worry about calling  <function>GenericXLogAbort()</function> during an error
      exit, either.
     </para>
    </listitem>

    <listitem>
     <para>
      <function>GenericXLogFinish()</function> takes care of marking buffers dirty
      and setting their LSNs.  You do not need to do this explicitly.
     </para>
    </listitem>

    <listitem>
     <para>
      For unlogged relations, everything works the same except that no
      actual WAL record is emitted.  Thus, you typically do not need to do
      any explicit checks for unlogged relations.
     </para>
    </listitem>

    <listitem>
     <para>
      The generic WAL redo function will acquire exclusive locks to buffers
      in the same order as they were registered.  After redoing all changes,
      the locks will be released in the same order.
     </para>
    </listitem>

    <listitem>
     <para>
      If <literal>GENERIC_XLOG_FULL_IMAGE</literal> is not specified for a
      registered buffer, the generic WAL record contains a delta between
      the old and the new page images.  This delta is based on byte-by-byte
      comparison.  This is not very compact for the case of moving data
      within a page, and might be improved in the future.
     </para>
    </listitem>
   </itemizedlist>
  </para>
</sect1>

Title: Using the Generic WAL Record Facility
Summary
This section provides important considerations and guidelines for using the generic WAL record facility, including rules for modifying buffers, registering and modifying page images, and handling errors, as well as details on the behavior of the generic WAL redo function and the format of the WAL records.