pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedsql query for postgres replication check
2+ messages / 2 participants
[nested] [flat]
* sql query for postgres replication check
@ 2019-11-22 13:20 Zwettler Markus (OIZ) <Markus.Zwettler@zuerich.ch>
2019-11-25 04:14 ` Re: sql query for postgres replication check Michael Paquier <michael@paquier.xyz>
0 siblings, 1 reply; 2+ messages in thread
From: Zwettler Markus (OIZ) @ 2019-11-22 13:20 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
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
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: sql query for postgres replication check
2019-11-22 13:20 sql query for postgres replication check Zwettler Markus (OIZ) <Markus.Zwettler@zuerich.ch>
@ 2019-11-25 04:14 ` Michael Paquier <michael@paquier.xyz>
0 siblings, 0 replies; 2+ messages in thread
From: Michael Paquier @ 2019-11-25 04:14 UTC (permalink / raw)
To: Zwettler Markus (OIZ) <Markus.Zwettler@zuerich.ch>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
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
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2019-11-25 04:14 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-11-22 13:20 sql query for postgres replication check Zwettler Markus (OIZ) <Markus.Zwettler@zuerich.ch>
2019-11-25 04:14 ` Michael Paquier <michael@paquier.xyz>
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