Search Postgresql Archives

sql query for postgres replication check

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

 

 

 

 

 

 

 

 


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux