Re: sql query for postgres replication check

Michael Paquier <[email protected]>
Newsgroups gmane.comp.db.postgresql.general
Message-ID <[email protected]>
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
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAl3bVSQACgkQnvQgOdby
QH3jDBAAnzIRN0boxVj2OI1g+CkNGID5R4vn88X5vuhiYe+5WrzPrEKmmN33eW+L
xRBrzMwpYF6Gqay/7V93J8I/UO4BsZEVuBBw8A5dUJIiqJexHobeFfrPouU7I1Id
srTyMdfDTKzZQGvQscr2ubtCiqGxfChaYMajvo6Qx6Ph2UlNUGYBD4LbCi9F806c
lnQ8mvz6ozqgTUcZglaSTpfYs9/2lGzFDBsorGHIm1ESsGLxFxvbZJDFg38cESsH
CENoG+ZGaw5T/GORad89EL4+u7lFMmt4N+/qK3wvwmCiNDqjbyUCcYIRg/2P9ypn
JfMPydxbUHIDhOwaZu9sJONBHU8I1hR1BZRv5ODwr8+e36TFMIfgVrG/gRsJoD33
fw/2YdtASOemtE/6rQ0TCZpcvyBV4DOtxCrWT2l6j1J04V8mtYkLfquHZoJbgbHv
gWVk7ib/4xIAYYqsm19SuP+GchFyz6Ni7sL/gJD6GavNn7T6yipdnVwwURbnGcDC
FzRv0saqH4mv8rmVnx51dyFeBvOD+38XU1W/jgQcK/9+UgwcH4f9/2rS3IT3MmQf
2fTe8Q0FwokPsc2WHL8m4Maaxrwv5A1wIgHlCJvtpNbcjzcKUYGhuXcHmJuC3giU
izctmAoYVYp5JyYNm9aP5bmjgB56i6po8zkewMFlPbkbI+j6vWc=
=4xmO
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.