Home Explore Blog CI



postgresql

20th chunk of `doc/src/sgml/logical-replication.sgml`
48432dbc33d1a365ffd528d2a1848520604609961742064c0000000100000fa1
 tab_gen_to_gen;
 a | b
---+----
 1 | 100
 2 | 200
 3 | 300
(3 rows)
</programlisting>
  </para>

  <para>
   In fact, prior to version 18.0, logical replication does not publish
   <literal>GENERATED</literal> columns at all.
  </para>

  <para>
   But, replicating a generated column to a regular column can sometimes be
   desirable.
   <tip>
    <para>
     This feature may be useful when replicating data to a
     non-PostgreSQL database via output plugin, especially if the target database
     does not support generated columns.
    </para>
  </tip>
  </para>

  <para>
   Generated columns are not published by default, but users can opt to
   publish stored generated columns just like regular ones.
  </para>

  <para>
   There are two ways to do this:
   <itemizedlist>
     <listitem>
      <para>
       Set the <command>PUBLICATION</command> parameter
       <link linkend="sql-createpublication-params-with-publish-generated-columns">
       <literal>publish_generated_columns</literal></link> to <literal>stored</literal>.
       This instructs PostgreSQL logical replication to publish current and
       future stored generated columns of the publication's tables.
      </para>
     </listitem>

     <listitem>
      <para>
       Specify a table <link linkend="logical-replication-col-lists">column list</link>
       to explicitly nominate which stored generated columns will be published.
      </para>

      <note>
       <para>
        When determining which table columns will be published, a column list
        takes precedence, overriding the effect of the
        <literal>publish_generated_columns</literal> parameter.
       </para>
      </note>
     </listitem>
   </itemizedlist>
  </para>

  <para>
   The following table summarizes behavior when there are generated columns
   involved in the logical replication. Results are shown for when
   publishing generated columns is not enabled, and for when it is
   enabled.
  </para>

  <table id="logical-replication-gencols-table-summary">
   <title>Replication Result Summary</title>
   <tgroup cols="4">

    <thead>
     <row>
      <entry>Publish generated columns?</entry>
      <entry>Publisher table column</entry>
      <entry>Subscriber table column</entry>
      <entry>Result</entry>
     </row>
    </thead>

    <tbody>
     <row>
      <entry>No</entry>
      <entry>GENERATED</entry>
      <entry>GENERATED</entry>
      <entry>Publisher table column is not replicated. Use the subscriber table generated column value.</entry>
     </row>

     <row>
      <entry>No</entry>
      <entry>GENERATED</entry>
      <entry>regular</entry>
      <entry>Publisher table column is not replicated. Use the subscriber table regular column default value.</entry>
     </row>

     <row>
      <entry>No</entry>
      <entry>GENERATED</entry>
      <entry>--missing--</entry>
      <entry>Publisher table column is not replicated. Nothing happens.</entry>
     </row>

     <row>
      <entry>Yes</entry>
      <entry>GENERATED</entry>
      <entry>GENERATED</entry>
      <entry>ERROR. Not supported.</entry>
     </row>

     <row>
      <entry>Yes</entry>
      <entry>GENERATED</entry>
      <entry>regular</entry>
      <entry>Publisher table column value is replicated to the subscriber table column.</entry>
     </row>

     <row>
      <entry>Yes</entry>
      <entry>GENERATED</entry>
      <entry>--missing--</entry>
      <entry>ERROR. The column is reported as missing from the subscriber table.</entry>
     </row>
    </tbody>
   </tgroup>
  </table>

  <warning>
   <para>
    There's currently no support for subscriptions comprising several
    publications where the same table has been published with different column
    lists. See <xref linkend="logical-replication-col-lists"/>.
   </para>

   <para>
    This same situation can occur if one publication is publishing generated
    columns, while another publication in the same subscription is not
    publishing generated columns for

Title: Generated Column Replication Options and Behavior
Summary
This section details how to replicate generated columns in PostgreSQL logical replication, including the use of the 'publish_generated_columns' parameter and column lists. It outlines the behavior and potential errors when replicating generated columns to different column types (generated, regular, or missing) on the subscriber side, both when publishing generated columns is enabled and disabled. A table summarizes these scenarios for clarity. The section concludes with a warning about limitations when using multiple publications with different column lists for the same table within a single subscription.