RE: Logical Replication of sequences

From: "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>
To: 'vignesh C' <vignesh21(at)gmail(dot)com>, shveta malik <shveta(dot)malik(at)gmail(dot)com>
Cc: Nisha Moond <nisha(dot)moond412(at)gmail(dot)com>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Peter Smith <smithpb2250(at)gmail(dot)com>, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, Shlok Kyal <shlok(dot)kyal(dot)oss(at)gmail(dot)com>, Peter Eisentraut <peter(at)eisentraut(dot)org>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Euler Taveira <euler(at)eulerto(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, "Zhijie Hou (Fujitsu)" <houzj(dot)fnst(at)fujitsu(dot)com>, "Jonathan S(dot) Katz" <jkatz(at)postgresql(dot)org>
Subject: RE: Logical Replication of sequences
Date: 2025-08-15 11:16:30
Message-ID: OSCPR01MB149660AE561977531A722208FF534A@OSCPR01MB14966.jpnprd01.prod.outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Dear Vignesh,

Thanks for updating the patch. Here are my small comments:

01.
Per pgindent report, publicationcmds.c should be fixed.

02.
```
+ ScanKeyInit(&skey[1],
+ Anum_pg_subscription_rel_srsubstate,
+ BTEqualStrategyNumber, F_CHARNE,
+ CharGetDatum(SUBREL_STATE_READY));
```

I felt it is more natural to "srsubstate = 'i'", instead of "srsubstate <> 'r'"

03.
```
+ table_close(sequence_rel, NoLock);
+ }
+
+ /* Cleanup */
+ systable_endscan(scan);
+ table_close(rel, AccessShareLock);
+
+ CommitTransactionCommand();
```

To clarify, can we release the sequence at the end of the inner loop?

I found that sequence relation is closed (but not release the lock) then commit
the transaction once. This approach cannot avoid dropping it by concurrent
transactions, but maybe you did due to the performance reason. So...I felt we
may able to release bit earlier.

04.
```
+ sequence_rel = try_table_open(seqinfo->localrelid, RowExclusiveLock);
+
+ /* Get the local sequence */
+ tup = SearchSysCache1(SEQRELID, ObjectIdGetDatum(seqinfo->localrelid));
+ if (!sequence_rel || !HeapTupleIsValid(tup))
+ {
+ elog(LOG, "skip synchronization of sequence \"%s.%s\" because it has been dropped concurrently",
+ seqinfo->nspname, seqinfo->seqname);
+
+ batch_skipped_count++;
+ continue;
+ }
```

a. Code comment can be atop try_table_open().
b. Isn't it enough to check HeapTupleIsValid() here?

05.
```
+ /* Update the sequence only if the parameters are identical */
+ if (seqform->seqtypid == seqtypid &&
+ seqform->seqmin == seqmin && seqform->seqmax == seqmax &&
+ seqform->seqcycle == seqcycle &&
+ seqform->seqstart == seqstart &&
+ seqform->seqincrement == seqincrement)
```

I noticed that seqcache is not compared. Is there a reason?

06.
```
+ foreach_ptr(LogicalRepSequenceInfo, seq_info, sequences_to_copy)
+ {
+ pfree(seq_info->seqname);
+ pfree(seq_info->nspname);
+ pfree(seq_info);
+ }
```

Per comment atop foreach_delete_current(), we should not directly do pfree()
the entry. Can you use foreach_delete_current()? I.e.,

07.
```
foreach_ptr(LogicalRepSequenceInfo, seq_info, sequences_to_copy)
{
pfree(seq_info->seqname);
pfree(seq_info->nspname);

sequences_to_copy =
foreach_delete_current(sequences_to_copy, seq_info);
}
```

08.
```
+$node_subscriber->init(allows_streaming => 'logical');
```

Actually no need to set to 'logical'.

Best regards,
Hayato Kuroda
FUJITSU LIMITED

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Hayato Kuroda (Fujitsu) 2025-08-15 12:07:30 RE: memory leak in logical WAL sender with pgoutput's cachectx
Previous Message Heikki Linnakangas 2025-08-15 11:12:03 Re: A few patches to clarify snapshot management