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 1jy7QV-0004ww-63 for pgsql-general@arkaria.postgresql.org; Wed, 22 Jul 2020 05:36:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jy7QU-0001LR-5K for pgsql-general@arkaria.postgresql.org; Wed, 22 Jul 2020 05:36:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jy7QT-0001LK-Sz for pgsql-general@lists.postgresql.org; Wed, 22 Jul 2020 05:36:21 +0000 Received: from mout.gmx.net ([212.227.17.21]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jy7QR-0004Fb-Id for pgsql-general@lists.postgresql.org; Wed, 22 Jul 2020 05:36:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1595396176; bh=2tev128DsdntcHDbZ04dEqJN4xYnUFpLl8JB/PItlvc=; h=X-UI-Sender-Class:Subject:To:References:From:Date:In-Reply-To; b=hof9mFk88zPnTnvIRgLMj0+BS4RDgal8l93U2+iuQCPHQAu9P3v2AOW7PwgN/PFmY szPrUYGHZFfFVwgirrAMHYDz/5/ed6Nk/Sre0xF5WaGRaH6r4Z+Gobd7wggQIR4GeB jPCRnzhHy6quVVeW3PLej2VF9hh8mcDzEExKiSDI= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [10.1.35.134] ([185.40.248.10]) by mail.gmx.com (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1Mnpru-1kdG0j3Pxa-00pOxg for ; Wed, 22 Jul 2020 07:36:15 +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> <8beac400-5c2c-560e-668c-e7c0c81e3b9c@gmx.net> <4b444d07-241c-b327-df64-da2ea15ed93b@aklaver.com> From: Thomas Kellerer Message-ID: Date: Wed, 22 Jul 2020 07:36:15 +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: <4b444d07-241c-b327-df64-da2ea15ed93b@aklaver.com> Content-Type: text/plain; charset=utf-8 Content-Language: de-DE Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:45OH0i0ODqIpiMW1GD9L+GuIc5ZiFwurhStc4L5r/I+/uGskBB3 +n/8nRI5txMWmJUhNxXNtdwGc8xK8B7E1x2lTyjWfKGT5HjpRB07ogE2Tmtaj+BXenoG6Vu HeKPdbI3CR11LS2KoNemu6iWWLI0fST11nrdTs2E6LxmRR3Y5YJ6IXqDTrmKzktwuHVq+l5 2Of1dm9IDdvtMwMIhp4yA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:fTSOPE357lQ=:CEFqPm9sUAZWPMJaVj7qZW t/MxkXmUHFkk+OnWxZjvhNyG63+5DcddHDPQDjDXYnjNNBpk0oauQUVVuRNS/AtN5WkDg791p AOabU6GYAxhq523f9B1qu1rSOqJNduRQVMJ0ufemYUYX5tYd6EThrQsK+anC84yU2Fczm0Iiv h1UPcXcpuQ6lmP/MGdKDK2DYNcYW863GI+1PU4kqEhG2I7RYLy2dwzoXcFhy2PFQTsw+hgcl+ Pyu7jxc7jh/YAoZjnVowIgz46VL8CMnm2eXOoDFTHroh8W03oEmRLXTnoTtUM/UbJjcK/EvcI 2nGMX0VohmZIQtCleN3aqEy3YxbFIonoM3Tr7vT3YmruWiDervwfM0bhC4tYWRvT8Sjz449de hDz9voNXg7xnofLcjLC+R10mdUQpFozTPpbqTpjwSFXaP3TaqHRqWWy397kzlmJxjDGuaXXwB WOxfSlty/STDk4/3CU5n5CRlT04Oq7eeDEVoDVC0fE3Jrpu4mT7rGe/v8F/FVGhMk80qZ/Y+Y H6Nnq8L05tnoQElpSghzZ7a2EbFwYfOtW6PotczE2e8S9+IPvOL2BjJ/VUsx+XK2FOABEyfOC EtnazSHmduQ/n8G4hs433Hy6I6sprq/sZgVioqc4vRykfRR423NkUdLfNfu9CP/lalGe7u1qi 6NIy32+Q5RunSVTo9BE9TM9fSvhvyjrRXQSqftrVBQoeY9aEpGNVO06UxfgJk/pJfnmHtXeFQ zdUCQiyr+aH1TR60fNVkQkZwVN4Ff8j3xBcqcZxFO+0kqdQsqjcIjJrAKchA0q8SQPHRLwy6z ENolZHibwA6R9QgEDTId1s9kdM6OLNVwRQ4Kw619g32WRsS7Q3ASm9x2ecOcKWaG+/NVXrafl zcFyAOE52ZcibzyT4JR2FbeoV/thYRNkFmZq9fRxZfi2ubG/dYy4Nnf79c5Mzq/+mVJK+5INs DuM5Bmr8Zo+SJGENkuEjKGMD9oOsh3wEoy9BGOs6A5MHkIyqAXgxm9m/ZrUD6tBsqH+mk/mFK rexEKtszs9T9ZmvK3Tui9roRRckgL+zRxQDPoekCbZBdT+35muyAj0n0F/TxkmSN5gUMXDhcM kQHn8i7N3RHlzxcHdzVzWAZksQhKNMmSuT2oBL2FUnrqu9MZ1Yzh/VMQawx2i2JcJT+aNAb81 sTF2b0efUoHhhKvDJLdM6Kkxp8Bk5MLGeHs0a87KXXM6aWXqVoyYx7Z9ZffegoBbmKGwNcw12 dhJ+vC1v+6NviAPPd List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Adrian Klaver schrieb am 21.07.2020 um 17:07: >> No, as mentioned, those are varchar(20) columns. >> The values are generated by the application (no default value defined f= or the column) > > Aah I see my mistake I was going off your follow up question not the > original post. In that original post though you had the PK containing > a varchar(100) column. Can we see the table schema and the PK > definition for at least one of the tables that threw an error? > Sorry about the confusion, some PKs are indeed defined as varchar(100) som= e as varchar(20) and some as varchar(15) And I was also wrong about the generation, there is indeed a default value= defined using a self-written ID generation function. But during replication, that function isn't called, so it shouldn't matter= , I guess. Here are two examples of failing tables: CREATE TABLE IF NOT EXISTS emp_status ( emp_status_id varchar(15) DEFAULT generate_id('EA') NOT NULL PR= IMARY KEY, status_name varchar(20) NOT NULL UNIQUE ); CREATE TABLE IF NOT EXISTS company ( comp_id varchar(15) DEFAULT generate_id('CO') NOT NULL PRIMAR= Y KEY, name varchar(50) NOT NULL UNIQUE, country varchar(50) NOT NULL, code varchar(20) NOT NULL ); Both tables only contain only a few rows (less than 10) and e.g. for the s= tatus lookup, the log entry was: LOG: logical replication table synchronization worker for subscription "f= oo", table "emp_status" has started ERROR: duplicate key value violates unique constraint "emp_status_pkey" DETAIL: Key (employee_available_status_id)=3D(BUJ4XFZ7ATY27EA) already ex= ists. CONTEXT: COPY employee_available_status, line 1 Thomas