Log the conflicts while applying changes in logical replication.
authorAmit Kapila <akapila@postgresql.org>
Tue, 20 Aug 2024 03:05:11 +0000 (08:35 +0530)
committerAmit Kapila <akapila@postgresql.org>
Tue, 20 Aug 2024 03:05:11 +0000 (08:35 +0530)
commit9758174e2e5cd278cf37e0980da76b51890e0011
tree9ca019972be8f6b4b20acd98cdeb12a9475851e9
parentadf97c1562380e02acd60dc859c289ed3a8352ee
Log the conflicts while applying changes in logical replication.

This patch provides the additional logging information in the following
conflict scenarios while applying changes:

insert_exists: Inserting a row that violates a NOT DEFERRABLE unique constraint.
update_differ: Updating a row that was previously modified by another origin.
update_exists: The updated row value violates a NOT DEFERRABLE unique constraint.
update_missing: The tuple to be updated is missing.
delete_differ: Deleting a row that was previously modified by another origin.
delete_missing: The tuple to be deleted is missing.

For insert_exists and update_exists conflicts, the log can include the origin
and commit timestamp details of the conflicting key with track_commit_timestamp
enabled.

update_differ and delete_differ conflicts can only be detected when
track_commit_timestamp is enabled on the subscriber.

We do not offer additional logging for exclusion constraint violations because
these constraints can specify rules that are more complex than simple equality
checks. Resolving such conflicts won't be straightforward. This area can be
further enhanced if required.

Author: Hou Zhijie
Reviewed-by: Shveta Malik, Amit Kapila, Nisha Moond, Hayato Kuroda, Dilip Kumar
Discussion: https://postgr.es/m/OS0PR01MB5716352552DFADB8E9AD1D8994C92@OS0PR01MB5716.jpnprd01.prod.outlook.com
18 files changed:
doc/src/sgml/logical-replication.sgml
src/backend/access/index/genam.c
src/backend/catalog/index.c
src/backend/executor/execIndexing.c
src/backend/executor/execMain.c
src/backend/executor/execReplication.c
src/backend/executor/nodeModifyTable.c
src/backend/replication/logical/Makefile
src/backend/replication/logical/conflict.c [new file with mode: 0644]
src/backend/replication/logical/meson.build
src/backend/replication/logical/worker.c
src/include/executor/executor.h
src/include/replication/conflict.h [new file with mode: 0644]
src/test/subscription/t/001_rep_changes.pl
src/test/subscription/t/013_partition.pl
src/test/subscription/t/029_on_error.pl
src/test/subscription/t/030_origin.pl
src/tools/pgindent/typedefs.list