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 1voHyA-000bGh-05 for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Feb 2026 09:17:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1voHy9-002sRK-0R for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Feb 2026 09:17:40 +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 1voHy8-002sRC-2K for pgsql-hackers@lists.postgresql.org; Fri, 06 Feb 2026 09:17:40 +0000 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1voHy6-00000000ohZ-2fpW for pgsql-hackers@lists.postgresql.org; Fri, 06 Feb 2026 09:17:39 +0000 Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-352c5bd2769so1096434a91.1 for ; Fri, 06 Feb 2026 01:17:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1770369457; cv=none; d=google.com; s=arc-20240605; b=MA9g8i4iiACkbUMSDv/3ShRLjvTan96SefNy8GdVmofKrDJ+8xzZHLCpR+RLauItqi 8DPoLBnCyOBvoSqffvzxv1tDs486QKTcSw6O60JitJcCam8aYlQv3JCdOpbbeUZvpJfX zjuLbe7INj+R72iE45BgvITUBHsVlycC6SRogzjQTR/u/h9hoaByeOo6FAxs4TBuoh63 pEasu1qmFyNqyDm2k/BkqD7JmIWAnOERd1C6aMP99Z8YgagJOs7uX8JzRHpaTLCFVfky rk1n8j4+XenAPdciZiMtPhJTUeb26fmc/6ZCWNP8pk1tmZh/AE/+4d1DtOuOADyBXQU1 gEsw== 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=bVPUq8S5U4+aYhwTl07Z3uXaVuYO1k02J9eH+iKHwuU=; fh=r9w9PsUtvtMRJQYuw+d2X3ogW396LTBPq014jPXw08Y=; b=h3yt6C7WlIDS9uoCvW8l9bKDrwEshyagylbLqyqiifKOrVsRtf6LIYH8Z/0EKUde4K +tiCZZ8hTv/v/uqPXhi0QDWPExIm43PngsiCi6eUqOqfsEokZX5w+G6gC4bKFOEzuKhJ U3ulVmbPScUEWSFq3Ah/3EKX7UTHhQOcq3udz/Qi9STUdQptdrAgLgohQRV2MxtJTNuA fnJ6Vibq0qknXt5LjuD1vv2dO7+K+y738XtbqzjPpSDgZ5AN2Qje33btN0RMRFCJhYrZ Z5KflTJ9qAlIUWxWm56cgjDeMpy0NNhnbiM2DZX9QEJ8KSKuEoGSUC7C0MbpFc/EjHkx TORg==; 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=1770369457; x=1770974257; 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=bVPUq8S5U4+aYhwTl07Z3uXaVuYO1k02J9eH+iKHwuU=; b=QQLes8Uq6+klSaiMK6SunWNKwHw7FFoax9uvUDA7iMJPL1tZ37vrPSzcCQ4rOc2C0g Ftl8FOESXphskC+LqlIi6r9sGfoMRSQc4mDPjbRtSb8reabe1kSjzEV5huq1bKdnSCFw keDt6X6J2YHArgWxXV916eHq3HtmTn+V6K93jMeDmtml3bgJ9RMGZNDREdns5k3NcU/Q YjArIzmEyguU5Z16mEAFKVUGs636dTMYFAMMp4QNZftrczQXDU2zkd6X0TdsIc136YKI Qz1e/h/ekm5KRy4NU/QPEwq4stL7YYBWFZ73Gkj9IlS+CnIsQumBDeREEKiyzp+NVjtR QQhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770369457; x=1770974257; 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=bVPUq8S5U4+aYhwTl07Z3uXaVuYO1k02J9eH+iKHwuU=; b=qhVFYk8+M0/MMM+sqAqO252FKR7qvfUJJ8mdCsmSHXaWPPR/e8tNaQ2aoHm3Ap3s18 A/GFfnLZFBm6CqMVLtwfPdBcgoP3G/FOtoFAL0oP9PHqWbxx32g1slE+7U6KVlk43Nxv fp2ZD75d8UF5Nf0IwAx6d6sPrzxfyATQnLPYsFIrVJ7xkYqWfH0cJftZ/PJLJV0E0NRr FgsXkudZUo8TKtTW+Xk1gL9VxBjFrKA8jqUPr4TLpRR3bM70VR8Oy+X2QG1iyVBJd978 r2edwk2DxW0MmTBDOnHwYHSXh9QijQmY7L7mRxq1kZl28TR6hyt5bpcSHwqvkj41eoh4 pKBQ== X-Gm-Message-State: AOJu0Yxlmn6H3prui3160XMbWvDy2V9vAu8CFjkmYp8O1dRTT31JDhvm 3LFORh+wV/yVjpW4e8IhEnAIk1Iq+bysW2PVa7rdgaFWE2+P0W3dlCu+tBws3sfJgsGg4JOf4gl c4VPpVqfFqmDAd6lFInMyAuFzla6HXWc1DvIs X-Gm-Gg: AZuq6aJSFiIlIy5u2WFwqQqNsRPqss0j7DMmhxDIW3y7Cx4Jv1BqPuWWWPI1mzAMhyL bMs9ETbJXK3LMp05MdwDjw1/0YaDBgkKJX/fkQ2NgHU4aYC8/yPP/Hv873K16HJn0n7JlB/D/Wx 9gCrl2Q2leiy4We+9jTtWqRWzvfogFdDERaXw9P23JoGFrOK0Pa3IGOWr2Tm5JUbLmb60IYCY/H csmcVScAm5XTRl8Q0w3ZZGM6hSpa+9kSIfdfARdepx23Ho/DLo5ketT4QkVwPoo/15YkSA0o7BP HWUaaQ3NbeTQEZC0L6nU4zFjs5JoCfEpc38oALQHoSYfIAX49es= X-Received: by 2002:a17:90a:dfc7:b0:33b:be31:8194 with SMTP id 98e67ed59e1d1-354b3e61f78mr1666080a91.34.1770369457341; Fri, 06 Feb 2026 01:17:37 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: shveta malik Date: Fri, 6 Feb 2026 14:47:26 +0530 X-Gm-Features: AZwV_Qj9DLuGVgql_CNyR2cqeZ8TwwQDpU85ZwDw3bG9RtEPICSBFM3ELwahqWY 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 Fri, Feb 6, 2026 at 2:45=E2=80=AFPM shveta malik wrote: > > On Thu, Feb 5, 2026 at 10:33=E2=80=AFAM Ajin Cherian = wrote: > > > > 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 whic= h > > > 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 use= r > > > 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? Correction to last line: There, we could check whether *the current susbcription* has any sequences and, if a worker is not already running,start one. thanks Shveta