Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wjyDi-000ObX-1a for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Jul 2026 11:56:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wjyDh-007AMO-0y for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Jul 2026 11:56:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wjyDg-007AME-2a for pgsql-hackers@lists.postgresql.org; Wed, 15 Jul 2026 11:56:09 +0000 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wjyDe-00000000NO2-0J4r for pgsql-hackers@postgresql.org; Wed, 15 Jul 2026 11:56:08 +0000 Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-383b4a3755fso1896156a91.3 for ; Wed, 15 Jul 2026 04:56:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1784116564; x=1784721364; darn=postgresql.org; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:content-type:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=diOskWWFh4ZDWRi+K1/W58bDtL7CILx64p+UP/jaEgQ=; b=U0gQMZPJwtpalsnE1T4ShM45ELPVMtqgrDmRElgQhlSoP1DHNtN366UZZMc7LK9Mfh ihgLL8aThJK0aDNODYjQlFUS2QtTuSprcKhi1v0N72VFDj64uMJHg/CgRb7vVjhYp4LQ iojVnUwxa2A35XmcpWMFnRoV9647ez2kyBxJY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784116564; x=1784721364; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:content-type:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=diOskWWFh4ZDWRi+K1/W58bDtL7CILx64p+UP/jaEgQ=; b=n6BGux8+YBUw4P3RCMf+X88eWKe4GZwlRviDUDPYbb4mr4D0s45QqQJXCXHmHvyu4p 7sZV9xh2aEdFZ6fX3VLm0rkvWJ+MaziZMeicqKzAbvBcAS9nbckMqySF2EUxrU6WR/PL Rl1aErakVz47K9xRovBdRx16kMY1lLxEqm/hnGCTeJpNnrsPguBAQJzC5Lwrofuf5od0 bfcn3uU/1ZEIH54CaW/ko+fPTORvp0+nXch82RVXXKUnchk36YJGqWBt5k6Q3KYQOM6r DLJTlPKpdOE3pAt/nImhj5EGvV7AysCU+vYwnJeZwoFlngDO6QIR1LX7zqLiCK2W/RYT ppkw== X-Forwarded-Encrypted: i=1; AHgh+Ro0BBxURbu3GXhR4bLgwpL2crqat9eEiA7gepl6CBHIxJ/C74KVMeOX+qaVowYc4uQ1802YkeLDMjwhAslL@postgresql.org X-Gm-Message-State: AOJu0YzngeVy++DObfHZlEyrXpBtQqDoXVWK9VctBARKzQcJUtIbSb54 dGKoimZNrTz2rZpEs+DSao+OgvaSDjAb6BzbxM/4UnH5vhgFLCLwn1ECeGDNcYgPqw== X-Gm-Gg: AfdE7ckNx04tNm4xsFqXfRPtPS6RWbT5hzfGYCezsnoZa2oYn5Hg8BI4BX7wZsT5esW aJXYZoWEKcnX6thjp4trqyA0h9n9KdPcIALe3ZcxjxAV5dC76+ndnZNPUI6zMmf7Eie8yiTtmwC x9LNcAoFW2SUub9/C9PNZlLE39+sBdRkEb0uiUrKKLihDt/9fb6Fc8xKdNUYZyMCW3HhPuPuAfs /OCFR7THtLi9QQl6UKAWnqnFJWXj7QzcHWPvqTEkof6Xi2M8ck+jJXjMekIcPGc+8yk0LOQTfrv w/NnyIBYYDE6sPttsqHrJadPF1jDvMkRm1mMKUg5BLRJrjK+r353hgq6MawmJ9KaQPbo+hI+zhr OAPxIB5X08RwmPjYZKsL27dDx3kyb/0w2de3DmQFH5bMsVFycqFYTryA/cg7tf7ClPWoIeFRtS7 Fvzee5nwrImDhi6GnEQFJsatPpjou6TXDk1xWzGZqkXUgp X-Received: by 2002:a05:6a21:7782:b0:3c3:6528:c87 with SMTP id adf61e73a8af0-3c365280cc4mr3335561637.1.1784116563750; Wed, 15 Jul 2026 04:56:03 -0700 (PDT) Received: from microsoft.com (c-73-15-160-255.hsd1.ca.comcast.net. [73.15.160.255]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13cd4359166sm702274c88.14.2026.07.15.04.56.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Jul 2026 04:56:03 -0700 (PDT) Date: Wed, 15 Jul 2026 04:56:01 -0700 From: Noah Misch To: Amit Kapila Cc: vignesh21@gmail.com, pgsql-hackers@postgresql.org Subject: Re: sequencesync worker race with REFRESH SEQUENCES Message-ID: <20260715115601.fd.noahmisch@microsoft.com> References: <20260710045217.f0.noahmisch@microsoft.com> <20260715025809.cd.noahmisch@microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/2.3.0 (2026-01-25) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Jul 15, 2026 at 05:23:05PM +0530, Amit Kapila wrote: > On Wed, Jul 15, 2026 at 8:28 AM Noah Misch wrote: > > On Mon, Jul 13, 2026 at 03:37:54PM +0530, Amit Kapila wrote: > > > On Fri, Jul 10, 2026 at 10:22 AM Noah Misch wrote: > > > > Fable 5 also wrote a lot more that neither it nor I confirmed by test case > > > > construction. I'm attaching the report; feel free to disregard. Finding-2 > > > > about default_transaction_read_only=on looks worth fixing if true, > > > > > > Agreed on Finding-2 as well. The issue is that the sequencesync > > > worker sets the value via SetSequence(), which calls > > > PreventCommandIfReadOnly("setval()") for non-temp sequences, so with > > > "default_transaction_read_only=on" on the subscriber the worker's > > > transaction is read-only and sequence sync fails and never reaches > > > READY. Table apply is unaffected only because > > > ExecSimpleRelationInsert() bypasses the executor's > > > ExecCheckXactReadOnly() path which is an undocumented, untested detail > > > rather than a stated guarantee. > > > > > > For a minimal backpatch, we can force the sequencesync worker to run > > > read-write (e.g. set default_transaction_read_only=off for its session > > > at startup) so it matches table apply, plus a test that sets the GUC > > > on the subscriber and verifies sequences reach READY. Separately, it's > > > worth documenting that logical replication apply is exempt from > > > default_transaction_read_only — it's a per-transaction default meant > > > to guard user writes and never makes the node physically read-only — > > > and making that exemption explicit for all logical replication workers > > > so tables no longer rely on the bypass. What do you think? > > > > I wouldn't document those things. default_transaction_read_only just has the > > user write "BEGIN READ WRITE" instead of plain "BEGIN". Hence, it's more like > > an "are you sure?" prompt than a restrictive guard. It's no surprise that > > logical replication apply achieves the equivalent of BEGIN READ WRITE; I don't > > see that outcome as an exemption. > > > > If easy, I would have the worker do the C equivalent of "BEGIN READ WRITE" > > instead of actually changing the GUC. That makes it clear exactly which areas > > are overriding the default. But changing the GUC is fine. > > Fair enough. I think this means we need to set XactReadOnly as false > each time after StartTransactionCommand() (where required) as we are > doing in snapbuild.c. There seems to be multiple places and some care > is required unless we want to do it each time after > StartTransactionCommand(). So, I prefer the GUC approach In that case, changing the GUC works for me.