Re: Does having pg_last_wal_replay_lsn[replica] >= pg_current_wal_insert_lsn[master] guarantee that the replica is caught up?

From: Dmitry Koterov <dmitry(dot)koterov(at)gmail(dot)com>
To: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Does having pg_last_wal_replay_lsn[replica] >= pg_current_wal_insert_lsn[master] guarantee that the replica is caught up?
Date: 2022-08-03 09:10:08
Message-ID: CA+CZih7Q5cghTYSFCwC_kNGLSx1jWC4w3=UgJz0mO5A_JYnfvA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thank you for the detailed explanation!

I doubt many people from -general would actually be able to provide such
info since the spirit of that list is to find work-arounds for problems and
questions at user level rather than dig into the details on how something
actually works.

It's worth adding to the documentation, with that exact example BTW:
https://www.postgresql.org/docs/current/functions-admin.html#FUNCTIONS-ADMIN-BACKUP-TABLE
(I can try submitting a docs PR if you think it's a good idea).

Also, when I said that we use PQexec, I did it just for an illustration: in
practice we use the node-postgres JS library which sends multi-statement
protocol messages. So - transaction wise - it works the same way as PQexec
with multiple queries, but it returns responses for ALL queries in the
batch, not just for the last one (very convenient BTW, saves on network
round-trip latency). This mode is fully supported by PG wire protocol:
https://www.postgresql.org/docs/current/protocol-flow.html#PROTOCOL-FLOW-MULTI-STATEMENT

On Wed, Aug 3, 2022 at 12:32 AM Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
wrote:

>
> <snip>
>

=# select pg_current_wal_insert_lsn();
> pg_current_wal_insert_lsn
> ---------------------------
> 0/*68E5038*
> (1 row)
> =# insert into t values(0)\; select pg_current_wal_lsn();
> INSERT 0 1
> pg_current_wal_lsn
> --------------------
> 0/*68E5038*
> (1 row)
> =# select pg_current_wal_insert_lsn();
> pg_current_wal_insert_lsn
> ---------------------------
> 0/68E50A0
> (1 row)

<snip>
>

> =# select pg_current_wal_insert_lsn();
> pg_current_wal_insert_lsn
> ---------------------------
> 0/*68E75C8*
> (1 row)
> =# begin\;insert into t values(0)\;commit\; select pg_current_wal_lsn();
> pg_current_wal_lsn
> --------------------
> 0/*68E7958*
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2022-08-03 10:53:15 Re: PostgreSQL 15 minor fixes in protocol.sgml
Previous Message Shinoda, Noriyoshi (PN Japan FSIP) 2022-08-03 08:42:01 RE: Improve logging when using Huge Pages