pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Zwettler Markus (OIZ) <Markus.Zwettler@zuerich.ch>
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: sql query for postgres replication check
Date: Fri, 22 Nov 2019 13:20:59 +0000
Message-ID: <cf8b3fce87404edd836ceb705d36776b@zuerich.ch> (raw)

We would like to check the Postgres SYNC streaming replication status with Nagios using the same query on all servers (master + standby) and versions (9.6, 10, 12) for simplicity.


I came up with the following query which should return any apply lag in seconds.


select coalesce(replay_delay, 0) replication_delay_in_sec
from (
       select datname,
              (
                select case
                         when received_lsn = latest_end_lsn then 0
                         else extract(epoch
                from now() - latest_end_time)
                       end
                from pg_stat_wal_receiver
              ) replay_delay
       from pg_database
       where datname = current_database()
     ) xview;


I would expect delays >0 in case SYNC or ASYNC replication is somehow behind. We will do a warning at 120 secs and critical at 300 secs.


Would this do the job or am I missing something here?


Thanks, Markus

view thread (2+ messages)  latest in thread

Message-ID: <cf8b3fce87404edd836ceb705d36776b@zuerich.ch>
Permalink:  ../cf8b3fce87404edd836ceb705d36776b@zuerich.ch/
Also on:    postgresql.org/message-id/cf8b3fce87404edd836ceb705d36776b@zuerich.ch

 · 

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: Markus.Zwettler@zuerich.ch
  Subject: Re: sql query for postgres replication check
  In-Reply-To: <cf8b3fce87404edd836ceb705d36776b@zuerich.ch>
  References: <cf8b3fce87404edd836ceb705d36776b@zuerich.ch>

* 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