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 1wi6n1-0001AA-0M for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Jul 2026 08:40:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wi6mz-00GwlA-0y for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Jul 2026 08:40:54 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wi6mz-00Gwl1-04 for pgsql-hackers@lists.postgresql.org; Fri, 10 Jul 2026 08:40:53 +0000 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wi6my-000000000KC-0Rci for pgsql-hackers@postgresql.org; Fri, 10 Jul 2026 08:40:52 +0000 Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-383cb94f742so596054a91.3 for ; Fri, 10 Jul 2026 01:40:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1783672850; cv=none; d=google.com; s=arc-20260327; b=EIu0hYE9Id6u7SpsKI0gq9pgzbfldfOirDBym/V1evHJit+3I55/2vYXErF/arynnM mFiT6xYA1vXpRqk/rIOahjmQoU58c+7D7L1soZaBqxc8CtLfGexALHnSkE4gtyjs8pqV 3vYycT/vsXicvZ8MEE7pcI/gwBv3CFOQQGS0nU09I6dYTeviURMTJQ8ulSzEDxsoZkeu SzTeFIuzgQEWv722Tz/dCyND9T1LDKDRYHarQ1PvdmYHb5D0lIKNK/4Hxh9KTOs0/fE9 L+ZGmp8BvwvLRzyMtx0SyAT4aYwaQQCaKqnHIDtooqw5bjqJIUN5RM9h7OoyeIQVhUEk acjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=zcH6CAYF0ERK6qWYEZQ7oh2QF/MNoxCli1Zx5ehgjQo=; fh=4i6SFvIGYMW0C+SvxzdOKINCvc6LTdEwX/j3nSGLhsI=; b=QsaNdI6qw0ao12+4zPBvf2BDEeZNZhHewCVNaq1lqhoeuYSArLhpiF6lzcG+4XFKMn sDzWqkuINfAuBr8MBWDfMixqljOxUOxtKvjpnFuOkpYh9Uw7YcUL/ALeZqYFptgLszT+ C56lhDUzBRzV0bATXDLpTYhDoUFby8Xv89u3B3i7oCB/2F9zPzDwHTPsg67ND3QaSPwD UCoRaKGNWSm8rTHM2uLCYIBLl+KoC4TF8sascDDS/goqgCLTcuW9/s067/B8wjCfFFfw Ww4CgrwNe2Ghop/KjRAJqrKMPw6EpQ2kV6zN8G7jS2woX7i0eO4kV9nLoRwp2wd26MC+ ZBig==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783672850; x=1784277650; darn=postgresql.org; h=content-transfer-encoding:content-type:cc:to:subject:message-id :date:from:in-reply-to:references:mime-version:from:to:cc:subject :date:message-id:reply-to:content-type; bh=zcH6CAYF0ERK6qWYEZQ7oh2QF/MNoxCli1Zx5ehgjQo=; b=V75C+TntA2JoZsLHWP7hQXbY9Vo/sjVUM2gbuenQPJXH3Urj/Jr4eacQbiHRlddvg4 LPMkNpE3TOneqj3xJudeoSWOzxgxIWSXtw1xJUvlN5+yAsiSiJhqGtivjpsbmWPp5unp pVaI5zH0PDVWSjGcbw7sWF8VX8Iki+jef7Uk7EudfFhjU/yqen14n/ouaaP3kyjG6Uct HkcajM8bNMVRlNa4GAiJEHPH3uhBPsjBuv4g6++yzxYojG1rVVy8x1GzdeFM/6SA6cxi s/E1znFKbVfd0ACbK4B68GOiUcHQ5jFbZU4pQkJMj0DIWHVIW5S9i6OIRgWYzBOsNYCU QZqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783672850; x=1784277650; h=content-transfer-encoding:content-type:cc:to:subject:message-id :date:from:in-reply-to:references:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=zcH6CAYF0ERK6qWYEZQ7oh2QF/MNoxCli1Zx5ehgjQo=; b=Y02ajmHfEabPyj8Q6ZFmYmUC1B9jTT5G3UYJkcLmZD8PCxymhl6zZmcrGRDNEDdvNU xyZFicdU92l/KEt1OBRQVh3cd6c3/7+4pDix+tM7jbmbaiWWj4GEnoYBlNiRdQDeohu4 L5EfX0/TE5gwbPfSs1fgHOHuf+IVMkW3jUKQjZc1IHGSaTnhdEromW2sIv3qFuOZwkd6 JxGKF6VURSWjWpvscoHaQMR/zDYOoIdx6lt0AE3A1pN5ZI8uE+y1af+kXnrvH2fuSkgr bATno9WCATZCiJmrepGtN69UnHFz7dF976wb7C0oYbj0NcBghLqw7xJVh34VXvA7oP0W fZMg== X-Forwarded-Encrypted: i=1; AHgh+RqofWpEr9cve7f49WwfWaZdVDStSqTrTrWQajFdOSyglXz0mP8nS/zzxhG6GR528QrEcIBFl+isLirKxnvk@postgresql.org X-Gm-Message-State: AOJu0Yz7pwJNmiw75CUE6bPgtz8G6B4kjXXiW9P/yApKx465AQ0mYORT 4wLDixZfZHFeaLZDpAmyBJl78+K0mkIc+ws8ags79UzJ3iV4b9Uckx+2xNAIrQ/78DOJMZXx7gb zc/gdQzfiLIp3RKPEGvbh8P94O1hMfSQ= X-Gm-Gg: AfdE7ckk8Rebb6ajIXv0IFSu4MJbQfcK+2EPuXNqjSN47IzPGaG6snmK6lZK5RXDxt1 3lgxVBGL/0Hyg5j96uxCoGvxt+B3P+mszKcK5J6cEtNJe7rL49OnljIaKG1NjZriMML3nrLfHug 6my7L8OnjR7v2UtMVKoAvGpwSOWzCE6/SN+YjEPglynjQVMn1rQUTw1VUbQV716h7irQEQaJkJM Mqvrt5CxpGb1EHjbMqdtW8Jdl5C3Tq1tCsP3lqmID1I4r/k/q1NnfQev14iJSULmxBz2QXkLpqM Ku8Dv0hM4HjN+g+yQMg8bzAcyGb8Yadpri8I8atZOQQ= X-Received: by 2002:a17:90b:574d:b0:38c:a59b:5189 with SMTP id 98e67ed59e1d1-38ca59b53b4mr3916251a91.15.1783672850320; Fri, 10 Jul 2026 01:40:50 -0700 (PDT) MIME-Version: 1.0 References: <20260710045217.f0.noahmisch@microsoft.com> In-Reply-To: From: shveta malik Date: Fri, 10 Jul 2026 14:10:38 +0530 X-Gm-Features: AVVi8Ceos_CVJooELrdgnLK-BlWsIxWM3qVU0F3bsj2HghNxGcudstOlEJgmMpY Message-ID: Subject: Re: sequencesync worker race with REFRESH SEQUENCES To: vignesh C Cc: Noah Misch , amit.kapila16@gmail.com, pgsql-hackers@postgresql.org, shveta malik Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Jul 10, 2026 at 12:30=E2=80=AFPM vignesh C wr= ote: > > On Fri, 10 Jul 2026 at 10:22, Noah Misch wrote: > > > > A Fable 5 review of logical replication of sequences found a way to get > > subscribed sequences into READY state despite the subscriber side havin= g data > > older than the last REFRESH SEQUENCES. I'm attaching the test case it = wrote. > > I reviewed the test, and I think it identifies a genuine defect. > > Thanks for reporting this. The test case reproduces this issue. This > issue is not limited to lock contention. It can also occur if the > sequence synchronization worker is simply slow. For example, the > worker may fetch the sequence value from the publisher, after which > the publisher sequence advances and ALTER SUBSCRIPTION ... REFRESH > SEQUENCES is executed. When the worker eventually updates the > subscriber, it uses the stale value that it fetched earlier, > overwriting the sequence with an out-of-date value. I have the same opinion here. > How about raising a warning for the second REFRESH SEQUENCES > indicating that the sequence is already being synchronized and > skipping it? The warning could also include a hint to rerun ALTER > SUBSCRIPTION ... REFRESH SEQUENCES after the current synchronization > completes. I agree. This is the simplest solution here. ~~ > Agree the basic approach that we avoid the re-initializing the catalog. > My primitive idea is to follow what slotsync does. SlotSyncCtxStruct::syn= cing is > checked from the SQL function and the slotsync worker, and either of them= can > continue. So we may be able to have LogicalRepCtxStruct::synching_seqs or > something to indicate the status. > But there might be other ways, needs to be investigated. If this approach is accepted, I would prefer implementing it similarly to how ALTER SUBSCRIPTION ... SET (two_phase) is handled. The command simply fails (with an appropriate hint) if the apply worker for the subscription is still running, by checking for the presence of the apply worker. IMO, a mechanism similar to SlotSync is not needed here because there is currently no scenario in which continuous incremental synchronization and one-time manual synchronization can run concurrently. The worker itself is started only by the manual synchronization operation and is not a continuously running process. thanks Shveta