mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Add ALTER SUBSCRIPTION ... SKIP.
This feature allows skipping the transaction on subscriber nodes. If incoming change violates any constraint, logical replication stops until it's resolved. Currently, users need to either manually resolve the conflict by updating a subscriber-side database or by using function pg_replication_origin_advance() to skip the conflicting transaction. This commit introduces a simpler way to skip the conflicting transactions. The user can specify LSN by ALTER SUBSCRIPTION ... SKIP (lsn = XXX), which allows the apply worker to skip the transaction finished at specified LSN. The apply worker skips all data modification changes within the transaction. Author: Masahiko Sawada Reviewed-by: Takamichi Osumi, Hou Zhijie, Peter Eisentraut, Amit Kapila, Shi Yu, Vignesh C, Greg Nancarrow, Haiying Tang, Euler Taveira Discussion: https://postgr.es/m/CAD21AoDeScrsHhLyEPYqN3sydg6PxAPVBboK=30xJfUVihNZDA@mail.gmail.com
This commit is contained in:
@ -7797,6 +7797,16 @@ SCRAM-SHA-256$<replaceable><iteration count></replaceable>:<replaceable>&l
|
||||
</para></entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
<entry role="catalog_table_entry"><para role="column_definition">
|
||||
<structfield>subskiplsn</structfield> <type>pg_lsn</type>
|
||||
</para>
|
||||
<para>
|
||||
Finish LSN of the transaction whose changes are to be skipped, if a valid
|
||||
LSN; otherwise <literal>0/0</literal>.
|
||||
</para></entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
<entry role="catalog_table_entry"><para role="column_definition">
|
||||
<structfield>subconninfo</structfield> <type>text</type>
|
||||
|
@ -362,19 +362,24 @@ CONTEXT: processing remote data for replication origin "pg_16395" during "INSER
|
||||
</screen>
|
||||
The LSN of the transaction that contains the change violating the constraint and
|
||||
the replication origin name can be found from the server log (LSN 0/14C0378 and
|
||||
replication origin <literal>pg_16395</literal> in the above case). To skip the
|
||||
transaction, the subscription needs to be disabled temporarily by
|
||||
<command>ALTER SUBSCRIPTION ... DISABLE</command> first or alternatively, the
|
||||
replication origin <literal>pg_16395</literal> in the above case). The
|
||||
transaction that produces conflict can be skipped by using
|
||||
<command>ALTER SUBSCRIPTION ... SKIP</command> with the finish LSN
|
||||
(i.e., LSN 0/14C0378). The finish LSN could be an LSN at which the transaction
|
||||
is committed or prepared on the publisher. Alternatively, the transaction can
|
||||
also be skipped by calling the <link linkend="pg-replication-origin-advance">
|
||||
<function>pg_replication_origin_advance()</function></link> function
|
||||
transaction. Before using this function, the subscription needs to be disabled
|
||||
temporarily either by <command>ALTER SUBSCRIPTION ... DISABLE</command> or, the
|
||||
subscription can be used with the <literal>disable_on_error</literal> option.
|
||||
Then, the transaction can be skipped by calling the
|
||||
<link linkend="pg-replication-origin-advance">
|
||||
<function>pg_replication_origin_advance()</function></link> function with
|
||||
the <parameter>node_name</parameter> (i.e., <literal>pg_16395</literal>) and the
|
||||
next LSN of the transaction's LSN (i.e., LSN 0/14C0379). After that the replication
|
||||
can be resumed by <command>ALTER SUBSCRIPTION ... ENABLE</command>. The current
|
||||
position of origins can be seen in the
|
||||
<link linkend="view-pg-replication-origin-status">
|
||||
Then, you can use <function>pg_replication_origin_advance()</function> function
|
||||
with the <parameter>node_name</parameter> (i.e., <literal>pg_16395</literal>)
|
||||
and the next LSN of the finish LSN (i.e., 0/14C0379). The current position of
|
||||
origins can be seen in the <link linkend="view-pg-replication-origin-status">
|
||||
<structname>pg_replication_origin_status</structname></link> system view.
|
||||
Please note that skipping the whole transaction include skipping changes that
|
||||
might not violate any constraint. This can easily make the subscriber
|
||||
inconsistent.
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
|
@ -29,6 +29,7 @@ ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> REFRESH PUB
|
||||
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> ENABLE
|
||||
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> DISABLE
|
||||
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> SET ( <replaceable class="parameter">subscription_parameter</replaceable> [= <replaceable class="parameter">value</replaceable>] [, ... ] )
|
||||
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> SKIP ( <replaceable class="parameter">skip_option</replaceable> = <replaceable class="parameter">value</replaceable> )
|
||||
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> OWNER TO { <replaceable>new_owner</replaceable> | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
|
||||
ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> RENAME TO <replaceable>new_name</replaceable>
|
||||
</synopsis>
|
||||
@ -210,6 +211,47 @@ ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> RENAME TO <
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>SKIP ( <replaceable class="parameter">skip_option</replaceable> = <replaceable class="parameter">value</replaceable> )</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Skips applying all changes of the remote transaction. If incoming data
|
||||
violates any constraints, logical replication will stop until it is
|
||||
resolved. By using <command>ALTER SUBSCRIPTION ... SKIP</command> command,
|
||||
the logical replication worker skips all data modification changes within
|
||||
the transaction. This option has no effect on the transactions that are
|
||||
already prepared by enabling <literal>two_phase</literal> on
|
||||
subscriber.
|
||||
After logical replication worker successfully skips the transaction or
|
||||
finishes a transaction, LSN (stored in
|
||||
<structname>pg_subscription</structname>.<structfield>subskiplsn</structfield>)
|
||||
is cleared. See <xref linkend="logical-replication-conflicts"/> for
|
||||
the details of logical replication conflicts. Using this command requires
|
||||
superuser privilege.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<replaceable>skip_option</replaceable> specifies options for this operation.
|
||||
The supported option is:
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term><literal>lsn</literal> (<type>pg_lsn</type>)</term>
|
||||
<listitem>
|
||||
<para>
|
||||
Specifies the finish LSN of the remote transaction whose changes
|
||||
are to be skipped by the logical replication worker. The finish LSN
|
||||
is the LSN at which the transaction is either committed or prepared.
|
||||
Skipping individual subtransaction is not supported. Setting
|
||||
<literal>NONE</literal> resets the LSN.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><replaceable class="parameter">new_owner</replaceable></term>
|
||||
<listitem>
|
||||
|
Reference in New Issue
Block a user