Hi, You could achieve that with a combination of those functions and querying the pg_stat_replication on either side of your setup.
Regards, [Fuji Xerox Australia] Nawaz Ahmed Database Administrator Fuji Xerox Australia Pty. Limited 8 Khartoum Rd, Macquarie Park NSW 2113 Australia | P: 02 9856 5337 | E: nawaz.ah...@aus.fujixerox.com<mailto:nawaz.ah...@aus.fujixerox.com> | W: www.fujixerox.com.au<http://www.fujixerox.com.au> | [http://xww.aus.xerox.com/staffdirectory/ebizcard/images/facebook.png]<https://www.facebook.com/FujiXeroxAustralia> [http://xww.aus.xerox.com/staffdirectory/ebizcard/images/twitter.png] <https://twitter.com/fujixeroxaus> [http://xww.aus.xerox.com/staffdirectory/ebizcard/images/linkedin.png] <http://www.linkedin.com/company/fuji-xerox-australia> [http://xww.aus.xerox.com/staffdirectory/ebizcard/images/youtube.png] <https://www.youtube.com/playlist?list=PL1624299D50FAA7C1> [http://xww.aus.xerox.com/staffdirectory/ebizcard/images/blog.png] <http://www.fujixerox.com.au/blog/> [http://xww.aus.xerox.com/staffdirectory/ebizcard/images/feedback.png]<https://fujixerox.au1.qualtrics.com/jfe/form/SV_ehrj1apkwRRNKYZ> Please think before you print and use duplex printing to preserve resources[Please think before you print and use duplex printing to preserve resources]<https://www.fujixerox.com.au/en/Company/Sustainability> From: Mariya Rampurawala <mariya.rampuraw...@veritas.com> Sent: Wednesday, 5 August 2020 1:23 AM To: pgsql-gene...@postgresql.org Subject: PostgreSQL-12 replication. Check replication lag Hi, I am working on providing HA for replication, using automation scripts. My set up consists of two nodes, Master and Slave. When master fails, The slave is promoted to master. In case of sync replication, we do not check if the data is up-to-date on slave. But in case of async replication, how can we check if the slave is up-to-date. One way I found from the blogs is to compare the values of pg_last_wal_receive_lsn() and pg_last_wal_replay_lsn() If these values are same, can we say that the slave is up-to-date? Both these values I will fetch from the slave node. How will the slave ensure it is up-to-date, if the network between master and slave is broken? Regards, Mariya IMPORTANT NOTE: Fuji Xerox email transmission, including any attachments, is private and confidential and may contain legally privileged information. It is for the addressee's attention only. If you are not the intended recipient and have received this transmission, you must not use, edit, print, copy or disclose its contents to any person or disseminate the information contained herein or hereto attached, and you must notify sender immediately by return email and delete this transmission from your system. Any confidentiality, privilege or copyright is not waived or lost because this e-mail has been sent to you in error. We have used reasonable efforts to protect this transmission from computer viruses and other malicious software, but no warranty is made and the sender takes no responsibility for any loss or damage incurred from using this email or the information contained in this email.