pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Thomas Kellerer <shammat@gmx.net>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Logical replication from 11.x to 12.x and "unique key violations"
Date: Mon, 20 Jul 2020 13:47:28 -0400
Message-ID: <578230.1595267248@sss.pgh.pa.us> (raw)
In-Reply-To: <76af9b83-74cc-88b5-23a7-0462774f472d@gmx.net>
References: <cfb19a91-e878-6994-4fda-3c64631f72e6@gmx.net>
	<76af9b83-74cc-88b5-23a7-0462774f472d@gmx.net>

Thomas Kellerer <shammat@gmx.net> writes:
>> I have a strange error when using logical replication between a 11.2
>> source database and a 12.3 target.
>> 
>> If I create the publication with all needed tables (about 50) at
>> once, I get "duplicate key value violates unique constraint xxx_pkey"
>> errors during the initial replication (when creating the
>> subscription).
>> 
>> When create the publication only with a few tables, the initial data
>> sync works without problems. To replicate all tables, I add the
>> tables incrementally to the publication, and refresh the
>> subscription.
>> 
>> If I do it like that (step-by-step) everything works fine. Tables
>> that generated the "duplicate key value" error previously will
>> replicate just fine. The tables are quite small, some of them less
>> then 100 rows.

I have not looked at the code, but it wouldn't surprise me if the initial
replication just copies all the specified tables in some random order.
If there are FK references involved, the replication would have to be
done with referenced tables first, and I bet there's no logic for that.
(Even if there was, it could not cope with circular references or
self-references.)

Best bet might be to not install the subscriber's foreign key
constraints till after the initial sync is done.

			regards, tom lane





view thread (17+ messages)  latest in thread

Message-ID: <578230.1595267248@sss.pgh.pa.us>
Permalink:  ../578230.1595267248@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/578230.1595267248@sss.pgh.pa.us

 · 

reply

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: tgl@sss.pgh.pa.us, shammat@gmx.net
  Subject: Re: Logical replication from 11.x to 12.x and "unique key violations"
  In-Reply-To: <578230.1595267248@sss.pgh.pa.us>
  References: <cfb19a91-e878-6994-4fda-3c64631f72e6@gmx.net> <76af9b83-74cc-88b5-23a7-0462774f472d@gmx.net> <578230.1595267248@sss.pgh.pa.us>

* 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