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 1mxs9e-00014m-Rh for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Dec 2021 14:54:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mxs9c-0008RR-KO for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Dec 2021 14:54:44 +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 1mxs9b-0008RH-U6 for pgsql-hackers@lists.postgresql.org; Thu, 16 Dec 2021 14:54:44 +0000 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mxs9X-0003Ub-Ob for pgsql-hackers@lists.postgresql.org; Thu, 16 Dec 2021 14:54:43 +0000 Received: by mail-ed1-x535.google.com with SMTP id e3so88940769edu.4 for ; Thu, 16 Dec 2021 06:54:39 -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=Cz9vGCUCVuVYbdJuw12ySKriEt79DrG1CAqgZlZHfEQ=; b=OBohz650VHwwCkvUIMHOwtdsVMniGufVB+ID2yFrYvo4aB32OwKI2cJ5T+56OhVpVy r9XuZO+FMK3xfzDKUu0/FVOlx2rjeL6QA/+ggo1AYj7wNlznBBYdEbr75dImXVfN98nE qQ/ZqIvz5hGZI/a1Gx1W5r+bVKrQemQv8O4d3AZLqbiNwFkl3RRK1I3fG8l9EcuS8tV/ AXFME0Cko6cd3QxSsl74xD4o/MQ3L4JeuDmAApmARSuv3Q0W5knUik14T7s6DKoZRVpC LJw1uT2ZAxpmKuNtN7SxaM7b5+6IycghIC9i5dZz1/RlwyDpQ/K76IvWjzjiL48qlYvW RMow== 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=Cz9vGCUCVuVYbdJuw12ySKriEt79DrG1CAqgZlZHfEQ=; b=HjMseAOcEJgKG6bBb3ZR2Al0/1MvHNBQnAlcD1vehxwls+89xTp0a4DxhXqytlyXok t8UAkg4ewDcrlVoTOGbNrGedtGL2qpA7hpz4SXVHzeuZrEUB8v745C6FVwjDDqa9WNk6 kGon/0UOtSTyQ1BfMz15CiU1FLGT/TjRyOGGsp260Ag5V6IGkIAoOxp/OufcbyTUEBu7 Cniv1lA+kux6g+qFEYJ3UNDxpAvM3Nvb38l4s68zgML+OV/YC3JHqCDJQm8ZMHnl72ku txEUgwUF/teDVzvMAyMG9ZPIkOaOqmXloksMgdly/AMgHCgOVxcDqpvGC5/tJpi1LGvi XCfg== X-Gm-Message-State: AOAM531Qj/+hHlqslVfBWx3Vq+kFtvzUvpGN/aQXW3yg+995gK9CXuOp ZYYc7DtOgvabUB+uhhGmluhb/+QMpmsduFnHB2SpetOs+hSo36P+h3y/Oz0x1uaSC2yQI8j3MCf DPpTkvouBK3YFAm1bFp6upfFcHryHTPLt6WdeA+ExZcHp1/iWE9fycozk/SIjxfk0g+EWQP9I1O q87q1l8zvau2Gi2BjUbZ4+oKxaZrBoay132AsnIGiCKcgG3hDAja24 X-Google-Smtp-Source: ABdhPJzlFcxkGXXvxw3p/GPB45HR1RKrgPKViqlRjBQDm73LyX9KAoVqn1FK+DFZEcQsjxEikLyFRw== X-Received: by 2002:a17:906:58c6:: with SMTP id e6mr16057650ejs.524.1639666478470; Thu, 16 Dec 2021 06:54:38 -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 dz18sm2583323edb.74.2021.12.16.06.54.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 16 Dec 2021 06:54:37 -0800 (PST) Message-ID: <797df1d7-9b35-42c7-4787-4665fcd1252f@enterprisedb.com> Date: Thu, 16 Dec 2021 15:54:30 +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: <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/16/21 12:59, Amit Kapila wrote: > On Wed, Dec 15, 2021 at 7:21 PM 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? >> > > 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. >> > > Yeah, something like Alter Sequence and nextval combination. I see > that it will be handled because of the transactional behavior for the > new relfilenode as for applying each sequence change, a new > relfilenode is created. Right. > I think on apply side, the patch always creates a new relfilenode > irrespective of whether the sequence message is transactional or not. > Do we need to do that for the non-transactional messages as well? > Good question. I don't think that's necessary, I'll see if we can simply update the tuple (mostly just like redo). regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company