Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jxl3G-0003Kv-Jc for pgsql-general@arkaria.postgresql.org; Tue, 21 Jul 2020 05:42:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jxl3E-0001BC-9U for pgsql-general@arkaria.postgresql.org; Tue, 21 Jul 2020 05:42:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jxl3D-00017l-W9 for pgsql-general@lists.postgresql.org; Tue, 21 Jul 2020 05:42:52 +0000 Received: from mout.gmx.net ([212.227.17.20]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jxl37-0003Z8-DY for pgsql-general@lists.postgresql.org; Tue, 21 Jul 2020 05:42:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1595310162; bh=vmTUCe9PCP83uapWKu1j4ZPczLVvaimu13HBidQoxo4=; h=X-UI-Sender-Class:Subject:To:References:From:Date:In-Reply-To; b=Ganhp4xLrhgzXuFYI1vdU+XhahTbz05VTP5Fq4VrO336CHPINaQtSkKDQpAT1qlfI b3GNfN/BeCfceGjDi9vBITwRxcKG7LAEG+nQirbHCsWk8zvhlxV7mneKtOanUFWzXs +oltE2QMsQ5oCpNZxf4MC6c+zeVvpLP2UVPC11dA= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [10.1.34.33] ([185.40.248.10]) by mail.gmx.com (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1Mi2Jt-1kSiDD1z6n-00e6va for ; Tue, 21 Jul 2020 07:42:42 +0200 Subject: Re: Logical replication from 11.x to 12.x and "unique key violations" To: pgsql-general@lists.postgresql.org References: <76af9b83-74cc-88b5-23a7-0462774f472d@gmx.net> <229a51af-0860-0ab4-5c91-3f0c197ba682@aklaver.com> From: Thomas Kellerer Message-ID: <8beac400-5c2c-560e-668c-e7c0c81e3b9c@gmx.net> Date: Tue, 21 Jul 2020 07:42:41 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 MIME-Version: 1.0 In-Reply-To: <229a51af-0860-0ab4-5c91-3f0c197ba682@aklaver.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:g/x5T3agXdx/6x9A7S54yZsZ3Wi7spuPsLp/ue0AuCicmXa0fl5 1RIGLk9PkqGoDOtR2bO3PiuWXhrzzsl+otLPwRT6OYryHcX87zQmpUUG2e8g/g4ccFolaoM b9QCsqQy5BhuDvyXd7qxbVWcxKnM/uj5ODWLPnwS9gu9j0ehPglxvNTlqAuuIhTM2cOhslB rUFhuZrl0ujbt63leXQbA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:rTjcX0Y/2fw=:ufjjNYi0iitxLAs1WCI6Yg VDDWwgmpxuwjzHG+Ee/oMywdlRJYdu9ykfjk3O+9oWqa7VJ4mHc4bK5mRRjAiDsaw5BBjJ3i7 LlYGU17yTDwIP95o2w9bwKi2gWPd/SWXvDJ/ElqLVingTn5ReYcxRtMQjBzMvzxy8FKsQHD0a eLTxea9Spn2G1UVDwa5SPaK529BoySFAk/jNCvLUHJi28OmMPxhGtC3DF2r5cenAmFA7WeKlJ LxXbYI4rXWKh3PX9Cg7KC9gkuilZU2bJsezZ/VRQ3s5bOa+7+hGW0HZvR2tMfbGB2W1Dxgsrt OmmWmA8Vk0QJe3OfoXlwd55nPrfloSRRI1iMv7vBdtRmIAJ2LdTZPiiI6DuGYB74R7NJv4xeA IJAVEqVlH1boW1TypKYOTJOHPh70o/8FInmhMAC+HOsY1XyTOMl2R9/N+JgOjBqxrE3RraPCA biF1oi3+WV/aTFOusY6HQHAMEfTA950D21BLpxe7WVWwNoGWeFhyKGojTJyT+Qhp2hGSW1jwi Z4exBzJSfcsEEnCgolRNFcNYk9xhzpgLunvNDz+PvKakfeB/2B3OI01MI7RtTYTxvcIUzbkBU RmxH1/iLqdG01dKtYPyWM2OA6ppBkbDbN3Z3sUmAhVYboGsavy/6Jhvhqx8sbEOXxYlVMosPe dc1Md3Vw/m9S00ctwJQ8OUzIwxyYgLYRIy0IQyAkiX1clQuLfUzJApkDcNpdFcaU3o1hAwqka l8QfclSDPZAjGiEh8Lp4V5JrrK50BeP1y5Abaa5Q88vkdM4k4dSS7vekupDNp2TPr/StNDtvZ lu/letljk4gohv4t60JXPpaZyaapYhP9pJxwNlJ1bhqMCLB3XWWctHJ54d8YpNDo6lxKpqNQN fUcq9aAcFFEKB7bI72VkASOGzvpQsM8vQutatQ45Y/3AIoKJ8kXanCXU6gv5XLIvKyJbP07Lw DRpXpTH9z0iQ9Bs5yF2Fu2iOwKbe+Y0z42IGWv/I1lV75oFHCxTYZOiNPZDgojd+DXoU26c2k WWJGxHaUTAvQ3egOi94LUbFao1WG1BoawISOyBpyiu5udKdwQUSAclzgdqS8wNeaTG/u2ZHEZ 7eRzn00WZSiFjN24yOYM8uLI1IrByXzvd9EULJysHBR6dHP9b9ovWrR9U/GusPJaazp6gRpGz g75XYlPmbyfGztTRnZ5EZm5jC5d+gsD3zPkTQ6t2HjFG/QUpK+csKA/CRZxjNf/EYw+TVj76a JwhQWQqJgruoB80VQ List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Adrian Klaver schrieb am 20.07.2020 um 16:45: > On 7/20/20 7:22 AM, Thomas Kellerer wrote: >>> 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. >>> >> >> Any pointers where I should start looking to investigate this? > > What are the PUBLICATION and SUBSCRIPTION commands being used? Pretty basic: create publication some_publication for table table1, table2, table3, ...., table50; create subscription foo connection '...' publication some_publication; The approach that worked: * create the publication with the first 10 tables * create the subscription, wait until the initial sync is finished * alter the publication add the next 10 tables * refresh the subscription, wait until the sync is finished - repeat until= all tables are replicated. Note that I did not pay attention to foreign key relationships when adding= the tables (I essentially added them in alphabetical order). I first thought that was= going to be a problem, but it seems Postgres can cope with that. Once the initial sync was through (about a week now), no further problems = came up. It's been running smoothly since then > Where is "xxx_pkey" coming from, e.g. sequence? No, as mentioned, those are varchar(20) columns. The values are generated by the application (no default value defined for = the column) > Where are source and target relative to each other in network/world? Same datacenter. > Are there any other errors in log at around the same time that might app= ly? No. > Are the tables heavily used when the subscription is invoked? Used, but not "heavily" (a few inserts per minute). And I think the tables where the errors happened, weren't written to at al= l. Those were rather small lookup tables (a few hundred rows at most) There are no triggers on the tables where the errors happened in case that= 's important.