Home Explore Blog CI



postgresql

7th chunk of `doc/src/sgml/ref/create_publication.sgml`
a0e8c0715ed69f2a1320cb1bb20dc66bce0aa493990a3e8e0000000100000bd1
 </para>

  <para>
   <command>ATTACH</command>ing a table into a partition tree whose root is
   published using a publication with <literal>publish_via_partition_root</literal>
   set to <literal>true</literal> does not result in the table's existing contents
   being replicated.
  </para>

  <para>
   <command>COPY ... FROM</command> commands are published
   as <command>INSERT</command> operations.
  </para>

  <para>
   <acronym>DDL</acronym> operations are not published.
  </para>

  <para>
   The <literal>WHERE</literal> clause expression is executed with the role used
   for the replication connection.
  </para>
 </refsect1>

 <refsect1>
  <title>Examples</title>

  <para>
   Create a publication that publishes all changes in two tables:
<programlisting>
CREATE PUBLICATION mypublication FOR TABLE users, departments;
</programlisting>
  </para>

  <para>
   Create a publication that publishes all changes from active departments:
<programlisting>
CREATE PUBLICATION active_departments FOR TABLE departments WHERE (active IS TRUE);
</programlisting>
  </para>

  <para>
   Create a publication that publishes all changes in all tables:
<programlisting>
CREATE PUBLICATION alltables FOR ALL TABLES;
</programlisting>
  </para>

  <para>
   Create a publication that only publishes <command>INSERT</command>
   operations in one table:
<programlisting>
CREATE PUBLICATION insert_only FOR TABLE mydata
    WITH (publish = 'insert');
</programlisting>
  </para>

  <para>
   Create a publication that publishes all changes for tables
   <structname>users</structname>, <structname>departments</structname> and
   all changes for all the tables present in the schema
   <structname>production</structname>:
<programlisting>
CREATE PUBLICATION production_publication FOR TABLE users, departments, TABLES IN SCHEMA production;
</programlisting>
  </para>

  <para>
   Create a publication that publishes all changes for all the tables present in
   the schemas <structname>marketing</structname> and
   <structname>sales</structname>:
<programlisting>
CREATE PUBLICATION sales_publication FOR TABLES IN SCHEMA marketing, sales;
</programlisting></para>

  <para>
   Create a publication that publishes all changes for table <structname>users</structname>,
   but replicates only columns <structname>user_id</structname> and
   <structname>firstname</structname>:
<programlisting>
CREATE PUBLICATION users_filtered FOR TABLE users (user_id, firstname);
</programlisting></para>
 </refsect1>

 <refsect1>
  <title>Compatibility</title>

  <para>
   <command>CREATE PUBLICATION</command> is a <productname>PostgreSQL</productname>
   extension.
  </para>
 </refsect1>

 <refsect1>
  <title>See Also</title>

  <simplelist type="inline">
   <member><xref linkend="sql-alterpublication"/></member>
   <member><xref linkend="sql-droppublication"/></member>
   <member><xref linkend="sql-createsubscription"/></member>
   <member><xref linkend="sql-altersubscription"/></member>
  </simplelist>
 </refsect1>
</refentry>

Title: CREATE PUBLICATION Examples and Compatibility
Summary
This section provides examples of how to create publications with various options, including specifying tables, schemas, WHERE clauses, publish modes (insert only), and column lists. It then notes that CREATE PUBLICATION is a PostgreSQL extension and lists related commands such as ALTER PUBLICATION, DROP PUBLICATION, CREATE SUBSCRIPTION, and ALTER SUBSCRIPTION.