pgsql: Detect and Log multiple_unique_conflicts type conflict. - Mailing list pgsql-committers

From Amit Kapila
Subject pgsql: Detect and Log multiple_unique_conflicts type conflict.
Date
Msg-id E1twc3b-000jo9-1j@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/73eba5004a06a744b6b8570e42432b9e9f75997b

Modified Files
--------------
doc/src/sgml/logical-replication.sgml      |  31 +++++++-
doc/src/sgml/monitoring.sgml               |  12 +++
src/backend/catalog/system_views.sql       |   1 +
src/backend/executor/execReplication.c     |  30 +++++---
src/backend/replication/logical/conflict.c |  64 +++++++++-------
src/backend/replication/logical/worker.c   |  68 ++++++++---------
src/backend/utils/adt/pgstatfuncs.c        |   6 +-
src/include/catalog/catversion.h           |   2 +-
src/include/catalog/pg_proc.dat            |   6 +-
src/include/replication/conflict.h         |  26 +++++--
src/test/regress/expected/rules.out        |   3 +-
src/test/subscription/meson.build          |   1 +
src/test/subscription/t/035_conflicts.pl   | 113 +++++++++++++++++++++++++++++
src/tools/pgindent/typedefs.list           |   1 +
14 files changed, 276 insertions(+), 88 deletions(-)


pgsql-committers by date:

Previous
From: David Rowley
Date:
Subject: pgsql: Add tests for POSITION(bytea, bytea)
Next
From: Heikki Linnakangas
Date:
Subject: pgsql: Add test case for when subscriber table is missing a column