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 1vqTXV-00BVKr-0t for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Feb 2026 10:03:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vqTXU-007iaD-1T for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Feb 2026 10:03:13 +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 1vqTXU-007ia4-0L for pgsql-hackers@lists.postgresql.org; Thu, 12 Feb 2026 10:03:12 +0000 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vqTXS-00000000IJP-3XOM for pgsql-hackers@lists.postgresql.org; Thu, 12 Feb 2026 10:03:12 +0000 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-823210d1d8eso3387896b3a.1 for ; Thu, 12 Feb 2026 02:03:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1770890587; cv=none; d=google.com; s=arc-20240605; b=AEWipB9SBcyf1rnC+kWzDMHEW+b7J58Ez4/txgKuBj1CoylWTPXIucPt8NJMNjVSxJ TpahX6Hzb+LQqAaDaKndZNQ0dNO8HhG4tn3BsRvrWQk6+44cBwY+xkKh1pLkBcbHJxBm nog0/XGsoKHEWV+c2ykodTBTq4CWnooISDCOUxL5YBBSFsyKhVczcp8MY70cHmE4jzGz XQ8MkiplmdxKCEQDzAr8myNgvVBd9ntbg92gTN4J/yhyp97pEZLsiFgFP5vVaWx+Qu6x MRVndhLupweXzsBrrns6ujR+5ZV+7lJ5T3pjuPuKFTu3ubx8cG7nHPtWmrCdQfPFESUZ uObA== 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=5vjqOwsH2fVMFtxP2CGyVIEEaRcnDTildIO4GrGL+ss=; fh=r9w9PsUtvtMRJQYuw+d2X3ogW396LTBPq014jPXw08Y=; b=FgAzDF8Vu/EHFOEnrd69pgdBeqBo/FOPOevSy6tGof+0tWZIbwKYrSYH2bg0Uec1iB ZT9IQM17Ogds+onFRv1Vieav8snoOBiARXBO2NQCeshuI6XE+RZ7OfLTNORd81C0Ydqb wHsduVETOR0E2XEbksMcfy/urGcQJVnIZvYaDOYPjdVoWHy4jHDyDh8I5F2bhfL6rtrD vtmHW59x3WPFZnwcv2ZxnneDtq583yR8JXYQ2ioEu21mLECZUo+Ygg9gB3xaQ9K8TycF S0tnIOq7zE69IA7gzPvll3ZGdu9aG39YU8x1hdI1aMbVw/KRzmr5xKhlKLCyJBela2z8 8UuQ==; 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=1770890587; x=1771495387; 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=5vjqOwsH2fVMFtxP2CGyVIEEaRcnDTildIO4GrGL+ss=; b=G8EcD7KmeBceaXYXtBg64p/MFmHJXshYWhYnFoUrnzST4LD14iAncFf+fl1c7rJ7Vw wA376mLNZSIKAGH5l5XaiVevIda+EhU+X8davI1r9sgium+PB3b0eSRf32C3UCQTTsSk i3UmHpKy4TmHZVh/G75g1fau3j32sxYih4JhOQjPZRij39jvz2uS96KFL1kKIJ4hcr/B P4uICMu0nWXTIS+HmfNJgxUw3FwWXqGipWBE7lNOdnZeNnXE4SZX5ClO+Lu87Z5WQgde SrCeuLjvC1e6ulcEHRZJtV/P++YfWRtwbb1D+3W8rTkLO3QPm6If7LEOX3JRo4KwH5mj 1Fwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770890587; x=1771495387; 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=5vjqOwsH2fVMFtxP2CGyVIEEaRcnDTildIO4GrGL+ss=; b=WCJzqtQ7RLD/fLJ/nngRiDHThDqVUy7JmqKhJNxhRQvhaPyXOmzVlZ6BMF0vNWmcPH myYbJNc6qsZldoL2QtILaeL8urXm8/QbHGI2Zwj727uD+wkNsr4sC9WSZMehm7jFy8mm KnDeOANFCYPMw6iqIIw5QYoqdW4bRcqiOhuCSjfKSt9SEqu7RBp3ubgML/NriArl51HG g2SDrFCspcZdBNrS4pk6awCUQXl/8ETKnWwwBotcqZ3gl1wIildfDJ86GLONvrEjwMGU WCFRy67Nenw9HB77AlQzCfPvyjUl7MV1OgdkpuSol4l5MWLjFT1Mxuftpxwldiu7mmUC p/ew== X-Gm-Message-State: AOJu0YxkQGn4izZk8M8bji56Hi319+H5NIUOUp3J8RrJgVC1IAAY+bg3 vGtl9jrElmmCX1qtzon65FtV5EwxxlTtiGBVjFXMn3pNfoB8c3VOWlbyMLy4kSCuLl+nNtgLYPM vzqIqXikIeeCPczcBZnQyhcSSJQkYtH0= X-Gm-Gg: AZuq6aJ81s+F+FQbG/qAlrBG7lwYKOgWzK2TU2UwSjh7YSUc2nAhEQVAagut7KOPUAx 8sGP06py3lOjZDm9vN1aFLc36eVxZi/X3NMBt+NkXAWX1Hh+o7wp8HVjXyBJTvkHJugSxbbmU45 F+IBKIA4v6Y3DQno8Pg5+ERUmJUHk2tEq1cJDZhBb+ZNhjqY4oMJ7TO3gKbemNVwTe59i4ucv3M o4nVW613LDq/gdxWG4ABvB/AonyuKwXRFaFHQ/pdROrBOf4xKnFCggdIua4WdOQoDJ4wxn3gzQm 9ifWFD/BtwIETsxCMLlroiPlPqFEgmcLGj1xRFr0vFACnq8mCJ+5 X-Received: by 2002:a05:6a20:a125:b0:35d:e4b2:b381 with SMTP id adf61e73a8af0-3944846592bmr2275064637.16.1770890587426; Thu, 12 Feb 2026 02:03:07 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: shveta malik Date: Thu, 12 Feb 2026 15:32:56 +0530 X-Gm-Features: AZwV_QjtWTysXkB8PDdfJX5WlhQkv2XPavp-VBsG4aBocFlUJ9zsbEO2-hzSSYA 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 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. Thanks Ajin, I will review. I will suggest waiting for others' feedback before doing anything about the upgrade issue. Meanwhile, we can try to improve the current patch itself. thanks Shveta