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 1nacP6-0004Sq-Sv for pgsql-hackers@arkaria.postgresql.org; Sat, 02 Apr 2022 11:58:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nacP5-0006ls-Nb for pgsql-hackers@arkaria.postgresql.org; Sat, 02 Apr 2022 11:58:51 +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 1nacP5-0006lj-48 for pgsql-hackers@lists.postgresql.org; Sat, 02 Apr 2022 11:58:51 +0000 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nacP0-0003HY-4i for pgsql-hackers@lists.postgresql.org; Sat, 02 Apr 2022 11:58:50 +0000 Received: by mail-ed1-x530.google.com with SMTP id b15so5813434edn.4 for ; Sat, 02 Apr 2022 04:58:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=H8Jg9ncOMSvzFc6N3Mg6wArSUzzeF/qHijqWWbL9c5c=; b=AoC5caBsOJVbJpqseEDSZcxbTLV5WI3TpoOPeJsF61LWymLNw+Qwg9EkNsfby3CSzu sb2/kqCqK9A5Ae6S899HjhqfQ/7RMyB+G481iwANoKr6fkXk8EzV4uUj0aLMfG0C+JJD aVDiuJJ9QtR5odlhigkrwgS2XQd4BWrcvXIfoJt+dGlu64vuvdC1I4OuhwtC4AqAtRBF 8m4VHztuEoVJIfM47LIDXiaEHcVWvUMYxj27DrB3iXDImS+aMYIolkJe1ZZTAvfSlrrN RFuZXlgcivd6OQQ0jEyxJNWmH+zdxEluGbr493mJh1AXdrCULoSoZU4+SYdYFs1rrG3c OEEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=H8Jg9ncOMSvzFc6N3Mg6wArSUzzeF/qHijqWWbL9c5c=; b=y2yCJFyTSUIwDd/2liK0i5Pz4riZE1Ygr3ghvdR6mGkyO/RhHKOM2+ccm6dY8Gq3ny g4iUpug2fRJZH5fUrePv7vHP99xImsXkQZq8GXXQt1n+g0lzdYuH2n+ZD6kL9Zy7RNzI vB5ycJ2TJ1T30DwLB76oQYTOLjF/C0cpVZw8phkwuG39BtZACK5DOWHEb/tx16FRbx+Y T9Z9oDMup1GaJs3y7jVHEYYudy2aeJbxO45OP5wCugWIE33bX/ZEvAzM16ci+n3EBsKr hKNfy6TEAgiBvkN6LPg8ahKYXwZLn8QZZDwabd4GO1BjS1/7hHpCvY/QuQFQ440TWtyn LGSg== X-Gm-Message-State: AOAM531US/dvhLKmCEysxznZjSeMjRNA1Bfi0FSf5Dxavza9Wet0l/FF bcWK8jC26jZNy2d9CeO6fPNa7s/O+S+r9SJw1hpoemtBs7jidoqy3ntxH2PpaTPsQ0ZItSBfAUN 1fYlpMkdpwOwVbVP0/GZPZrucKV+Q9BG4Cvkgdrf5z2MDno+GryFPc6+hP20KRLpboH63WmwHdq mUectodpwW8PWfshzQ2UCsnGnVP67R3TPEU2k/FvfBIITb4NwTyagzXCFjhkhU X-Google-Smtp-Source: ABdhPJwvIZOEqOX10PXWGcvBACg5IuCvx8NnLTIh7753rcbtbAKZWSuJ4KvGQ/AGgegumIzj5MzllQ== X-Received: by 2002:a05:6402:26d6:b0:419:3664:595e with SMTP id x22-20020a05640226d600b004193664595emr25594591edd.306.1648900723535; Sat, 02 Apr 2022 04:58:43 -0700 (PDT) Received: from [10.137.0.17] (ip-86-49-250-165.net.upcbroadband.cz. [86.49.250.165]) by smtp.gmail.com with ESMTPSA id hb6-20020a170907160600b006dff6a979fdsm2011920ejc.51.2022.04.02.04.58.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Apr 2022 04:58:42 -0700 (PDT) Message-ID: <7f4f4783-a9fd-6b1b-b39d-3c5f72d54961@enterprisedb.com> Date: Sat, 2 Apr 2022 13:58:43 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: logical decoding and replication of sequences Content-Language: en-US To: Amit Kapila Cc: Petr Jelinek , Peter Eisentraut , PostgreSQL Hackers References: <74729cc5-960b-9295-912a-a7c37356a0c4@enterprisedb.com> <9d7635f8-2402-e038-64da-cbc3732ce8cf@enterprisedb.com> <83c682bf-7164-5976-608c-385cc394bb6c@enterprisedb.com> <494bb2d9-0c1c-b429-e6bb-231f00f2c36f@enterprisedb.com> <00708727-d856-1886-48e3-811296c7ba8c@enterprisedb.com> From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 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 4/2/22 12:43, Amit Kapila wrote: > On Sat, Apr 2, 2022 at 5:47 AM Tomas Vondra > wrote: >> >> On 4/1/22 17:02, Tomas Vondra wrote: >> >> The only option I see is reworking the decoding so that it does not need >> the snapshot at all. We'll need to stash the changes just like any other >> change, apply them at end of transaction, and the main difference >> between transactional and non-transactional case would be what happens >> at abort. Transactional changes would be discarded, non-transactional >> would be applied anyway. >> > > I think in the above I am not following how we can make it work > without considering *snapshot at all* because based on that we would > have done the initial sync (copy_sequence) and if we don't follow that > later it can lead to inconsistency. I might be missing something here. > Well, what I meant to say is that we can't consider the snapshot at this phase of decoding. We'd still consider it later, at commit/abort time, of course. I.e. it'd be fairly similar to what heap_decode/DecodeInsert does, for example. AFAIK this does not build the snapshot anywhere. >> The challenge is this reorders the sequence changes, so we'll need to >> reconcile them somehow. One option would be to simply (1) apply the >> change with the highest LSN in the transaction, and then walk all other >> in-progress transactions and changes for that sequence with a lower LSN. >> Not sure how complex/expensive that would be, though. Another problem is >> not all increments are WAL-logged, of course, not sure about that. >> >> Another option might be revisiting the approach proposed by Hannu in >> September [1], i.e. tracking sequences touched in a transaction, and >> then replicating the current state at that particular moment. >> > > I'll think about that approach as well. > Thanks! -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company