Detect and Log multiple_unique_conflicts type conflict.
authorAmit Kapila <akapila@postgresql.org>
Mon, 24 Mar 2025 07:00:44 +0000 (12:30 +0530)
committerAmit Kapila <akapila@postgresql.org>
Mon, 24 Mar 2025 07:00:44 +0000 (12:30 +0530)
commit73eba5004a06a744b6b8570e42432b9e9f75997b
treeda0a5610000c1b9c4fd540299dc2068231efcf82
parent35a92b7c2520cca3df9ecddab1dcad14ff71ec0b
Detect and Log multiple_unique_conflicts type conflict.

Introduce a new conflict type, multiple_unique_conflicts, to handle cases
where an incoming row during logical replication violates multiple UNIQUE
constraints.

Previously, the apply worker detected and reported only the first
encountered key conflict (insert_exists/update_exists), causing repeated
failures as each constraint violation needs to be handled one by one
making the process slow and error-prone.

With this patch, the apply worker checks all unique constraints upfront
once the first key conflict is detected and reports
multiple_unique_conflicts if multiple violations exist. This allows users
to resolve all conflicts at once by deleting all conflicting tuples rather
than dealing with them individually or skipping the transaction.

In the future, this will also allow us to specify different resolution
handlers for such a conflict type.

Add the stats for this conflict type in pg_stat_subscription_stats.

Author: Nisha Moond <nisha.moond412@gmail.com>
Author: Zhijie Hou <houzj.fnst@fujitsu.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Peter Smith <smithpb2250@gmail.com>
Reviewed-by: Dilip Kumar <dilipbalaut@gmail.com>
Discussion: https://postgr.es/m/CABdArM7FW-_dnthGkg2s0fy1HhUB8C3ELA0gZX1kkbs1ZZoV3Q@mail.gmail.com
14 files changed:
doc/src/sgml/logical-replication.sgml
doc/src/sgml/monitoring.sgml
src/backend/catalog/system_views.sql
src/backend/executor/execReplication.c
src/backend/replication/logical/conflict.c
src/backend/replication/logical/worker.c
src/backend/utils/adt/pgstatfuncs.c
src/include/catalog/catversion.h
src/include/catalog/pg_proc.dat
src/include/replication/conflict.h
src/test/regress/expected/rules.out
src/test/subscription/meson.build
src/test/subscription/t/035_conflicts.pl [new file with mode: 0644]
src/tools/pgindent/typedefs.list