diff options
author | Amit Kapila <akapila@postgresql.org> | 2025-03-24 12:30:44 +0530 |
---|---|---|
committer | Amit Kapila <akapila@postgresql.org> | 2025-03-24 12:30:44 +0530 |
commit | 73eba5004a06a744b6b8570e42432b9e9f75997b (patch) | |
tree | da0a5610000c1b9c4fd540299dc2068231efcf82 /doc/src | |
parent | 35a92b7c2520cca3df9ecddab1dcad14ff71ec0b (diff) | |
download | postgresql-73eba5004a06a744b6b8570e42432b9e9f75997b.tar.gz postgresql-73eba5004a06a744b6b8570e42432b9e9f75997b.zip |
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
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/logical-replication.sgml | 31 | ||||
-rw-r--r-- | doc/src/sgml/monitoring.sgml | 12 |
2 files changed, 39 insertions, 4 deletions
diff --git a/doc/src/sgml/logical-replication.sgml b/doc/src/sgml/logical-replication.sgml index 3556ce7cb46..f288c049a5c 100644 --- a/doc/src/sgml/logical-replication.sgml +++ b/doc/src/sgml/logical-replication.sgml @@ -1877,6 +1877,19 @@ test_sub=# SELECT * from tab_gen_to_gen; </para> </listitem> </varlistentry> + <varlistentry id="conflict-multiple-unique-conflicts" xreflabel="multiple_unique_conflicts"> + <term><literal>multiple_unique_conflicts</literal></term> + <listitem> + <para> + Inserting or updating a row violates multiple + <literal>NOT DEFERRABLE</literal> unique constraints. Note that to log + the origin and commit timestamp details of conflicting keys, ensure + that <link linkend="guc-track-commit-timestamp"><varname>track_commit_timestamp</varname></link> + is enabled on the subscriber. In this case, an error will be raised until + the conflict is resolved manually. + </para> + </listitem> + </varlistentry> </variablelist> Note that there are other conflict scenarios, such as exclusion constraint violations. Currently, we do not provide additional details for them in the @@ -1935,8 +1948,8 @@ DETAIL: <replaceable class="parameter">detailed_explanation</replaceable>. <para> The <literal>Key</literal> section includes the key values of the local tuple that violated a unique constraint for - <literal>insert_exists</literal> or <literal>update_exists</literal> - conflicts. + <literal>insert_exists</literal>, <literal>update_exists</literal> or + <literal>multiple_unique_conflicts</literal> conflicts. </para> </listitem> <listitem> @@ -1945,8 +1958,8 @@ DETAIL: <replaceable class="parameter">detailed_explanation</replaceable>. tuple if its origin differs from the remote tuple for <literal>update_origin_differs</literal> or <literal>delete_origin_differs</literal> conflicts, or if the key value conflicts with the remote tuple for - <literal>insert_exists</literal> or <literal>update_exists</literal> - conflicts. + <literal>insert_exists</literal>, <literal>update_exists</literal> or + <literal>multiple_unique_conflicts</literal> conflicts. </para> </listitem> <listitem> @@ -1982,6 +1995,16 @@ DETAIL: <replaceable class="parameter">detailed_explanation</replaceable>. The large column values are truncated to 64 bytes. </para> </listitem> + <listitem> + <para> + Note that in case of <literal>multiple_unique_conflicts</literal> conflict, + multiple <replaceable class="parameter">detailed_explanation</replaceable> + and <replaceable class="parameter">detail_values</replaceable> lines + will be generated, each detailing the conflict information associated + with distinct unique + constraints. + </para> + </listitem> </itemizedlist> </listitem> </varlistentry> diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index aaa6586d3a4..0960f5ba94a 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -2252,6 +2252,18 @@ description | Waiting for a newly initialized WAL file to reach durable storage <row> <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>confl_multiple_unique_conflicts</structfield> <type>bigint</type> + </para> + <para> + Number of times a row insertion or an updated row values violated multiple + <literal>NOT DEFERRABLE</literal> unique constraints during the + application of changes. See <xref linkend="conflict-multiple-unique-conflicts"/> + for details about this conflict. + </para></entry> + </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> <structfield>stats_reset</structfield> <type>timestamp with time zone</type> </para> <para> |