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 1vnDXq-003tMU-35 for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Feb 2026 10:22:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vnDXp-004KPd-1q for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Feb 2026 10:22:05 +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 1vnDXp-004KPU-0K for pgsql-hackers@lists.postgresql.org; Tue, 03 Feb 2026 10:22:04 +0000 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vnDXm-00000000ovG-1siF for pgsql-hackers@lists.postgresql.org; Tue, 03 Feb 2026 10:22:04 +0000 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-81ecbdfdcebso2984739b3a.1 for ; Tue, 03 Feb 2026 02:22:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1770114120; cv=none; d=google.com; s=arc-20240605; b=f7A2v3sVf2EwQGPrd0b+fVme8wFNkltWMRwPqazc81+tGd7VbL0suU3axAO1c8VThj SCrrRowgy86ztc8q83+cSFXoWE+vbyRDpLlMzT57gYHnm460XTOr2MDMYXsl6ScNm4md 4bw0GBaUUkTe8cuslYaeCnV+NWFQh9ymklUSDp8iYB7QWlLjWfS2O6ETrssM3OnHS89x cEcwtk5vTIbt35WLX8n4Prs3NrdTjT5hsHHTYUXEssamWCPXnx+dJuwUo7i6V6FkDgOj 5CRU2jvRlPDvyHYZ8/3yAtbfoPsvQDfeOo7SFNEq1kVfNtUPq2ByuXXv3zrbZYWPvsbI U9dA== 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=ioT0bXj/eNBODKkpD1CthhLx+PogUOnnRmpAfLCEnpc=; fh=r9w9PsUtvtMRJQYuw+d2X3ogW396LTBPq014jPXw08Y=; b=iGZOFKjbb/jNl32ZUCN4z60I7sjW80JRGUGmM1MBvqD/Wu0czXxAPfKw+hJg0y8Bcd lu1kUxBPzbeMZXHtcSBxBZS32l++WJwZyncFKnQkWtHY7vTqupPgaGChvQRpxaykk/ZF o1VOR7iVUDwyUB0YabJ4kaAySNUIH4G/hoiz4lNQK3aC4RmrpR7b616KvZAmKaNMYg7s Da7wNGpk8cWbLT+eZO/AVylAmqPnND2n4DG+jzB/kVOU12ORVkMEtcjHH/jWIwyWBOFE sg9qp1mSuP/QF9lNUF+P0y3ZV2VlPdZAv6Y9bYReRvmINvRyg7c0aZ0yyuZW1MbCTO18 a8QQ==; 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=1770114120; x=1770718920; 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=ioT0bXj/eNBODKkpD1CthhLx+PogUOnnRmpAfLCEnpc=; b=lCTSOBK+McUlGSm0RVE5ShFUDm/AmlEhOXYeiEd3qggGQYGuhnhEiHd1AyFyckhvvR Is+wuTmtSVbjZqDZs27L4QxiuyEurY64z/Z4VOYUFUsHioOwGuc2ZJg5I0nz2gAsV8d0 g5C+r6BZK1CcEz8gWu2WIdH8R5wlsN6qFDsJd3e98jEer7uevLmYpIYgN0jOJ7FUUXU1 JHrI3x1HgjgffQen6bIdK8vw1Q+AM3L7haAL8XGyTLVjzZzovpjQecKLrIcYD7vPyYLy 2BrO/SWc110Lh1WReqjTnKe3uGwAoVHa2c/tm3pH+2lScZqZrILk1JPrlIc3c7l15Dl+ tymw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770114120; x=1770718920; 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=ioT0bXj/eNBODKkpD1CthhLx+PogUOnnRmpAfLCEnpc=; b=sTtGvN3r98fY7uguofaQrHjDnaOpj8NYYB4Wz7Ldn4pJ4I/nTs5SoMEvO3UTWVm08H Y9vVoQMX5BSIi6e4OoPd1mcnpNhWjBYrzse93y+9hSwueGMsORypvCARAFyc8m99p+J9 XRiGzZy73RTzHWA0vOzxW+8dKldpstvvvnb4uoZ2pOiuyPU/6MA/4RSH1DqGLP7YQUCU HBfBBilK98BvvJEf5f4Xl6Hp/SPtFccuHhMzR2bh/FDZ3dsJmlO4/JW+UCPNk4r02hup W4tbFBpswJhpTt/TjAdbJV5NplpZFO/eivCDq9o5ePMOPQUkIu0uyxVqSKPZIjShigxl sCeA== X-Gm-Message-State: AOJu0Yz8IhTnQlDWyEplenGCWUbKDHJgq/sUpmODT6Ww0p5ljFLJEXWI sYqJXHTI0hp/Npo9JHVEPRjw76Ct9hKVlLLNH6VywmKh6x1WXzp6qeeA7uW0b6uFQMzbPoUGSx6 f5zNLv1I9I7bPbWUSaaDHo5Xhu8/IqIvZUA== X-Gm-Gg: AZuq6aKPa5OaxT35U+kcmTDWed3RWd6uU0RQvDT4M6XT/KHpsHOaNkioEGHv9TEvtpb I0LGLjjr4aRf0Vy2yl6De8Q07D0USYJs4NX0qgHyUPHsqkPcLHskC3QZTdXEJBos99GdGm1/97j naK+6c++d7Wgr1jYpT7RapbMSz4oU3X18WnRbL99WRxQgDaZgazyctztcYih2uBBjShhQWEM2hc kHBOLbgv3L/LuBEdUUO7MZrbHRm467Qz0GhN9L+LyIyHakW4Jc7/NCMBsCd9hjX9O9jWF7ud/y0 pYnDDsB2866ezfyGDjz2Zd7lysBtJdwjuS+DhlhX8UUvD7/kmdlag0YJMmB7SoGebY0NLfSW X-Received: by 2002:a05:6a20:e196:b0:366:1de8:62dc with SMTP id adf61e73a8af0-392dffe059bmr14018072637.8.1770114120459; Tue, 03 Feb 2026 02:22:00 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: shveta malik Date: Tue, 3 Feb 2026 15:51:48 +0530 X-Gm-Features: AZwV_QjRhzKt5188bywxJfUZxkQnhPmvGFJYPOODCpjfkmBQwYlLFbgsEhJ2AA4 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 Tue, Feb 3, 2026 at 9:18=E2=80=AFAM Ajin Cherian wro= te: > > Hello hackers, > > I'd like to propose an improvement to the sequence replication feature > that was committed in [1]. > > The current implementation synchronizes sequences during initial > subscription setup, but the sequence sync worker exits after this > initial sync. This means that as sequences advance on the publisher, > they drift from the subscriber values over time. Users must manually > run ALTER SUBSCRIPTION ... REFRESH SEQUENCES to resynchronize, which > requires monitoring and intervention. > > Proposed Enhancement: > > This patch changes the sequence sync worker to run continuously > throughout the subscription lifetime, automatically detecting and > correcting sequence drift. The key changes are: > > 1. The sequence sync worker remains running instead of exiting after > initial sync, periodically checking for and synchronizing drifted > sequences. > > 2. The worker uses an exponential backoff strategy - starting at 2 > seconds, doubling up to a maximum of 30 seconds when sequences are in > sync, and resetting to the minimum interval when drift is detected. > > 3. Since synchronization is now automatic, ALTER SUBSCRIPTION ... > REFRESH SEQUENCES is no longer needed and has been removed. > > The patch modifies documentation to reflect the new behavior, removes > the REFRESH SEQUENCES command from the grammar and subscription > commands, and implements the continuous monitoring loop in > sequencesync.c. Tap tests have been updated to verify automatic > synchronization rather than manual refresh. > > The attached v2 patch is attached and ready for review. > > Thoughts and feedback are welcome! > > [1] - https://github.com/postgres/postgres/commit/5509055d6956745532e65ab= 218e15b99d87d66ce > 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). 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. 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" 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" 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? thanks Shveta