pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Robert Sjöblom <robert.sjoblom@fortnox.se>
To: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Re: Logical Replication Sync Validation
Date: Tue, 18 Apr 2023 18:07:21 +0200
Message-ID: <e82c7f47b11ce462d9a8ed44962e181a97699135.camel@cybertec.at> (raw)
In-Reply-To: <81990e48-56c3-21c5-7dcc-25725522c495@fortnox.se>
References: <81990e48-56c3-21c5-7dcc-25725522c495@fortnox.se>

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





view thread (4+ messages)

Message-ID: <e82c7f47b11ce462d9a8ed44962e181a97699135.camel@cybertec.at>
Permalink:  ../e82c7f47b11ce462d9a8ed44962e181a97699135.camel@cybertec.at/
Also on:    postgresql.org/message-id/e82c7f47b11ce462d9a8ed44962e181a97699135.camel@cybertec.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: laurenz.albe@cybertec.at, robert.sjoblom@fortnox.se
  Subject: Re: Logical Replication Sync Validation
  In-Reply-To: <e82c7f47b11ce462d9a8ed44962e181a97699135.camel@cybertec.at>
  References: <81990e48-56c3-21c5-7dcc-25725522c495@fortnox.se> <e82c7f47b11ce462d9a8ed44962e181a97699135.camel@cybertec.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox