1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Logical replication support for TRUNCATE

Update the built-in logical replication system to make use of the
previously added logical decoding for TRUNCATE support.  Add the
required truncate callback to pgoutput and a new logical replication
protocol message.

Publications get a new attribute to determine whether to replicate
truncate actions.  When updating a publication via pg_dump from an older
version, this is not set, thus preserving the previous behavior.

Author: Simon Riggs <simon@2ndquadrant.com>
Author: Marco Nenciarini <marco.nenciarini@2ndquadrant.it>
Author: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Reviewed-by: Petr Jelinek <petr.jelinek@2ndquadrant.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
This commit is contained in:
Peter Eisentraut
2018-04-07 11:24:53 -04:00
parent 5dfd1e5a66
commit 039eb6e92f
19 changed files with 572 additions and 111 deletions

View File

@ -5518,6 +5518,14 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l
<entry>If true, <command>DELETE</command> operations are replicated for
tables in the publication.</entry>
</row>
<row>
<entry><structfield>pubtruncate</structfield></entry>
<entry><type>bool</type></entry>
<entry></entry>
<entry>If true, <command>TRUNCATE</command> operations are replicated for
tables in the publication.</entry>
</row>
</tbody>
</tgroup>
</table>

View File

@ -108,8 +108,8 @@
<para>
Publications can choose to limit the changes they produce to
any combination of <command>INSERT</command>, <command>UPDATE</command>, and
<command>DELETE</command>, similar to how triggers are fired by
any combination of <command>INSERT</command>, <command>UPDATE</command>,
<command>DELETE</command>, and <command>TRUNCATE</command>, similar to how triggers are fired by
particular event types. By default, all operation types are replicated.
</para>
@ -364,15 +364,6 @@
</para>
</listitem>
<listitem>
<para>
<command>TRUNCATE</command> commands are not replicated. This can, of
course, be worked around by using <command>DELETE</command> instead. To
avoid accidental <command>TRUNCATE</command> invocations, you can revoke
the <literal>TRUNCATE</literal> privilege from tables.
</para>
</listitem>
<listitem>
<para>
Large objects (see <xref linkend="largeobjects"/>) are not replicated.

View File

@ -6774,6 +6774,62 @@ Delete
</listitem>
</varlistentry>
<varlistentry>
<term>
Truncate
</term>
<listitem>
<para>
<variablelist>
<varlistentry>
<term>
Byte1('T')
</term>
<listitem>
<para>
Identifies the message as a truncate message.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
Int32
</term>
<listitem>
<para>
Number of relations
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
Int8
</term>
<listitem>
<para>
Option bits for <command>TRUNCATE</command>:
1 for <literal>CASCADE</literal>, 2 for <literal>RESTART IDENTITY</literal>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
Int32
</term>
<listitem>
<para>
ID of the relation corresponding to the ID in the relation
message. This field is repeated for each relation.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</listitem>
</varlistentry>
</variablelist>
<para>

View File

@ -106,10 +106,11 @@ CREATE PUBLICATION <replaceable class="parameter">name</replaceable>
This parameter determines which DML operations will be published by
the new publication to the subscribers. The value is
comma-separated list of operations. The allowed operations are
<literal>insert</literal>, <literal>update</literal>, and
<literal>delete</literal>. The default is to publish all actions,
<literal>insert</literal>, <literal>update</literal>,
<literal>delete</literal>, and <literal>truncate</literal>.
The default is to publish all actions,
and so the default value for this option is
<literal>'insert, update, delete'</literal>.
<literal>'insert, update, delete, truncate'</literal>.
</para>
</listitem>
</varlistentry>
@ -168,8 +169,7 @@ CREATE PUBLICATION <replaceable class="parameter">name</replaceable>
</para>
<para>
<command>TRUNCATE</command> and <acronym>DDL</acronym> operations
are not published.
<acronym>DDL</acronym> operations are not published.
</para>
</refsect1>