Home Explore Blog CI



postgresql

1st chunk of `doc/src/sgml/ref/create_publication.sgml`
fc56c75bd11bc8f5f3f2641215b20ab5798ffdf7a97038fa0000000100000fa8
<!--
doc/src/sgml/ref/create_publication.sgml
PostgreSQL documentation
-->

<refentry id="sql-createpublication">
 <indexterm zone="sql-createpublication">
  <primary>CREATE PUBLICATION</primary>
 </indexterm>

 <refmeta>
  <refentrytitle>CREATE PUBLICATION</refentrytitle>
  <manvolnum>7</manvolnum>
  <refmiscinfo>SQL - Language Statements</refmiscinfo>
 </refmeta>

 <refnamediv>
  <refname>CREATE PUBLICATION</refname>
  <refpurpose>define a new publication</refpurpose>
 </refnamediv>

 <refsynopsisdiv>
<synopsis>
CREATE PUBLICATION <replaceable class="parameter">name</replaceable>
    [ FOR ALL TABLES
      | FOR <replaceable class="parameter">publication_object</replaceable> [, ... ] ]
    [ WITH ( <replaceable class="parameter">publication_parameter</replaceable> [= <replaceable class="parameter">value</replaceable>] [, ... ] ) ]

<phrase>where <replaceable class="parameter">publication_object</replaceable> is one of:</phrase>

    TABLE [ ONLY ] <replaceable class="parameter">table_name</replaceable> [ * ] [ ( <replaceable class="parameter">column_name</replaceable> [, ... ] ) ] [ WHERE ( <replaceable class="parameter">expression</replaceable> ) ] [, ... ]
    TABLES IN SCHEMA { <replaceable class="parameter">schema_name</replaceable> | CURRENT_SCHEMA } [, ... ]
</synopsis>
 </refsynopsisdiv>

 <refsect1>
  <title>Description</title>

  <para>
   <command>CREATE PUBLICATION</command> adds a new publication
   into the current database.  The publication name must be distinct from
   the name of any existing publication in the current database.
  </para>

  <para>
   A publication is essentially a group of tables whose data changes are
   intended to be replicated through logical replication.  See
   <xref linkend="logical-replication-publication"/> for details about how
   publications fit into the logical replication setup.
   </para>
 </refsect1>

 <refsect1>
  <title>Parameters</title>

  <variablelist>
   <varlistentry id="sql-createpublication-params-name">
    <term><replaceable class="parameter">name</replaceable></term>
    <listitem>
     <para>
      The name of the new publication.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry id="sql-createpublication-params-for-table">
    <term><literal>FOR TABLE</literal></term>
    <listitem>
     <para>
      Specifies a list of tables to add to the publication.  If
      <literal>ONLY</literal> is specified before the table name, only
      that table is added to the publication.  If <literal>ONLY</literal> is not
      specified, the table and all its descendant tables (if any) are added.
      Optionally, <literal>*</literal> can be specified after the table name to
      explicitly indicate that descendant tables are included.
      This does not apply to a partitioned table, however.  The partitions of
      a partitioned table are always implicitly considered part of the
      publication, so they are never explicitly added to the publication.
     </para>

     <para>
      If the optional <literal>WHERE</literal> clause is specified, it defines a
      <firstterm>row filter</firstterm> expression. Rows for
      which the <replaceable class="parameter">expression</replaceable>
      evaluates to false or null will not be published. Note that parentheses
      are required around the expression. It has no effect on
      <literal>TRUNCATE</literal> commands.
     </para>

     <para>
      When a column list is specified, only the named columns are replicated.
      The column list can contain stored generated columns as well. If the
      column list is omitted, the publication will replicate all non-generated
      columns (including any added in the future) by default. Stored generated
      columns can also be replicated if <literal>publish_generated_columns</literal>
      is set to <literal>stored</literal>. Specifying a column list has no
      effect on <literal>TRUNCATE</literal> commands. See
      <xref linkend="logical-replication-col-lists"/>

Title: CREATE PUBLICATION
Summary
This section of the PostgreSQL documentation describes the CREATE PUBLICATION command, which adds a new publication to the current database. A publication is a group of tables whose data changes are intended for logical replication. The command syntax and parameters, including FOR TABLE (specifying tables to add, with options for ONLY, *, WHERE clause for row filtering, and column lists for replication) are explained.