Re: Logical replication from 11.x to 12.x and "unique key violations"

From: Thomas Kellerer <shammat(at)gmx(dot)net>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Logical replication from 11.x to 12.x and "unique key violations"
Date: 2020-07-21 05:48:03
Message-ID: caa83d96-d701-e910-0f70-885532d0c6ca@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

John Ashmead schrieb am 20.07.2020 um 20:11:
> I have had this problem with logical replication on PG 10 repeatedly.
> In a clean build no problem.
>
> But if I am restarting replication because of some problem I’ve seen
> problems with rows already present.
>
> My own fix, which has worked in my shop, is to add replica triggers
> to check for the row being already present. If it is, they drop the
> row on the floor. This lets stuff come in in whatever order it
> happens to come in.
>
> Sample code:
>
> if TG_OP = ‘INSERT’ then
> select id into id1 from table1 where id = new.id <http://new.id>;
> if id1 is not null then
> — log error for analysis
> return null;
> end if;
> end if;
>
> In an ideal world, this would probably not be necessary. But it can
> be tricky to restart replication in an absolutely clean way across
> all tables and in this case it can be better to allow for a bit of
> overlap in the rows being replicated.
>

Interesting idea, I'll keep this in mind.

For now everything works fine, so there is no pressing need.

Thomas

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Radoslav Nedyalkov 2020-07-21 07:24:38 Re: Could not open file pg_xact/0E97
Previous Message Thomas Kellerer 2020-07-21 05:46:53 Re: Logical replication from 11.x to 12.x and "unique key violations"