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 1m5mkg-00020j-QE for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Jul 2021 10:13:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m5mke-0004zd-Mx for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Jul 2021 10:13:24 +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 1m5mke-0004zT-4U for pgsql-hackers@lists.postgresql.org; Tue, 20 Jul 2021 10:13:24 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m5mka-0002Ky-7I for pgsql-hackers@lists.postgresql.org; Tue, 20 Jul 2021 10:13:23 +0000 Received: by mail-wm1-x334.google.com with SMTP id l17-20020a05600c1d11b029021f84fcaf75so1163094wms.1 for ; Tue, 20 Jul 2021 03:13:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=/HnZAzFLolWNwkwMAYrMla8UjyRBtMTDqJFUTIS02oI=; b=fjGIKEHEOlhDk8LBHeZqCnjJioat92zGBODECyqp8vYdk4dsVT0wKahsHpXtA7x4+y cV8SbB9C3wg17h8je9zNS2BkKUyx6j4dj/zQw3qHNMf1L3S9uf83TNMxd6JVxeCgngnh zQuzky1na3OFSZCMvVIo42dPB6lScaLbMYPL9vIiFZn8cjyiFOI7WfgcRIm0BMujX8EJ 75aHA55j0h03HR1oEKllByW1thM2UShRFsqdDE3Ldbna9TGbZ3O5xmDg3OXGTRsLPRNE bk7EI5kWjWwOe02h1cGYsKVMGLaZb3fMPb25CmqF78LlyVQkxz/s/V3/mqnaYsiYgc+f 5F3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=/HnZAzFLolWNwkwMAYrMla8UjyRBtMTDqJFUTIS02oI=; b=SuVbX0SYEWNdGhyUaQKrJYtrn70TRH7TpWeDejsTDhPi26JxyNsApq1dAwkQ8M7d7k eQgjYD3txZ5fi3vFdgWKl0CIEsfoYhwsrn0uLIkCBTWGLnV/OUrincdsufmfOgU20Nzi npbMUO0Ly7bQzZUh2Vp84UOA4SANrmXQxc50je98Pxu+nKUY17iRRaEGU2eseV4bONh5 jY36JOdCA1fTIrIcb86nI4fTg+Jun8RLVhwGe/dMDl03H3uGduLRVj3I67wyjlLLrOJ4 Nzhs0Yq6WH6FpkOnM8mqLK8eRWWiLsXp2SCzFJ5LOqzr/xEDhGkwDxqFLiJz8xrPtmZ2 JhTQ== X-Gm-Message-State: AOAM531tigfW7C2OzCuxfPGXy0PG/cng22neCfZ9YHy+uv/YPMi9bq5u t9D0jrc6ThTl9QmktDCPJUjvDETnWFRo1+Fl7qnNMdTvbruGkWd0LSHnizs5wijRrMAIbvobrId Yn5st7iijadRs+6a8TmWXlkU0EeBFyvj23UnSe+FefUrJZnxx1wC/44F/JImgdgVQTvSYbncCeT nnTmaEF5Twk91P0/u5zn+rytdF83P5amgywVku7HH/UrUd7nppd+3+mnHCvhLKeoModqWcpCtNI DajpILpzplEvN8FZgMw0n5V5ErWfg4FKcv6W5sV4RmoNlv4fTp21w== X-Google-Smtp-Source: ABdhPJw5oPKGvSGaWkheNFFLlMDHNMvXS4PTfHEAaMvbVoMbqaABBjrQaEwJtP+t7jQgW1KCQk00IA== X-Received: by 2002:a7b:c002:: with SMTP id c2mr30362531wmb.118.1626775997033; Tue, 20 Jul 2021 03:13:17 -0700 (PDT) Received: from [10.137.0.19] (ip-86-49-254-183.net.upcbroadband.cz. [86.49.254.183]) by smtp.gmail.com with ESMTPSA id n5sm22334799wri.31.2021.07.20.03.13.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Jul 2021 03:13:16 -0700 (PDT) Subject: Re: row filtering for logical replication To: Amit Kapila Cc: Dilip Kumar , Alvaro Herrera , Greg Nancarrow , Euler Taveira , Peter Smith , Rahila Syed , Peter Eisentraut , =?UTF-8?B?w5ZuZGVyIEthbGFjxLE=?= , japin , Michael Paquier , David Steele , Craig Ringer , Tomas Vondra , Amit Langote , PostgreSQL Hackers References: <202107162135.m5ehijgcasjk@alvherre.pgsql> From: Tomas Vondra Message-ID: Date: Tue, 20 Jul 2021 12:13:13 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 7/20/21 11:42 AM, Amit Kapila wrote: > On Tue, Jul 20, 2021 at 2:39 PM Tomas Vondra > wrote: >> >> On 7/20/21 7:23 AM, Amit Kapila wrote: >>> On Mon, Jul 19, 2021 at 7:02 PM Tomas Vondra >>> wrote: >> >>>> So maybe the best thing is to stick to the simple approach already used >>>> e.g. by pglogical, which simply user the new row when available (insert, >>>> update) and old one for deletes. >>>> >>>> I think that behaves more or less sensibly and it's easy to explain. >>>> >>> >>> Okay, if nothing better comes up, then we can fall back to this option. >>> >>>> All the other things (e.g. turning UPDATE to INSERT, advanced conflict >>>> resolution etc.) will require a lot of other stuff, >>>> >>> >>> I have not evaluated this yet but I think spending some time thinking >>> about turning Update to Insert/Delete (yesterday's suggestion by >>> Alvaro) might be worth especially as that seems to be followed by some >>> other replication solution as well. >>> >> >> I think that requires quite a bit of infrastructure, and I'd bet we'll >> need to handle other types of conflicts too. >> > > Hmm, I don't see why we need any additional infrastructure here if we > do this at the publisher. I think this could be done without many > changes to the patch as explained in one of my previous emails [1]. > Oh, I see. I've been thinking about doing the "usual" conflict resolution on the subscriber side. I'm not sure about doing this on the publisher ... >> I don't have a clear >> opinion if that's required to get this patch working - I'd try getting >> the simplest implementation with reasonable behavior, with those more >> advanced things as future enhancements. >> >>>> and I see them as >>>> improvements of this simple approach. >>>> >>>>>>> Maybe a second option is to have replication change any UPDATE into >>>>>>> either an INSERT or a DELETE, if the old or the new row do not pass the >>>>>>> filter, respectively. That way, the databases would remain consistent. >>>>> >>>>> Yeah, I think this is the best way to keep the data consistent. >>>>> >>>> >>>> It'd also require REPLICA IDENTITY FULL, which seems like it'd add a >>>> rather significant overhead. >>>> >>> >>> Why? I think it would just need similar restrictions as we are >>> planning for Delete operation such that filter columns must be either >>> present in primary or replica identity columns. >>> >> >> How else would you turn UPDATE to INSERT? For UPDATE we only send the >> identity columns and modified columns, and the decision happens on the >> subscriber. >> > > Hmm, we log the entire new tuple and replica identity columns for the > old tuple in WAL for Update. And, we are going to use a new tuple for > Insert, so we have everything we need. > Do we log the TOAST-ed values that were not updated? regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company