Re: Logical Replication of sequences

From: vignesh C <vignesh21(at)gmail(dot)com>
To: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Cc: shveta malik <shveta(dot)malik(at)gmail(dot)com>, 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>, 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-10-31 09:27:35
Message-ID: CALDaNm2PFHHceXBnbMa_8eGZbARbRm5x=tNmKvU2LDxbTi6xYw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, 24 Oct 2024 at 04:24, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com> wrote:
>
> Here are comments on the 0001 and 0002 patches:
>
> 0001 patch:
>
> read_seq_tuple() reads a buffer and acquires a lock on it, and the
> buffer is returned to the caller while being locked. So I think it's
> possible for the caller to get the page LSN even without changes.
> Since pg_sequence_state() is the sole caller that requests lsn_ret to
> be set, I think the changes of read_seq_tuples() is not necessarily
> necessary.

Modified

> 0002 patch:
> + Assert(all_tables && *all_tables == false);
> + Assert(all_sequences && *all_sequences == false);
>
> I think it's better to set both *all_tables and *all_sequence to false
> at the beginning of the function to ensure this function works as
> expected regardless of their initial values.

Modified

> ---
> appendPQExpBufferStr(query,
> "SELECT p.tableoid, p.oid, p.pubname, "
> "p.pubowner, "
> - "p.puballtables, p.pubinsert,
> p.pubupdate, p.pubdelete, p.pubtruncate, p.pubviaroot "
> + "p.puballtables, false as
> p.puballsequences, p.pubinsert, p.pubupdate, p.pubdelete,
> p.pubtruncate, p.pubviaroot "
> "FROM pg_publication p");
> else if (fout->remoteVersion >= 110000)
> appendPQExpBufferStr(query,
> "SELECT p.tableoid, p.oid, p.pubname, "
> "p.pubowner, "
> - "p.puballtables, p.pubinsert,
> p.pubupdate, p.pubdelete, p.pubtruncate, false AS pubviaroot "
> + "p.puballtables, false as
> p.puballsequences, p.pubinsert, p.pubupdate, p.pubdelete,
> p.pubtruncate, false AS pubviaroot "
> "FROM pg_publication p");
> else
> appendPQExpBufferStr(query,
> "SELECT p.tableoid, p.oid, p.pubname, "
> "p.pubowner, "
> - "p.puballtables, p.pubinsert,
> p.pubupdate, p.pubdelete, false AS pubtruncate, false AS pubviaroot "
> + "p.puballtables, false as
> p.puballsequences, p.pubinsert, p.pubupdate, p.pubdelete, false AS
> pubtruncate, false AS pubviaroot "
> "FROM pg_publication p");
>
> The column name should be puballsequences, not p.puballsequences.

Modified

> ---
> IIUC the changes of describeOneTableDetails() includes two kinds of
> changes: refactoring to use printTable() instead of printQuery(), and
> adding publications that includes the sequence. Is the first
> refactoring necessary for the second change? If not, should it be done
> in a separate patch?

We are adding publication titles as footers to the sequence
description, each with different publication names. Since the number
of publications is unknown in advance, we will first determine the
total number of publications, then allocate the necessary size for the
footers. We will append footers[0] with either 'Owned by' or 'Sequence
for identity column,' followed by the publication titles.
Additionally, these will be subject to version checks. In this case,
using printTable instead of printQuery is preferable, as it simplifies
the code.

The attached patch has the changes for the fixes.

Regards,
Vignesh

Attachment Content-Type Size
v20241031-0002-Introduce-ALL-SEQUENCES-support-for-Postgr.patch text/x-patch 89.3 KB
v20241031-0001-Introduce-pg_sequence_state-function-for-e.patch text/x-patch 7.4 KB
v20241031-0005-Documentation-for-sequence-synchronization.patch text/x-patch 23.1 KB
v20241031-0003-Reorganize-tablesync-Code-and-Introduce-sy.patch text/x-patch 23.0 KB
v20241031-0004-Enhance-sequence-synchronization-during-su.patch text/x-patch 89.9 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alastair Turner 2024-10-31 09:47:41 Re: Count and log pages set all-frozen by vacuum
Previous Message vignesh C 2024-10-31 09:24:24 Fix typos where 'the' was repeated