pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Zwettler Markus (OIZ) <Markus.Zwettler@zuerich.ch>
To: Michael Paquier <michael@paquier.xyz>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: AW: sql query for postgres replication check
Date: Mon, 25 Nov 2019 09:26:09 +0000
Message-ID: <0df1cf5f79f546ce9797e8510ad22047@zuerich.ch> (raw)
In-Reply-To: <20191125041428.GJ37821@paquier.xyz>
References: <cf8b3fce87404edd836ceb705d36776b@zuerich.ch>
	<20191125041428.GJ37821@paquier.xyz>

> On Fri, Nov 22, 2019 at 01:20:59PM +0000, Zwettler Markus (OIZ) wrote:
> > 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.
> 
> pg_stat_wal_receiver is available only on the receiver, aka the standby so it would
> not really be helpful on a primary.  On top of that streaming replication is system-
> wide, so there is no actual point to look at databases either.
> 
> > Would this do the job or am I missing something here?
> 
> Here is a suggestion for Nagios: hot_standby_delay, as told in
> https://github.com/bucardo/check_postgres/blob/master/check_postgres.pl
> --
> Michael


I don't want to use check_hot_standby_delay as I would have to configure every streaming replication configuration separately with nagios.

I want a generic routine which I can load on any postgres server regardless of streaming replication or database role.

The query would return >0 if streaming replication falls behind and 0 in all other cases (replication or not).

Checking streaming replication per database doesn't make any sense to me.

Markus






Message-ID: <0df1cf5f79f546ce9797e8510ad22047@zuerich.ch>
Permalink:  ../0df1cf5f79f546ce9797e8510ad22047@zuerich.ch/
Also on:    postgresql.org/message-id/0df1cf5f79f546ce9797e8510ad22047@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, michael@paquier.xyz
  Subject: Re: sql query for postgres replication check
  In-Reply-To: <0df1cf5f79f546ce9797e8510ad22047@zuerich.ch>
  References: <cf8b3fce87404edd836ceb705d36776b@zuerich.ch> <20191125041428.GJ37821@paquier.xyz> <0df1cf5f79f546ce9797e8510ad22047@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