You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add the additional information to the logical replication worker errcontext.
This commits adds both the finish LSN (commit_lsn in case transaction got
committed, prepare_lsn in case of a prepared transaction, etc.) and
replication origin name to the existing error context message.
This will help users in specifying the origin name and transaction finish
LSN to pg_replication_origin_advance() SQL function to skip a particular
transaction.
Author: Masahiko Sawada
Reviewed-by: Takamichi Osumi, Euler Taveira, and Amit Kapila
Discussion: https://postgr.es/m/CAD21AoBarBf2oTF71ig2g_o=3Z_Dt6_sOpMQma1kFgbnA5OZ_w@mail.gmail.com
Copy file name to clipboardExpand all lines: doc/src/sgml/logical-replication.sgml
+19-4
Original file line number
Diff line number
Diff line change
@@ -352,11 +352,26 @@
352
352
<para>
353
353
The resolution can be done either by changing data or permissions on the subscriber so
354
354
that it does not conflict with the incoming change or by skipping the
355
-
transaction that conflicts with the existing data. The transaction can be
356
-
skipped by calling the <link linkend="pg-replication-origin-advance">
355
+
transaction that conflicts with the existing data. When a conflict produces
356
+
an error, the replication won't proceed, and the logical replication worker will
357
+
emit the following kind of message to the subscriber's server log:
358
+
<screen>
359
+
ERROR: duplicate key value violates unique constraint "test_pkey"
360
+
DETAIL: Key (c)=(1) already exists.
361
+
CONTEXT: processing remote data for replication origin "pg_16395" during "INSERT" for replication target relation "public.test" in transaction 725 finished at 0/14C0378
362
+
</screen>
363
+
The LSN of the transaction that contains the change violating the constraint and
364
+
the replication origin name can be found from the server log (LSN 0/14C0378 and
365
+
replication origin <literal>pg_16395</literal> in the above case). To skip the
366
+
transaction, the subscription needs to be disabled temporarily by
367
+
<command>ALTER SUBSCRIPTION ... DISABLE</command> first. Then, the transaction
368
+
can be skipped by calling the
369
+
<link linkend="pg-replication-origin-advance">
357
370
<function>pg_replication_origin_advance()</function></link> function with
358
-
a <parameter>node_name</parameter> corresponding to the subscription name,
359
-
and a position. The current position of origins can be seen in the
371
+
the <parameter>node_name</parameter> (i.e., <literal>pg_16395</literal>) and the
372
+
next LSN of the transaction's LSN (i.e., LSN 0/14C0379). After that the replication
373
+
can be resumed by <command>ALTER SUBSCRIPTION ... ENABLE</command>. The current
errcontext("processing remote data during \"%s\"",
3681
+
errcontext("processing remote data for replication origin \"%s\" during \"%s\"",
3682
+
errarg->origin_name,
3658
3683
logicalrep_message_type(errarg->command));
3659
-
else
3660
-
errcontext("processing remote data during \"%s\" in transaction %u",
3684
+
elseif (XLogRecPtrIsInvalid(errarg->finish_lsn))
3685
+
errcontext("processing remote data for replication origin \"%s\" during \"%s\" in transaction %u",
3686
+
errarg->origin_name,
3661
3687
logicalrep_message_type(errarg->command),
3662
3688
errarg->remote_xid);
3689
+
else
3690
+
errcontext("processing remote data for replication origin \"%s\" during \"%s\" in transaction %u finished at %X/%X",
3691
+
errarg->origin_name,
3692
+
logicalrep_message_type(errarg->command),
3693
+
errarg->remote_xid,
3694
+
LSN_FORMAT_ARGS(errarg->finish_lsn));
3663
3695
}
3664
3696
elseif (errarg->remote_attnum<0)
3665
-
errcontext("processing remote data during \"%s\" for replication target relation \"%s.%s\" in transaction %u",
3697
+
errcontext("processing remote data for replication origin \"%s\" during \"%s\" for replication target relation \"%s.%s\" in transaction %u finished at %X/%X",
3698
+
errarg->origin_name,
3666
3699
logicalrep_message_type(errarg->command),
3667
3700
errarg->rel->remoterel.nspname,
3668
3701
errarg->rel->remoterel.relname,
3669
-
errarg->remote_xid);
3702
+
errarg->remote_xid,
3703
+
LSN_FORMAT_ARGS(errarg->finish_lsn));
3670
3704
else
3671
-
errcontext("processing remote data during \"%s\" for replication target relation \"%s.%s\" column \"%s\" in transaction %u",
3705
+
errcontext("processing remote data for replication origin \"%s\" during \"%s\" for replication target relation \"%s.%s\" column \"%s\" in transaction %u finished at %X/%X",
0 commit comments