RE: Simplify code building the LR conflict messages

From: "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>
To: 'Amit Kapila' <amit(dot)kapila16(at)gmail(dot)com>, shveta malik <shveta(dot)malik(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Álvaro Herrera <alvherre(at)kurilemu(dot)de>, Peter Smith <smithpb2250(at)gmail(dot)com>
Subject: RE: Simplify code building the LR conflict messages
Date: 2026-01-14 11:31:04
Message-ID: TY7PR01MB145549F3DB97B41825AB97910F58FA@TY7PR01MB14554.jpnprd01.prod.outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Dear Amit, Shveta,

> >
> > 1)
> > DETAIL: Could not apply remote row (20, 10).
> > DETAIL: Could not apply remote row (40, 200) by using replica
> > identity (i)=(20).
> >
> > We generally "apply" in terms of insert, update, delete etc and not
> > rows. Do you think we shall have:
> > 'Could not apply remote change (20, 10)..'
> >
> > The most informative will be to say below, but since operation-type is
> > already mentioned in Context, mentioning it here might not be needed.
> > So we can say 'remote change'.
> >
> > DETAIL: Could not apply remote INSERT for row (30, 10).
> > DETAIL: Could not apply remote UPDATE for row (40, 200) using replica
> > identity (i)=(20).
> >
>
> IIRC, the operation is already displayed in the context message. Here,
> we can say: DETAIL: Could not apply remote change using replica
> identity (i)=(20): remote row (40, 200).

Thanks for suggestions. I updated accordingly. Also, I found that local slot won't
be available in case of update_deleted, thus I removed from the code.
Current concern is that {update|delete}_origin_differ still construct the message
because there are three printable info. Can you suggest if you know better approaches?

In below I want to show some examples.

Case 1: multiple_unique_conflicts with UPDATE
HEAD:
DETAIL: Key already exists in unique index "foo_pkey", modified locally in transaction 789 at ...
Key (a)=(6); existing local row (6, 6, 6); remote row (6, 7, 8); replica identity (a)=(5).
Key already exists in unique index "foo_b_key", modified locally in transaction 789 at ...
Key (b)=(7); existing local row (7, 7, 7); remote row (6, 7, 8); replica identity (a)=(5).
Key already exists in unique index "foo_c_key", modified locally in transaction 789 at ...
Key (c)=(8); existing local row (8, 8, 8); remote row (6, 7, 8); replica identity (a)=(5).

V1:
DETAIL: Could not apply remote row (6, 7, 8) by using replica identity (a)=(5).
Key (a)=(6) already exists in unique index "foo_pkey", modified locally in transaction 790 at ...: local row (6, 6, 6).
Key (b)=(7) already exists in unique index "foo_b_key", modified locally in transaction 790 at ...: local row (7, 7, 7).
Key (c)=(8) already exists in unique index "foo_c_key", modified locally in transaction 790 at ...: local row (8, 8, 8).

V2:
DETAIL: Could not apply remote change by using replica identity (a)=(5): remote row (6, 7, 8).
Key (a)=(6) already exists in unique index "foo_pkey", modified locally in transaction 788 at ...: local row (6, 6, 6).
Key (b)=(7) already exists in unique index "foo_b_key", modified locally in transaction 788 at ...: local row (7, 7, 7).
Key (c)=(8) already exists in unique index "foo_c_key", modified locally in transaction 788 at ...: local row (8, 8, 8).

Case 2: update_origin_differs
HEAD:
DETAIL: Updating the row that was modified locally in transaction 790 at ...
Existing local row (5, 5, 5); remote row (6, 7, 8); replica identity (a)=(5).

V1:
DETAIL: Remote row (6, 7, 8) was applied but previously modified by different origin.
Local row (5, 5, 5) detected by replica identity (a)=(5) is being updated, but it was previously modified locally in transaction 790 at ....

V2:
DETAIL: Updating the row that was modified locally in transaction 790 at ...: local row (5, 5, 5), remote row (6, 7, 8), replica identity (a)=(5).

Case 3: delete_origin_differs with huge column
HEAD:
DETAIL: Deleting the row that was modified locally in transaction 795 at ...
Existing local row (1, testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttest...); replica identity (id)=(1).

V1:
DETAIL: Local row (1, testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttest...) detected by replica identity (id)=(1) is being deleted, but it was previously modified locally in transaction 797 at ....

V2:
DETAIL: Deleting the row that was modified locally in transaction 807 at ...: local row (1, testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttest...), replica identity (id)=(1).

Case 4: update_deleted
HEAD:
DETAIL: The row to be updated was deleted locally in transaction 789 at ...
Remote row (6, 7, 8); replica identity (a)=(5).

V1:
DETAIL: Could not find remote row (6, 7, 8) by using replica identity (a)=(5).
Local row was previously deleted locally in transaction 795 at ....

V2:
DETAIL: Could not find the row by using replica identity (a)=(5): remote row (6, 7, 8).
The row to be updated was deleted locally in transaction 789 at ....

Best regards,
Hayato Kuroda
FUJITSU LIMITED

Attachment Content-Type Size
v2-0001-Fix-errdetail-for-logical-replication-conflict.patch application/octet-stream 37.5 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alena Vinter 2026-01-14 11:38:27 Re: Startup PANIC on standby promotion due to zero-filled WAL segment
Previous Message Jelte Fennema-Nio 2026-01-14 11:25:14 Re: Always show correct error message for statement timeouts, fixes random buildfarm failures