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 1mxUhT-0000UX-2O for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Dec 2021 13:52:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mxUhR-0007jC-1K for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Dec 2021 13:52:05 +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 1mxUhQ-0007j3-Bt for pgsql-hackers@lists.postgresql.org; Wed, 15 Dec 2021 13:52:04 +0000 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mxUhI-0001i9-Te for pgsql-hackers@lists.postgresql.org; Wed, 15 Dec 2021 13:52:02 +0000 Received: by mail-ed1-x534.google.com with SMTP id r11so74267901edd.9 for ; Wed, 15 Dec 2021 05:51:56 -0800 (PST) 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=/OqMJXmYjFW/sk9AD5lgvtfAJ0Nc+rUXcJfA5ZSOVO4=; b=VIB3BPCGFCzywpTClyRs1gR8Fn+EeRYD1IMVrL33T14QNTC8JlTIBPD3+KJ5eycXIJ 461EWTB308BjdzJ5WVQ35hJEUtZy3LRqJXBqdN/8qEIkM02xkGn1O4+Y3ztoAEuVxTpq dTXKEerkunQK5fj40bsBYdaV9Y9NPmzaEz+so00F4D48NI91DVlCwc51lyXyzxSWTyc2 QAxlf3plRjOOnSz1vvzI0azoBY/HOqqCC5aQPOHN0iwn770QxseW1atzQqOWqpgIYSEE D650xjcnlGpY+BiUMNvjI/DOGvv8PCTyU5uKwyPgB4gAAUOgbjRkYjkzAqGTTwZ1lWip iJjQ== 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=/OqMJXmYjFW/sk9AD5lgvtfAJ0Nc+rUXcJfA5ZSOVO4=; b=1ff4m+JWXBpJD7Pqcpn9ZbJES5hOXxmqUJxvsxnsrgxxv6MEV4cwGigjrKMWtIMcb7 aKDhIaVkItBe9XxdkZ03ZPPM/6YsTuezwZEDSdT/215lwj2In4aUNzrBWBH2fjeJoxuL 6c4Qyj3xEfqVl++fWi9uB395uoQ6tO5w3QZg5j1k4Mdra/o+evW5ZZK/C4xPv2KdkLcc PdgSejHpDkf0Cgb0lOMDYsGEBqRPsKUO+htiOMpO/jH6uaWz7Xb2e2Ke0I96NyMUrGJ3 Hd4bmSyMvf2I8Xj59ZRLJdy1t4HiziGxlR3c6enmr8xuMYD+RHNMRGcomXGVB0Bu8v4E 89aw== X-Gm-Message-State: AOAM530jvVbqZp1JPrnPEhVk+Vx7Kc3fMZ7KFBKNkN83DMF2ogsdk/TY zegyU9f3PF7YTwbX756RIfonexLeG0egpFSJylAG2W0KPlJqJN2PzDYtxj0kesOQM3xk4kgHlFN smyirVuUbE7gxRJO7Y2mu+Fwo5Wr9ZN9ZNOSOoPkY/YzjIY3g8tJuvVGPEuFWFckumDsr61+yZY N6ft/fvV6LrjSLIWSac6M5EdvvKDQbkrXsfLvadiXaE946xhqJ7gr/ X-Google-Smtp-Source: ABdhPJz5kJ5ondAM60ZEg/U53OlQWCoemcI6KAEXxAbKwXLKB8lsNXXZSjuIzqloZ+7o7wP+p6OMiA== X-Received: by 2002:a05:6402:51d3:: with SMTP id r19mr14761188edd.271.1639576315238; Wed, 15 Dec 2021 05:51:55 -0800 (PST) Received: from [10.137.0.19] (ip-86-49-251-241.net.upcbroadband.cz. [86.49.251.241]) by smtp.gmail.com with ESMTPSA id ds22sm795617ejc.186.2021.12.15.05.51.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 15 Dec 2021 05:51:54 -0800 (PST) Message-ID: Date: Wed, 15 Dec 2021 14:51:51 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: logical decoding and replication of sequences Content-Language: en-US To: Amit Kapila Cc: Peter Eisentraut , PostgreSQL Hackers , Petr Jelinek References: <5105c3ad-d726-fc22-1d09-514b6852a15e@enterprisedb.com> <3005299b-267d-8e4a-68a3-abdad3e96aba@enterprisedb.com> <3d6df331-5532-6848-eb45-344b265e0238@enterprisedb.com> <482c10c1-b110-819f-b0e7-17549fa2f0dc@enterprisedb.com> <12a9ecd6-4edb-a367-33da-4e2d03b0aace@enterprisedb.com> <2cd38bab-c874-8e0b-98e7-d9abaaf9806a@enterprisedb.com> <118b249f-e4ef-2faf-8e25-dd25236dc964@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 12/15/21 14:20, Amit Kapila wrote: > On Tue, Dec 14, 2021 at 7:02 AM Tomas Vondra > wrote: >> >> Hi, >> >> here's an updated version of the patches, dealing with almost all of the >> issues (at least in the 0001 and 0002 parts). The main changes: >> >> 1) I've removed the 'created' flag from fill_seq_with_data, as >> discussed. I don't think it's needed by any of the parts (not even 0003, >> AFAICS). We still need it in xl_seq_rec, though. >> >> 2) GetCurrentTransactionId() added to sequence.c are called only with >> wal_level=logical, to minimize the overhead. >> >> >> There's still one remaining problem, that I already explained in [1]. >> The problem is that with this: >> >> BEGIN; >> SELECT nextval('s') FROM generate_series(1,100); >> ROLLBACK; >> >> >> The root cause is that pg_current_wal_lsn() uses the LogwrtResult.Write, >> which is updated by XLogFlush() - but only in RecordTransactionCommit. >> Which makes sense, because only the committed stuff is "visible". >> >> But the non-transactional behavior of sequence decoding disagrees with >> this, because now some of the changes from aborted transactions may be >> replicated. Which means the wait_for_catchup() ends up not waiting for >> the sequence change to be replicated. This is an issue for tests in >> patch 0003, at least. >> >> My concern is this actually affects other places waiting for things >> getting replicated :-/ >> > > By any chance, will this impact synchronous replication as well which > waits for commits to be replicated? > Physical or logical replication? Physical is certainly not replicated. For logical replication, it's more complicated. > How is this patch dealing with prepared transaction case where at > prepare we will send transactional changes and then later if rollback > prepared happens then the publisher will rollback changes related to > new relfilenode but subscriber would have already replayed the updated > seqval change which won't be rolled back? > I'm not sure what exact scenario you are describing, but in general we don't rollback sequence changes anyway, so this should not cause any divergence between the publisher and subscriber. Or are you talking about something like ALTER SEQUENCE? I think that should trigger the transactional behavior for the new relfilenode, so the subscriber won't see that changes. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company