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 1jxl8N-0003WY-H9 for pgsql-general@arkaria.postgresql.org; Tue, 21 Jul 2020 05:48:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jxl8M-00089g-Bf for pgsql-general@arkaria.postgresql.org; Tue, 21 Jul 2020 05:48:10 +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 1jxl8M-00089Y-4G for pgsql-general@lists.postgresql.org; Tue, 21 Jul 2020 05:48:10 +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 1jxl8I-0000UD-Cp for pgsql-general@lists.postgresql.org; Tue, 21 Jul 2020 05:48:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1595310485; bh=Fz4kybjBHh01wDnqyHdZ4LrhRAv7WDYX5TDpI+LsTJk=; h=X-UI-Sender-Class:Subject:To:References:From:Date:In-Reply-To; b=H6eoHzzNNlv3OMjk4kWhUcYUpawCfNYLb0RIx6U+MSF/lak6u0bzPgrEZ6JLZFd2K Iqz4GxzXTjuvNA1zYdM+S1ZCyQwuoRTuBsE2PnSjnLB7lZQLhx2lvbrjO1Bk02dX+X bozUqpw7wOfqk8GwTP+JM6jXuFSb7e/Fg6Ir7L+k= 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 1M3DJl-1jz96v3Mib-003e2P for ; Tue, 21 Jul 2020 07:48:04 +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> <578230.1595267248@sss.pgh.pa.us> <6D3A1971-B2AF-4320-BC8C-A04147A5F842@ashmeadsoftware.com> From: Thomas Kellerer Message-ID: Date: Tue, 21 Jul 2020 07:48:03 +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: <6D3A1971-B2AF-4320-BC8C-A04147A5F842@ashmeadsoftware.com> Content-Type: text/plain; charset=utf-8 Content-Language: de-DE Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:JkfuzVBVM6z0ebY+e0EoFoeUjEUfUQRuhh29CRd2hDKf96+RnUB fIfx8akjbHIq1S0BYHm2MO5tM7JJ7FA5EvMxUcAzva0A9AS6by7VkqumWPp7652wrqBUVCY Ih0QQ+r9vIUH3+mVPHdY74hk0TEEHZlVSAc7wIQfK8+O0Tdu2C9l0q8Lv4RALqtfKEAHwQN 3L3PTro1r3Ace1tn8HODQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:MBGQIccfvRE=:owhooNLItM1xet/izVyDhZ qnmsoCS0AZZAOCk++IbhdaEXFvOKTVBzB7lCKcnQI/pY0DlFqCMxAlCv+AhDYXoZqNQS8yzD8 Qx1NJOzyIFLPvw3OnYRPoNpEgIrQVMpNWBPNDrNecKoXqjyMR+NZnXZdsEH2i0pvyizd43RKt AkPRZefuugRks+gYV8QfC7Q5/C/NRxtEJbvIfjmDCfiRJd/biBTZ38G4vb/CyXkJSIdt4O/Cp nI3uoIzWmkwMN0CKNO4Ha9+tF0fAzv6Qry6/zBSpHJDbONhpq6w5861m+uN5tf2dCLch0YPgW Cc3FRFjKi+xzya53MFFfcoDbVfo28JEa0cJj8aGArS96VMdz6HETsERpWqb4o3Twr8a756iyo TUUo82CulKXlBAAJQpFKiWeEtutJkYpO7y2za5/XGs5gXhKmfwvZ5TdbGk46jNOeDkP9Ee0CQ UY2MkILuw188UMSqyvbYZQr6Mime61J6rdJ6aESoGdnHd+Wa2c1zYWGhPRlfp6aqod/WCgnDa 3WDNVK2BdCv8OqD8Q9IhTz2KaDXM0DCShXqbTmvGgZgCH7R32H21fOkoqNCh55ALDPBVvzANp d7If0lVV4krvYXf04+G0KQ8cF2ablfkU0ugiUQAKEBkBHoOLqoIXC31qK0bL/SXa7COJvYa45 Nnf8KQgW74gYbOT8jI+GKWSlMPyWZAPcYXjhHHl+OAIGW2IX9JolFR/YJ7gPcjtcBViEIpzov swHox1B6mEo82KjmdWawePmhO6SluZ97QOzTKwJbHNgrADXohcSiVhGID/8U9enBvyo9j6E9J 9avrOlH7IsbzcCQrMtyth/kR6uosdIh7llgukk+sSxqagJErBJ4CX0J/rEEKtZi2MdKiYyO+f XU6B2/BhlYdtZqi9+bNMAq8b0dsUZqFVfZX+6OQI67vH0a0dhCHReWi9nzRHLJhVrKI7qqNu2 /40as49z3C1PedMVqZUnzqK8WViV7jLneqE3iu+rausPU+LwTrEMHJVjHJw3hRsQUjgpG0yIe yi+v/yD1zteEkPwDu+ilnOVQunG0rmchVZLlUBqgVtMbjyMtKyI7ZpBJk+cORFMojFCwLDgGb TdEL/+TM0D6/Ov0cRp5CNhXsMxBbQG6tPGELqGzs/2SZZwIDI3XaN5oXah9m8Gi1DG3Vkv+QX dOmi/2Fwv88yaIsR/f27DhhtNljkgajpfJAfPZvk8dJRWYndu2H9Mwxp/aWtpKgoqA5ouMDsL 7qhk4RzCwj07/o2HC List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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=E2=80=99ve = 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 =3D =E2=80=98INSERT=E2=80=99 then > select id into id1 from table1 where id =3D new.id ; > if id1 is not null then > =E2=80=94 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