Re: Logical Replication of sequences

From: vignesh C <vignesh21(at)gmail(dot)com>
To: shveta malik <shveta(dot)malik(at)gmail(dot)com>
Cc: Peter Smith <smithpb2250(at)gmail(dot)com>, Shlok Kyal <shlok(dot)kyal(dot)oss(at)gmail(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, Peter Eisentraut <peter(at)eisentraut(dot)org>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>, Euler Taveira <euler(at)eulerto(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>, Hou, Zhijie/侯 志杰 <houzj(dot)fnst(at)fujitsu(dot)com>, "Jonathan S(dot) Katz" <jkatz(at)postgresql(dot)org>
Subject: Re: Logical Replication of sequences
Date: 2024-08-05 09:04:34
Message-ID: CALDaNm1kk1MHGk3BU_XTxay=dR6sMHnm4TT5cmVz2f_JXkWENQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, 1 Aug 2024 at 09:26, shveta malik <shveta(dot)malik(at)gmail(dot)com> wrote:
>
> On Mon, Jul 29, 2024 at 4:17 PM vignesh C <vignesh21(at)gmail(dot)com> wrote:
> >
> > Thanks for reporting this, these issues are fixed in the attached
> > v20240730_2 version patch.
> >
>
> Thanks for addressing the comments. Please find few comments on patch001 alone:
>
> Potential Bug:
> 1) 'last_value' returned by pg_sequence_state() is wrong initially.
>
> postgres=# create sequence myseq5;
> CREATE SEQUENCE
>
> postgres=# select * from pg_sequence_state('myseq5');
> page_lsn | last_value | log_cnt | is_called
> -----------+------------+---------+-----------
> 0/1579C78 | 1 | 0 | f
>
> postgres=# SELECT nextval('myseq5') ;
> nextval
> ---------
> 1
>
> postgres=# select * from pg_sequence_state('myseq5');
> page_lsn | last_value | log_cnt | is_called
> -----------+------------+---------+-----------
> 0/1579FD8 | 1 | 32 | t
>
>
> Both calls returned 1. First call should have returned NULL.

I noticed the same behavior for selecting from a sequence:
postgres=# select * from myseq5;
last_value | log_cnt | is_called
------------+---------+-----------
1 | 0 | f
(1 row)

postgres=# select nextval('myseq5');
nextval
---------
1
(1 row)

postgres=# select * from myseq5;
last_value | log_cnt | is_called
------------+---------+-----------
1 | 32 | t
(1 row)

By default it shows the last_value as the start value for the
sequence. So this looks ok to me.

> 2)
> func.sgml:
> a) pg_sequence_state : Don't we need to give input arg as regclass
> like we give in nextval,setval etc?
> b) Should 'lsn' be changed to 'page_lsn' as returned in output of
> pg_sequence_state()

Modified

>
> 3)
> read_seq_tuple() header says:
> * lsn_ret will be set to the page LSN if the caller requested it.
> * This allows the caller to determine which sequence changes are
> * before/after the returned sequence state.
>
> How, using lsn which is page-lsn and not sequence value/change lsn,
> does the user interpret if sequence changes are before/after the
> returned sequence state? Can you please elaborate or amend the
> comment?

I have added this to pg_sequence_state function header in 003 patch as
the subscriber side changes are present here, I felt that is more apt
to mention. This is also added in sequencesync.c file header.

The attached v20240805_2 version patch has the changes for the same.

Regards,
Vignesh

Attachment Content-Type Size
v20240805_2-0001-Introduce-pg_sequence_state-function-for.patch text/x-patch 11.4 KB
v20240805_2-0002-Introduce-ALL-SEQUENCES-support-for-Post.patch text/x-patch 90.2 KB
v20240805_2-0003-Enhance-sequence-synchronization-during-.patch text/x-patch 101.6 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message vignesh C 2024-08-05 09:06:37 Re: Logical Replication of sequences
Previous Message Amit Kapila 2024-08-05 08:49:03 Re: Fixed small typo in bufpage.h