Thread: Re: [EXTERNAL] RE: PostgreSQL-12 replication. Check replication lag
Hi Ahmed,
Can you please elaborate?
One way I found to check the time lag is this:
postgres=# SELECT CASE WHEN pg_last_wal_receive_lsn() = pg_last_wal_replay_lsn()
THEN 0
ELSE EXTRACT (EPOCH FROM now() - pg_last_xact_replay_timestamp())
END AS log_delay;
What I want to understand is that, in case of replication link failure, there will still be inserts happening at the master node. In that case, how will the slave know if it is up-to-date?
Regards,
Mariya
From: "Ahmed, Nawaz (Fuji Xerox Australia)" <Nawaz.Ahmed@aus.fujixerox.com>
Date: Wednesday, 5 August 2020 at 11:41 PM
To: Mariya Rampurawala <Mariya.Rampurawala@veritas.com>, "pgsql-general@postgresql.org" <pgsql-general@postgresql.org>
Subject: [EXTERNAL] RE: PostgreSQL-12 replication. Check replication lag
Hi,
You could achieve that with a combination of those functions and querying the pg_stat_replication on either side of your setup.
Regards,
Nawaz Ahmed
Database Administrator
Fuji Xerox Australia Pty. Limited
8 Khartoum Rd, Macquarie Park NSW 2113 Australia
| P: 02 9856 5337 | E: Nawaz.Ahmed@aus.fujixerox.com | W: www.fujixerox.com.au |
Please think before you print and use duplex printing to preserve resources
From: Mariya Rampurawala <Mariya.Rampurawala@veritas.com>
Sent: Wednesday, 5 August 2020 1:23 AM
To: pgsql-general@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.
On Wed, Aug 05, 2020 at 06:36:15PM +0000, Mariya Rampurawala wrote: > What I want to understand is that, in case of replication link > failure, there will still be inserts happening at the master > node. In that case, how will the slave know if it is up-to-date? It cannot do that by itself, which is why in common HA scenarios you have a witness host that acts as a monitoring instance for the primary and the standby so as you limit SPOF issues. This depends of course on your application requirements, but you can also leverage things by using a replication lag in bytes on the primary, and even couple that with synchronous replication to check when commits are getting blocked. IMO, I think that you should try to not reinvent the wheel and use one of the solutions provided by the community, pg_auto_failover coming into my mind as one solution for example. -- Michael