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 1mpVyJ-0002om-Fo for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Nov 2021 13:36:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mpVyI-0001q8-7o for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Nov 2021 13:36:30 +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 1mpVyH-0001pz-Hy for pgsql-hackers@lists.postgresql.org; Tue, 23 Nov 2021 13:36:29 +0000 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mpVy9-0003cW-Vx for pgsql-hackers@lists.postgresql.org; Tue, 23 Nov 2021 13:36:28 +0000 Received: by mail-ed1-x529.google.com with SMTP id v1so58551961edx.2 for ; Tue, 23 Nov 2021 05:36:21 -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=RNNpv3rAzOfi0QQAdZvjGyZxw8lGZU+CligtturGhis=; b=YjaTo8MPH//6i5a93StWVrI4Aq1W4Im3HYXEv3X9REjRwxpJCEaSNMU48sF8uW/KYA PmPSHY/jXCap5tG8eQHyOgERn5tbBJWZ0kENZCPPpqi0ybEeSKU6SXwnxTeKaXZTCJeY DGvJFQJlDmw+591mmYLah1ytrd1A7yPGfUzeMwZTBUNydNzPs46CcqptErhdXLbsRCkm fc1hBkbpUHUIEe7E6jYTLldYsiopREEOi1q3D9C4kvZpHFoBNvEJZn/f1PpLPsjdywmO 24iyoqiK3s51969oXq0s0kWyfGMbyTgSIWO3ict0oSuKW+LApnl4bKZazxC6TDR4AEmS I61Q== 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=RNNpv3rAzOfi0QQAdZvjGyZxw8lGZU+CligtturGhis=; b=6907nYKbkHKAr0Y6aeVQEJs7IosNrbcTZOXixLug7wUV+kIfApZoie3X1g8KjvDGzu 2Jv5pLt2QrD/NVkP9OOEJuR51gGDvMa4iRnq6DwdYz4cfd4h89H/Ea08jz/27ZAaDDCG /15Yfu2hBz2baxHQLDABu2Fhvp2EXTP5DFfevzIbX9H300ym4a5DuWEV1CLksPa0RTpb CueFD0WmpmSYqML0ienHHlPjMclZozfELvY97O55aAA0LMwTENRWvgd9f1Gs076G22Bx RsH1ySyKs+Uc2HMVhVra1cxeLZn3p00HlKFCYee393CmBwfbMPD7YLFzrNYM/7rNedET pSpQ== X-Gm-Message-State: AOAM530uYX1+TNcVXeRSjCpvdmUhtBbhi1tf4xd2zB4j/rxa+j6VpSn2 Qx5eFffJguJEaio6m2NRpnLvl4EXEjYOjNmDj19kdvjhPZCpK9WUTYoMsoh0OArB9T8TGA9qivl wWHZspuHTJt7l5woOZ1V4t9yuIrydSnogr/lDy0gTRA+O10P9LHL6fIlCsZGfLqs5anc3iYs4XS N6ktjkwrjufZ+R39QKhRiq4uOvSaajU4rJEzJl8kI+EC5pGyIO5Q/7 X-Google-Smtp-Source: ABdhPJx4fVDpf2dYMiwHvVLhpPIuiqZEUGuHf/oiTbD5gvgjJesYAFAaC9oUyRvwzddsI8CyPeE28Q== X-Received: by 2002:a17:906:7310:: with SMTP id di16mr7492175ejc.92.1637674579879; Tue, 23 Nov 2021 05:36:19 -0800 (PST) Received: from [10.137.0.18] (ip-86-49-251-104.net.upcbroadband.cz. [86.49.251.104]) by smtp.gmail.com with ESMTPSA id qb21sm5314833ejc.78.2021.11.23.05.36.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Nov 2021 05:36:19 -0800 (PST) Message-ID: <5de939c3-830e-59fd-5280-b8c52a1ad410@enterprisedb.com> Date: Tue, 23 Nov 2021 14:36:17 +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: Andres Freund , Hannu Krosing Cc: Peter Eisentraut , vignesh C , PostgreSQL Hackers , Petr Jelinek References: <377c6fda-c3eb-7a69-e981-c77ae459c5db@enterprisedb.com> <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> <20211123010114.5jdp35p7p5cuzwsl@alap3.anarazel.de> From: Tomas Vondra In-Reply-To: <20211123010114.5jdp35p7p5cuzwsl@alap3.anarazel.de> Content-Type: text/plain; charset=UTF-8; format=flowed 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 11/23/21 02:01, Andres Freund wrote: > Hi, > > On 2021-09-25 22:05:43 +0200, Hannu Krosing wrote: >> If our aim is just to make sure that all user-visible data in >> *transactional* tables is consistent with sequence state then one >> very much simplified approach to this could be to track the results of >> nextval() calls in a transaction at COMMIT put the latest sequence >> value in WAL (or just track the sequences affected and put the latest >> sequence state in WAL at commit which needs extra read of sequence but >> protects against race conditions with parallel transactions which get >> rolled back later) > > I think this is a bad idea. It's architecturally more complicated and prevents > use cases because sequence values aren't guaranteed to be as new as on the > original system. You'd need to track all sequence use somehow *even if there > is no relevant WAL generated* in a transaction. There's simply no evidence of > sequence use in a transaction if that transaction uses a previously logged > sequence value. > Not quite. We already have a cache of all sequences used by a session (see seqhashtab in sequence.c), and it's not that hard to extend it to per-transaction tracking. That's what the last two versions do, mostly. But there are various issues with that approach, described in my last message(s). regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company