Re: [HACKERS] make async slave to wait for lsn to be replayed

From: Alexey Kondratov <a(dot)kondratov(at)postgrespro(dot)ru>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com>, Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>, a(dot)akenteva(at)postgrespro(dot)ru, a(dot)korotkov(at)postgrespro(dot)ru, i(dot)kartyshov(at)postgrespro(dot)ru, amit(dot)kapila16(at)gmail(dot)com, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: [HACKERS] make async slave to wait for lsn to be replayed
Date: 2020-04-09 18:16:05
Message-ID: a8bff0350a27e0a87a6eaf0905d6737f@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2020-04-09 16:33, Tom Lane wrote:
> Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com> writes:
>> On 2020/04/09 16:11, Kyotaro Horiguchi wrote:
>>> At Wed, 08 Apr 2020 16:35:46 -0400, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
>>> wrote in
>>>> Why is this getting grafted onto BEGIN/START TRANSACTION in the
>>>> first place?
>
>>> The rationale for not being a fmgr function is stated in the
>>> following
>>> comments. [...]
>
>> This issue happens because the function is executed after BEGIN? If
>> yes,
>> what about executing the function (i.e., as separate transaction)
>> before BEGIN?
>> If so, the snapshot taken in the function doesn't affect the
>> subsequent
>> transaction whatever its isolation level is.
>
> I wonder whether making it a procedure, rather than a plain function,
> would help any.
>

Just another idea in case if one will still decide to go with a separate
statement + BEGIN integration instead of a function. We could use
parenthesized options list here. This is already implemented for VACUUM,
REINDEX, etc. There was an idea to allow CONCURRENTLY in REINDEX there
[1] and recently this was proposed again for new options [2], since it
is much more extensible from the grammar perspective.

That way, the whole feature may look like:

WAIT (LSN '16/B374D848', TIMEOUT 100);

and/or

BEGIN
WAIT (LSN '16/B374D848', WHATEVER_OPTION_YOU_WANT);
...
COMMIT;

It requires only one reserved keyword 'WAIT'. The advantage of this
approach is that it can be extended to support xid, timestamp, csn or
anything else, that may be invented in the future, without affecting the
grammar.

What do you think?

Personally, I find this syntax to be more convenient and human-readable
compared with function call:

SELECT pg_wait_for_lsn('16/B374D848');
BEGIN;

[1]
https://www.postgresql.org/message-id/aad2ec49-5142-7356-ffb2-a9b2649cdd1f%402ndquadrant.com

[2]
https://www.postgresql.org/message-id/20200401060334.GB142683%40paquier.xyz

Regards
--
Alexey Kondratov

Postgres Professional https://www.postgrespro.com
Russian Postgres Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Davis 2020-04-09 18:25:56 Re: Default setting for enable_hashagg_disk
Previous Message Alvaro Herrera 2020-04-09 18:05:33 Re: Multiple FPI_FOR_HINT for the same block during killing btree index items