Re: [EXTERNAL] RE: PostgreSQL-12 replication. Check replication lag - Mailing list pgsql-general

From Mariya Rampurawala
Subject Re: [EXTERNAL] RE: PostgreSQL-12 replication. Check replication lag
Date
Msg-id 2C54A29A-5569-4024-80D8-C1C25EC82E46@veritas.com
Whole thread Raw
Responses Re: [EXTERNAL] RE: PostgreSQL-12 replication. Check replication lag  (Michael Paquier <michael@paquier.xyz>)
List pgsql-general

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,

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.Ahmed@aus.fujixerox.com | W: www.fujixerox.com.au |

        





Please think before you print and use duplex printing to preserve resourcesPlease 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.

pgsql-general by date:

Previous
From: "Ahmed, Nawaz (Fuji Xerox Australia)"
Date:
Subject: RE: PostgreSQL-12 replication. Check replication lag
Next
From: Sreejith P
Date:
Subject: Check replication lag