Re: Logical Replication Sync Validation

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Robert Sjöblom <robert(dot)sjoblom(at)fortnox(dot)se>, pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Logical Replication Sync Validation
Date: 2023-04-18 16:07:21
Message-ID: e82c7f47b11ce462d9a8ed44962e181a97699135.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 2023-04-18 at 10:20 +0200, Robert Sjöblom wrote:
> At the moment where we would switch to pg15 being the primary/lead we
> will stop writes to pg10; at that point we will validate that we are
> fully in sync, tear down pg10 and send writes to pg15. Our question is
> how we can validate our sync status. Given that there have been no DDL
> changes on pg10 (new tables, for instance), would the following check be
> sufficient?
>
> Compare byte diff between WAL LSNs:
> SELECT abs(pg_wal_lsn_diff(write_lsn, flush_lsn)) AS lag FROM
> pg_stat_replication;
>
> If the byte diff is 0, I would assume that we're fully in sync. Is this
> understanding correct?

I would compare the last replayed log sequence number with the current
position on the primary:

SELECT abs(pg_wal_lsn_diff(pg_current_wal_lsn(), replay_lsn)) AS lag
FROM pg_stat_replication;

If that is 0, you are good.

Yours,
Laurenz Albe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2023-04-18 16:35:52 Re: Request for information about postgres version 15.2 stability
Previous Message David Tinker 2023-04-18 16:04:40 Postgres as a LRU cache?