From: Thomas Kellerer <shammat@gmx.net>
To: pgsql-general@lists.postgresql.org
Subject: Re: Logical replication from 11.x to 12.x and "unique key violations"
Date: Tue, 21 Jul 2020 07:48:03 +0200
Message-ID: <caa83d96-d701-e910-0f70-885532d0c6ca@gmx.net> (raw)
In-Reply-To: <6D3A1971-B2AF-4320-BC8C-A04147A5F842@ashmeadsoftware.com>
References: <cfb19a91-e878-6994-4fda-3c64631f72e6@gmx.net>
<76af9b83-74cc-88b5-23a7-0462774f472d@gmx.net>
<578230.1595267248@sss.pgh.pa.us>
<6D3A1971-B2AF-4320-BC8C-A04147A5F842@ashmeadsoftware.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: shammat@gmx.net
Subject: Re: Logical replication from 11.x to 12.x and "unique key violations"
In-Reply-To: <caa83d96-d701-e910-0f70-885532d0c6ca@gmx.net>
References: <cfb19a91-e878-6994-4fda-3c64631f72e6@gmx.net> <76af9b83-74cc-88b5-23a7-0462774f472d@gmx.net> <578230.1595267248@sss.pgh.pa.us> <6D3A1971-B2AF-4320-BC8C-A04147A5F842@ashmeadsoftware.com> <caa83d96-d701-e910-0f70-885532d0c6ca@gmx.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox