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 1vsJ9J-00Fo6a-0j for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Feb 2026 11:21:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vsJ9H-009rZU-2p for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Feb 2026 11:21:48 +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 1vsJ9H-009rZ4-1M for pgsql-hackers@lists.postgresql.org; Tue, 17 Feb 2026 11:21:47 +0000 Received: from mail-dl1-x122c.google.com ([2607:f8b0:4864:20::122c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vsJ9D-0000000130B-1mk3 for pgsql-hackers@lists.postgresql.org; Tue, 17 Feb 2026 11:21:46 +0000 Received: by mail-dl1-x122c.google.com with SMTP id a92af1059eb24-124a635476fso4482061c88.0 for ; Tue, 17 Feb 2026 03:21:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1771327303; cv=none; d=google.com; s=arc-20240605; b=Zk00S2JgpQ9vZcg2FxGJjfiCgODXCM7BYCce5j5NDMfCbBzmwst+NTngh6DefZ0/jT 80hn5sug2asRzMolcq/9FT7Ev2CiuMZeq/B5vBKLqb1Wij8R5SVr4+1GWbfcsU8mEhP7 pvc5cohgnp+Nn9834tc4feEwq9eVoQMrZrw5hWZgaxielv3RdvtbfkxLLO5KqQf7Wp5B gfFrQk32V44LciYa1crtqzL9ZHkzlCPeZEMXA5YKgDWV9JpmjRHFFtobXCe7CMpIwNc6 L7ybj05BMAPnHRYneD9OnqNA6o4g60WyfyaVq1fK2boM4QJjVNhzrr1WF+x+4eX0RW1P Zvnw== 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=ePGdf2RiS5Oxj+yR67i1WD8mgRJPl8gl7RUN/u2E96s=; fh=MZMHq5bGBShKGSDtRDx0/+DwFmw5sfBHkZmQLfP8ERs=; b=CafG2cevolGQ3+ccbmmECw/WLWP92ggs066xOxLw2DjO/pMSLVUn93HwsF0crqNWqs Vs4cfZmxa7NvjwBslJqhpOEjJpY0d2yC9A1Pyv4QnqUaGbz8sh/UbzV+YgsE+VssPRRs H4INFqlgehTFH3AcYfdPpIsB3eYVeC0te/ECiUrh7tfHhbCdVgdPP4+zl1+qvA2nvvsD PAm3dLmJKuPm3dpAwsb3HoxmAGgbEce+yMASwYcf9ijxIrcrB2xRCjrrkajIUlrIo9Eb +/YJZsFwpmniWHZmLgZ8wu8Q1bhor0FeVEJSDEVTazRCzaEUhwt+s1UtLbia/6eiAUHK UWwQ==; 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=1771327303; x=1771932103; 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=ePGdf2RiS5Oxj+yR67i1WD8mgRJPl8gl7RUN/u2E96s=; b=LFjRp6DCrUp+kmAMu5O9jlPzPWtp5JpYEfb8KkIAx2A6XEs1u+cpwmBOXKCGx2evkn hozCw2rK+J4TqUSTXBsx96CykZ1KG5G0NLlHKLh1fhkpqxdgk7+WkyH0qSoVSYQJJHX+ PFwSew4Trklsvw4MyHdx31xMSOvKQYTtLh1qOnm6A/wyOQWhwTIfZ+5uwSjoZjpzWuX8 IaCaj0pI6NprRxXUaEb7IPpx+54+7xRFsjT+QZFPy2x7MbFjuA2JVH19t4+V8DUALwDg HknDGJLIx3X5fsxDmATs0fsuBCxrrx4i63jNKE2eL2P9ly0fnastlxetwqGHX4RZRXgw 5zCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771327303; x=1771932103; 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=ePGdf2RiS5Oxj+yR67i1WD8mgRJPl8gl7RUN/u2E96s=; b=rFW5j4rToTHMbabLCJ8ZczfuI0QWj4f314b2Da//Y4gqVt6tsGew+lb9SS6BnT29tO QLSidE8Ifqij/SBXCaGyoNLffAd8E2iwom6vNYGnTVmI8UkhRwXUpyLI97crShMUgK0Y 7RBgBuYow6L4GxPPK7TXQbchO15coNBct24u8WFOOFjtCHFChuLC/01TS17v8kVwmppG df24jly1G5YPqWhv0iy2rMVbKL5Bgnq6P/M1WZDD0dr2Apkvm/tJodYXQeqliybn3F9R ksVElFi8gKi6N/lcw327H41wvhA+r2DZPYW7uc4sTtvrOK+G8bUsG2H8pMdoikd7NeFw ZQCg== X-Forwarded-Encrypted: i=1; AJvYcCWlC+cdUJWTN7JTQ42O2Dq5Xxo+gyuk7f545ComVQm0es1534rf58QOr3sA2QTWVGYQfp7wTvw2Ttxp/0JG@lists.postgresql.org X-Gm-Message-State: AOJu0Ywl5HYQlVGNy1P80K+v0aEe4gRvWrMm+TKW0Px1OhSlLkvF+7po +I2YGDaHMg+O5ykplU0iMeCNSDH5nvcmcKrJbLW7uyk/wl2GkaWJolKkHfolqkovKhBxp8tLhhW unM00H3srGyXVyfPD6wnqq80ZWnFzNmNKBCfGKRk= X-Gm-Gg: AZuq6aJ9eunEu+yt/bTGiqMT0KbNkotNTp00lpMa4/jPm3Ohyba/auVQ+Ziw21IziGU IRIwWvQ/cjy5oQ3iaCFe7jFN+INtevVAd3D8pwu1crY1n/uxHgHUFyVLHa27iDZEq9IP3AThGnJ jC6kt2bP/nRj1WI6UV4RUHz6iS+SeH325UXrUdzPE6mXNoj010tBdxdGEwS7ylc7sN7O8G2eHAq puDEq8XlN5fmVtmX9FvEF2pb8w9eCu8rgapWTWqFZNqTUQ75YLQaheHy8LGXKrvXpA+wIJMpPku nS/nphQ+KfINc4eH/mJ9Y3lo4j1HvC9qBa3NqggB X-Received: by 2002:a05:7022:6b8d:b0:119:e55a:9c06 with SMTP id a92af1059eb24-1273ae42a63mr5426604c88.34.1771327303193; Tue, 17 Feb 2026 03:21:43 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Ashutosh Sharma Date: Tue, 17 Feb 2026 16:51:32 +0530 X-Gm-Features: AaiRm50o4MoqUf-zpsz9kv5d-1EGhbvOEIlzJ3iUQsHGLkB3tk7dvLhS3JQOJd4 Message-ID: Subject: Re: [PATCH] Support automatic sequence replication To: Ajin Cherian Cc: shveta malik , PostgreSQL Hackers 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 Hi, On Thu, Feb 12, 2026 at 2:54=E2=80=AFPM Ajin Cherian wr= ote: > > On Fri, Feb 6, 2026 at 8:15=E2=80=AFPM shveta malik wrote: > > > > On Thu, Feb 5, 2026 at 10:33=E2=80=AFAM Ajin Cherian wrote: > > > Thank You for the patch. I haven=E2=80=99t reviewed the details yet, bu= t 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? > > > > I've moved this to LogicalRepApplyLoop() > > > > On Mon, Feb 9, 2026 at 10:55=E2=80=AFAM Peter Smith wrote: > > > > Some review comments for v3-0001. > > > > =3D=3D=3D=3D=3D=3D > > .../replication/logical/sequencesync.c > > > > copy_sequences: > > > > 1. > > - if (sync_status =3D=3D COPYSEQ_SUCCESS) > > + > > + /* > > + * For sequences in READY state, only sync if there's drift > > + */ > > + if (relstate =3D=3D SUBREL_STATE_READY && sync_status =3D=3D COPYSEQ_= SUCCESS) > > + { > > + should_sync =3D check_sequence_drift(seqinfo); > > + if (should_sync) > > + drift_detected =3D true; > > + } > > + > > + if (sync_status =3D=3D COPYSEQ_SUCCESS && should_sync) > > sync_status =3D copy_sequence(seqinfo, > > - sequence_rel->rd_rel->relowner); > > + sequence_rel->rd_rel->relowner, > > + relstate); > > + else if (sync_status =3D=3D COPYSEQ_SUCCESS && !should_sync) > > + sync_status =3D COPYSEQ_NOWORK; > > > > I'm struggling somewhat to follow this logic. > > > > For example, every condition refers to COPYSEQ_SUCCESS -- is that > > really necessary; can't this all be boiled down to something like > > below? > > > > SUGGESTION > > > > /* > > * For sequences in INIT state, always sync. > > * Otherwise, for sequences in READY state, only sync if there's drift. > > */ > > if (sync_status =3D=3D COPYSEQ_SUCCESS) > > { > > if ((relstate =3D=3D SUBREL_STATE_INIT) || check_sequence_drift(seqin= fo)) > > sync_status =3D copy_sequence(...); > > else > > sync_status =3D COPYSEQ_NOWORK; > > } > > Changed as suggested. > > > > On Wed, Feb 11, 2026 at 2:30=E2=80=AFPM shveta malik wrote: > > > > On Fri, Feb 6, 2026 at 2:47=E2=80=AFPM shveta malik wrote: > > > > > Few more comments: > > > > 1) > > + /* Run sync for sequences in READY state */ > > + sequence_copied |=3D LogicalRepSyncSequences(LogRepWorkerWalRcvConn, > > SUBREL_STATE_READY); > > + > > + /* Call initial sync for sequences in INIT state */ > > + sequence_copied |=3D LogicalRepSyncSequences(LogRepWorkerWalRcvConn, > > SUBREL_STATE_INIT); > > > > Above logic means we ping primary twice for one seq-sync cycle? Is it > > possible to do it in below way: > > > > Get all sequences from the publisher in one go. > > If local-seq's state is INIT, copy those sequences, move the state to R= EADY. > > If local-seq's state is READY, check the drift and proceed accordingly. > > > > i.e, there should be a single call to LogicalRepSyncSequences() and > > relstate shouldn't even be an argument. > > > > Changed as suggested. > > > 2) > > GetSequence: > > + /* Open and lock the sequence relation */ > > + seqrel =3D table_open(relid, AccessShareLock); > > > > GetSequence is called from check_sequence_drift and > > check_sequence_drift() from copy_sequences(). In copy_sequences(), we > > already open the seq's (localrelid) table in > > get_and_validate_seq_info() and give it as output (see sequence_rel). > > Same can be passed to this instead of trying opening the table again. > > > > 3) > > + /* Verify it's actually a sequence */ > > + if (seqrel->rd_rel->relkind !=3D RELKIND_SEQUENCE) > > + ereport(ERROR, > > + (errcode(ERRCODE_WRONG_OBJECT_TYPE), > > + errmsg("\"%s\" is not a sequence", > > + RelationGetRelationName(seqrel)))); > > > > Changed these. > > Other than these, I've changed seqinfos from being a global static > list to a list that gets passed around and destroyed in each > iteration. > I haven't addressed the upgrade issue raised by Vignesh and Shveta in > this patch. I will address that in the next patch. > Here's patch v4 addressing the above comments. > How about retaining ALTER SUBSCRIPTION ... REFRESH SEQUENCES command? It can be useful in scenarios where automatic sequence replication cannot be enabled, for example, due to the max_worker_processes limit on the server preventing a new worker from being registered. Since increasing max_worker_processes requires a server restart, which the user may not want to perform immediately, this command would provide a way to manually synchronize the sequences. Thoughts? -- One minor comment: * Sequence state transitions follow this pattern: - * INIT -> READY + * INIT --> READY ->-+ + * ^ | (check/synchronzize) + * | | + * +--<---+ "synchronzize" =E2=86=92 "synchronize" -- With Regards, Ashutosh Sharma.