> On Dec 2, 2026, at 09:55, Tristan Su <[email protected]> wrote:
>
> Hi all,
>
> I noticed two places in slotfuncs.c that reimplement helpers we already
> have.
>
> copy_replication_slot() scans ReplicationSlotCtl->replication_slots[]
> itself to find the source slot. SearchNamedReplicationSlot() performs
> exactly that lookup, and the caller already holds
> ReplicationSlotControlLock, so it can be called with
> need_lock = false.
This change replaces a for loop with SearchNamedReplicationSlot(), I think it’s
a nice cleanup.
>
> pg_get_replication_slots() compares slot_contents.data.database with
> InvalidOid three times to distinguish physical from logical slots.
> SlotIsPhysical() expresses the same condition, and the same function
> already uses this macro elsewhere.
```
- if (slot_contents.data.database == InvalidOid)
+ if (SlotIsPhysical(&slot_contents))
values[i++] = CStringGetTextDatum("physical");
else
values[i++] = CStringGetTextDatum("logical");
```
I think this change also improves readability.
>
> No functional change. make check passes, and the patch applies to
> master at cb94cb41. pgindent is clean. No backpatch is intended.
>
> Comments welcome.
>
> Regards,
> Tristan Su
> <0001-Reuse-slot-helpers-in-pg_get_replication_slots-and-s.patch>
A nit comment:
For
```
ReplicationSlot *src = NULL;
```
With the old code, src might not be assigned lately, thus it must be
initialized to NULL. But with this change:
```
+ src = SearchNamedReplicationSlot(NameStr(*src_name), false);
```
We no longer need to initialize src.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/