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 1nY39v-0001gc-3u for pgsql-hackers@arkaria.postgresql.org; Sat, 26 Mar 2022 09:56:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nY39t-0003LI-8u for pgsql-hackers@arkaria.postgresql.org; Sat, 26 Mar 2022 09:56:33 +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 1nY39s-0003L9-Ke for pgsql-hackers@lists.postgresql.org; Sat, 26 Mar 2022 09:56:32 +0000 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nY39o-0006sB-8v for pgsql-hackers@lists.postgresql.org; Sat, 26 Mar 2022 09:56:31 +0000 Received: by mail-ed1-x533.google.com with SMTP id g20so11681462edw.6 for ; Sat, 26 Mar 2022 02:56:27 -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=rdowDKwnr2UIuft0OQDaGnDlB3+Jdn7AaaNkwx06DM0=; b=NJDZSBmknTy7FIk7G86nvUoX7DaZawaMaBLek89lA30ZbV47MF9qsadJAlQGG2kYF4 55PQjsCV7hs6c/EoVCaZpF5ZAiiHl62p3USWkfiCRmoXO7KIS7VcswKw3aC2y0zkF7tt mGyMPxrRIZ379fKQ1d3EUWtf7Bpq0H02t6BlqrPA0FX8twfYn+hlffjNCwA7HOJPsQxQ LbAe4BxPeLP0OHk5i9wQIvfFfE5pczyHsSMTZ9FGzlOKZeHti1pqm5X7bLGowgyed0sD qZGY6DqqNqwUOglGllus9Jwnhsy6BLfOH7KS7vq4xk7469YO3qY9qiPn8IXE4A9xikZe Vtjw== 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=rdowDKwnr2UIuft0OQDaGnDlB3+Jdn7AaaNkwx06DM0=; b=5hBwklxmD/FM7E/IC8LRqQI8n5SfhnpXfYcBMaYtPzCob5UEhbStD15n56Fpd89XX2 bRN9q61SD8mXII0zG/GkWDevHyp107ucOMbNHd9RkvdGpr6xtQrwhGK8HYKKvhcRgzcl Q1gn6QVkJWMrTEtNcQBQIBK5KNYOIQ6cxzDHNkx8ZwwTBeIf2FrQP0twh8jNyn0mx1mM HQSJ0sEPZPmb5q55UosR5bJ5xs9HwxEonxsTNSnu9YZFMJGYfN/eVFh1ik1BtC5Jwn4Z isuQ6tvo0sWBR7BRnN6bqJoz7Ov4s8Q5g87o/OHwQq7Aa/tyQWvBBUJGHwLb1TUcUOia /jvg== X-Gm-Message-State: AOAM531Ra03iCrrUATV1/abOhTzCCB/rFQpGHg0KnRcXuCwowkNEhPo5 Fw5JupXuGn2ok6rYTS1zCAXmg8EIdNuzRCRkfUPe2N67WONi2H5pz707pfXp+jB1fP0vTDH5AIo wwWfz0ZM66LDZvbyyU3xPPzwZDvxULrxvxmu7iMphdqO7+RdC9t0FaED5cRS67ozquvtKo2barp mQ/29PxCpjQnYvHhWqI+yfi5+5WC8+regwy5CIPchUI9AOu124R8AZ X-Google-Smtp-Source: ABdhPJzi2RGevl/oHMJPdO2EHaSkKayPm1wbpFlEtwahpBDYilbRCJVCxnTwmzH0f3GYONDD+H1SqA== X-Received: by 2002:a05:6402:506:b0:419:46b2:2433 with SMTP id m6-20020a056402050600b0041946b22433mr3542998edv.21.1648288585757; Sat, 26 Mar 2022 02:56:25 -0700 (PDT) Received: from [10.137.0.17] (ip-86-49-251-241.net.upcbroadband.cz. [86.49.251.241]) by smtp.gmail.com with ESMTPSA id gt34-20020a1709072da200b006df6bb3db69sm3362951ejc.158.2022.03.26.02.56.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 26 Mar 2022 02:56:25 -0700 (PDT) Message-ID: <494bb2d9-0c1c-b429-e6bb-231f00f2c36f@enterprisedb.com> Date: Sat, 26 Mar 2022 10:56:23 +0100 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: <6b21233e-c880-e4ad-5df2-7832f769296c@enterprisedb.com> <9da788c7-01eb-f11d-aa08-c5f61fe9f33a@enterprisedb.com> <456A528F-8F19-41C7-9857-927024D32396@enterprisedb.com> <74729cc5-960b-9295-912a-a7c37356a0c4@enterprisedb.com> <9d7635f8-2402-e038-64da-cbc3732ce8cf@enterprisedb.com> <83c682bf-7164-5976-608c-385cc394bb6c@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 3/26/22 08:28, Amit Kapila wrote: > On Fri, Mar 25, 2022 at 10:20 PM Tomas Vondra > wrote: >> >> Hmm, so fixing this might be a bit trickier than I expected. >> >> Firstly, currently we only send nspname/relname in the sequence message, >> not the remote OID or schema. The idea was that for sequences we don't >> really need schema info, so this seemed OK. >> >> But should_apply_changes_for_rel() needs LogicalRepRelMapEntry, and to >> create/maintain that those records we need to send the schema. >> >> Attached is a WIP patch does that. >> >> Two places need more work, I think: >> >> 1) maybe_send_schema needs ReorderBufferChange, but we don't have that >> for sequences, we only have TXN. I created a simple wrapper, but maybe >> we should just tweak maybe_send_schema to use TXN. >> >> 2) The transaction handling in is a bit confusing. The non-transactional >> increments won't have any explicit commit later, so we can't just rely >> on begin_replication_step/end_replication_step. But I want to try >> spending a bit more time on this. >> > > I didn't understand what you want to say in point (2). > My point is that handle_apply_sequence() either needs to use the same transaction handling as other apply methods, or start (and commit) a separate transaction for the "transactional" case. Which means we can't use the begin_replication_step/end_replication_step and the current code seems a bit complex. And I'm not sure it's quite correct. So this place needs more work. >> >> But there's a more serious issue, I think. So far, we allowed this: >> >> BEGIN; >> CREATE SEQUENCE s2; >> ALTER PUBLICATION p ADD SEQUENCE s2; >> INSERT INTO seq_test SELECT nextval('s2') FROM generate_series(1,100); >> COMMIT; >> >> and the behavior was that we replicated the changes. But with the patch >> applied, that no longer happens, because should_apply_changes_for_rel >> says the change should not be applied. >> >> And after thinking about this, I think that's correct - we can't apply >> changes until ALTER SUBSCRIPTION ... REFRESH PUBLICATION gets executed, >> and we can't do that until the transaction commits. >> >> So I guess that's correct, and the current behavior is a bug. >> > > Yes, I also think that is a bug. > OK >> For a while I was thinking that maybe this means we don't need the >> transactional behavior at all, but I think we do - we have to handle >> ALTER SEQUENCE cases that are transactional. >> > > I need some time to think about this. Understood. > At all places, it is mentioned > as creating a sequence for transactional cases which at the very least > need some tweak. > Which places? regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company