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 1voHwM-000ad2-2G for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Feb 2026 09:15:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1voHwL-002qQ6-2I for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Feb 2026 09:15:49 +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 1voHwL-002qPy-1B for pgsql-hackers@lists.postgresql.org; Fri, 06 Feb 2026 09:15:49 +0000 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1voHwI-00000001KsQ-35lE for pgsql-hackers@lists.postgresql.org; Fri, 06 Feb 2026 09:15:48 +0000 Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-34c93e0269cso1871420a91.1 for ; Fri, 06 Feb 2026 01:15:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1770369344; cv=none; d=google.com; s=arc-20240605; b=TtWQzAWlFKFL9tRwhuPGoi7+lhwrcOkGu8YIaAIzOyj3DdTznkzOSNN2faqrbw5NVD cfjAeLz6ncFuv505sCZT6q7w259UtkQt1Hh2T3LafivaXLdZxUY4g1yh+vfn2H5H0Rx8 CA+V4ErwArOT9a0Qp0iuiqBC5DaHgLSZVLarANg3binnfRXpm6mC+e00xXZBt1wR50Gf Y+vGZbJKcVeO2wQeqDykTPUx87yo5QlnI18so4N6VJ21Q6FzizDvYR2IocNmZIPQ5Ozq OOVMmGAL6Trly4TDu/YtGlr1fk4JgjJYDkCGK/5pgpNH7M1QqziwHxjOfgQWjNUWjwBL b0aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Kzo3x/8ZzPJE80dh+TTo4yGXjbP545EnS9jWo8y7tz4=; fh=r9w9PsUtvtMRJQYuw+d2X3ogW396LTBPq014jPXw08Y=; b=NKKL/mEeSfAhqcgEo+rRXnDgZsGC30KdgXzwahUnT1hNxmO7rCB84z9hN8ChQwLA+X 1dcgvRDSTMo3UGbGRX09SgvjmZuRoKh6LP9W5lHTS4nPr5/3axq93HVOL4b9cJya/TdX QYG9WFquKqK/nJqb8ucLX5yHiBmskOIVr0HI80rViSIDk6q6YfsIJpB8uzhbpwVo23Ob MqeVp8W18g8/XB03/yEyc1o+/CjgyNNsqAOokbWe06b+3sk/eq10vJeJ1xuoJqjCDp2V uHCqEOjLfqNn4Qm/8WGPZW7Y5gJx12xUb76/Nq845A81WMalbJLY0kU5zcGIu2ES9z+B vZXw==; darn=lists.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=20230601; t=1770369344; x=1770974144; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Kzo3x/8ZzPJE80dh+TTo4yGXjbP545EnS9jWo8y7tz4=; b=Kg9zxtg/+DfTM49z1FN9imn3lekgW3q4+sUDLxVmRz6InAhnYoy3afLFgQuYBmWvpc DKjjGU0AXniTIoDI0wfgpMSS8rO+5bSVDCnmDqMl5Uy06cBpTGR2D81y18otK7et1ROW aWLuFUKMtaB4vsndCDkYPE17NA/bxtdICLJBeasZXXsW3RUEKuWBBCp4g9/nYoQbpXSx zGAkyZEYErPJZnD8trCV7DxUaDVfgBKRLq57fpuqPYsm1XXaNq+6hhRON2bNnZ3Q/q3p S9tS0XOwgppo0f8V7CC/gkaRBn6dUSknm7OTg7U6c+dvn8oo407BId+XkatSc1kXBIr1 pFHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770369344; x=1770974144; h=content-transfer-encoding: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; bh=Kzo3x/8ZzPJE80dh+TTo4yGXjbP545EnS9jWo8y7tz4=; b=ElAPCx+a4PxFqqcXj96TWXtdYnWvBX7JgePlf8rG6DxtWYUbwQ6C8p3r6UO56CsIjz jsB1Fe4Zqvd1s32X7cVwlKEafOLsO4/yLkdYt1qkiK5w+wXEYkzDa5N2q6ZVyA8Na4X3 D7uAy/JeA8gSlN3up1FHhMfjJXdHk/DVAO/OENdEZyQokbcSDsbo7BwrM8oWdCTGFhwb 6yHLnKLUx1Qz7GzfGzrY/3k4cWkO5eIcuMXSuHRYEiKpQ+9t11usuZY9OPPzpzTHxKqp DiDTO/L5IX5rQRdSlq36+R5ZEQNUApiKPs0uw4UMjcHG6nAgw9LVPnvvp4ewILw+ADxV msBw== X-Gm-Message-State: AOJu0Yzi3bsmDLDzW3ouAasfHDbGyGRXktmktf06IsM7aKXnB5wO+M7w 8+gSZCv9tw/P4yCUaBJfygtDvNhaVcxTvzRRAdom21AxnGq6++2H5wg9JPZuHek+WWVWxdhy6hG D1jFysdOqSKUo4CnEJ3IkEIBmbOviNhw= X-Gm-Gg: AZuq6aIN2RU1tZG5M3BDS8yM5v80wr47rX6rSaoKVgOdXWe7ltKNI4vbr1MShbw1nQ6 smlRrH1G7GS55QR5KZyePrhGjD7Bmt2RatUjt6jTpnFT/A8TyNxOvmHGWMv9dcxh4/IdDh/ec3K 8ftJF+h/d6DFb7n1IWpf7v/U9sViAh6DRWWY3dz4rfIMjlRtFBIoTcZ5tjKefVQQdZMdTlOVzXS ewd4Krav9XyQPIwr52UOXvMv5agFTHaXSgA8kpIl+dV1jnf/zoLq/D6U++pGxlXYIKNNkrLi2C6 5U/un+iikBBxaaNvKXjQNmGwC0LlCDjZUZVsU6w= X-Received: by 2002:a17:90b:4b8a:b0:354:7e46:4a8e with SMTP id 98e67ed59e1d1-354b2f8d096mr1731295a91.7.1770369344217; Fri, 06 Feb 2026 01:15:44 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: shveta malik Date: Fri, 6 Feb 2026 14:45:32 +0530 X-Gm-Features: AZwV_Qhwafa8jxGtQIkREamPdCjS9Q937xOC37YsKukq2y9tDGLKJhewxg25W60 Message-ID: Subject: Re: [PATCH] Support automatic sequence replication To: Ajin Cherian Cc: PostgreSQL Hackers , 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 Thu, Feb 5, 2026 at 10:33=E2=80=AFAM Ajin Cherian wr= ote: > > On Tue, Feb 3, 2026 at 9:22=E2=80=AFPM shveta malik wrote: > > > > On Tue, Feb 3, 2026 at 9:18=E2=80=AFAM Ajin Cherian = wrote: > > Thanks for the patch. > > > > +1 for the overall idea of patch that once a subscription is created > > which subscribes to sequences, a sequence sync worker is started which > > continuously syncs the sequences. This makes usage of REFRESH > > SEQUENCES redundant and thus it is removed. I am still reviewing the > > design choice here, and will post my comments soon (if any). > > > > Thanks! > > > By quick validation, few issues in current implementation: > > > > 1) > > If the sequence sync worker exits due to some issue (or killed or > > server restarts), sequence-sync worker is not started again by apply > > worker unless there is a sequence in INIT state i.e. synchronization > > of sequences in READY state stops. IIUC, the logic of > > ProcessSequencesForSync() needs to change to start seq sync worker > > irrespective of state of sequences. > > > > Yes, I fixed this. I've changed FetchRelationStates to fetch sequences > in ANY state and not just ones in NON READY state. > > > 2) > > There is some issue in how LOGs (DEBUGs) are getting generated. > > > > a) Even if there is no drift, it still keeps on dumping: > > "logical replication sequence synchronization for subscription "sub1" > > - total unsynchronized: 3" > > > > Removed this. > > > b) > > When there is a drift in say single sequence, it puts rest (which are > > in sync) to "missing" section: > > "logical replication sequence synchronization for subscription "sub1" > > - batch #1 =3D 3 attempted, 1 succeeded, 0 mismatched, 0 insufficient > > permission, 2 missing from publisher, 0 skipped" > > > > Fixed, and added a new section called "no drift". Also now this debug > message is printed every time the worker attempts to synchronize > sequences. also mentioning the state of the sequences being synced. > > > 3) > > If a sequence sync worker is taking a nap, and subscription is > > disabled or the server is stopped just before upgrade, how is the user > > supposed to know that sequences are synced at the end? > > Well, one way is to wait for a debug message that says that all the > attempted sequences are in the "no drift" state. Also remote > sequence's LSN is updated in pg_subscription_rel for each sequence. > Let me know if you have anything more in mind. One option is to leave > the ALTER SUBSCRIPTION..REFRESH SEQUENCE in place, that will change > the state of all the sequences to the INIT state, and the user can > then wait for the sequences to change state to READY. I think this point needs more analysis. I am analyzing and discussing it further. > Attaching patch v3 addressing the above comments. > Thank You for the patch. I haven=E2=80=99t reviewed the details yet, but it would be good to evaluate whether we really need to start the sequence sync worker so deep inside the apply worker. Currently, the caller of ProcessSequencesForSync(), namely ProcessSyncingRelations() is invoked for every apply message to process possible state-changes of relation and start worker (tablesync/sequence-sync etc). Since monitoring state-change behavior is no longer required for sequences, should we consider moving this logic to the main loop of the apply worker, possibly within LogicalRepApplyLoop()? There, we could check whether the table has any sequences and, if a worker is not already running, start one. Thoughts? thanks Shveta