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 1mxUnx-000164-FC for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Dec 2021 13:58:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mxUnw-0002gK-1n for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Dec 2021 13:58:48 +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 1mxUnv-0002gA-FW for pgsql-hackers@lists.postgresql.org; Wed, 15 Dec 2021 13:58:47 +0000 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mxUnr-0007fC-Cv for pgsql-hackers@lists.postgresql.org; Wed, 15 Dec 2021 13:58:46 +0000 Received: by mail-ed1-x52b.google.com with SMTP id o20so75484786eds.10 for ; Wed, 15 Dec 2021 05:58:42 -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 :from:to:cc:references:in-reply-to:content-transfer-encoding; bh=JC/8rT7MF1AGBdBQKmGJGCGlsAE21D5RUzeHspk07I4=; b=LL0v/aCdMZ68YkhjjFoO6UaF1NLpW7FfhBq6vz8CtMjB0EmaVH++JAoHW31mf69xy1 32sfUakvWmqp6iMhWVhjaSLpfoB+HQVuzopTw54pzT987nnlPhjPN98DfToPITLA/WsP QjXy/Ft6h9ll/8ktoD9HjoqV9QsdRvTisFNFhd+LGRVpWF3Nr0LWAfcMOHUJVbEX6QBL /Nad8IxjhIAfvnGVPRsyQJs4zn/JuuxPPVFrOiZKw6Sa0Ka8lCyNrlo0xJ75XFXzV6b5 GZlt2ZTc6LHk0kx9hobG65SexiVKJ740AfIQMfwMi9+j5OaXHo1ldOiB33G863EAuXh6 L5Sg== 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:from:to:cc:references:in-reply-to :content-transfer-encoding; bh=JC/8rT7MF1AGBdBQKmGJGCGlsAE21D5RUzeHspk07I4=; b=Q6MHLEevh8PVGnaa070sGIRABLzFiJ+hcN2b1iU/+EpR1naQUXIR/20H6CChtzal0I M5vytwnikikq/6UgDLBMB8eW2qBMsgVtX1yI6K4+tnYPkGSM3nwvvIjWsAbYB0uTDqty 9AgpuxGmrQDib/CMf1m7TR0X/cfTT5x+qAyOvztvEgtcZYgIu+P/2Uxf1Ogp8nIZZ3W9 crl8Ya8aN8tsnpgLrab14fOXfNt8Bv7viurL1DLsdhDT0IWPSBP1h9W7vyWzRPQGSEWI EmD0aDJ6RyumaEbd7s4UKJO/u5SwJ1sXWpUnFYMGYKlB/3SuT57I01AYUIJavU9Q6s+1 PPjw== X-Gm-Message-State: AOAM532LM5GcLvC4yAP8lDxpi7DbVeAB89o9u7NR5v4qIqfmb0ez181p sNSjlxXJchn+So5wB60MRChjFHwO5cV8bTURg+swH2siEuHRVOET/ohnZ7ckgzDT4BBm3+2OfRL s1N/CrLujQV7d/m3P5d8gN2238XyU/YvanHucoFFK/sUA/ZEknokMBVU5QJP3y+CtL9nlzwqAvg C0S6VbGG+yYnMiv/xGxu+TsjuOXou8yi4teaVQNBmYyayD1GwJ8dpT X-Google-Smtp-Source: ABdhPJxhrHBezqe1VoBOj9Blon5xjlmpDO5PxJVrgwoEQTA2yRJTmVThWC3fRPIdIV3Q8l6qktSdeg== X-Received: by 2002:aa7:d997:: with SMTP id u23mr14918437eds.164.1639576721841; Wed, 15 Dec 2021 05:58:41 -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 l14sm45633ejo.218.2021.12.15.05.58.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 15 Dec 2021 05:58:41 -0800 (PST) Message-ID: Date: Wed, 15 Dec 2021 14:58:39 +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 From: Tomas Vondra To: Amit Kapila Cc: Peter Eisentraut , PostgreSQL Hackers , Petr Jelinek References: <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> 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:51, Tomas Vondra wrote: > 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. > Apologies, sent too early ... I think it's more complicated for logical sync replication, because of a scenario like this: BEGIN; SELECT nextval('s') FROM generate_series(1,100); <-- writes WAL ROLLBACK; SELECT nextval('s'); The first transaction advances the sequence enough to generate a WAL, which we do every 32 values. But it's rolled back, so it does not update LogwrtResult.Write, because that happens only at commit. And then the nextval() generates a value from the sequence without generating WAL, so it doesn't update the LSN either (IIRC). That'd mean a sync replication may not wait for this change to reach the subscriber. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company