film42 / pgreba

A health-checking service for postgres
2 stars 5 forks source link

Replica byte lag health check #5

Closed schinns closed 4 years ago

schinns commented 4 years ago

Addresses issue https://github.com/film42/pgreba/issues/3.

Reads pg_current_wal_lsn from primary and pg_last_wal_receive_lsn from replica and gets byte lag from pg_wal_lsn_diff(lsn, lsn).

postgres=# select pg_current_wal_lsn();                                                                                                                 
-[ RECORD 1 ]------+----------                                                                                                                          
pg_current_wal_lsn | 0/4000108 
postgres=# select pg_last_wal_receive_lsn();                                                                                                            
-[ RECORD 1 ]-----------+----------                                                                                                                     
pg_last_wal_receive_lsn | 0/4000108  
postgres=# postgres=# select pg_wal_lsn_diff('0/4000108', '0/4000108');                                                                                 
-[ RECORD 1 ]---+--                                                                                                                                     
pg_wal_lsn_diff | 0  

example payload:

{
   "state":0,
   "postmaster_start_time":"2020-08-07 08:54:37.141 MDT",
   "role":"replica",
   "xlog":{
      "location":0,
      "received_location":1694501464,
      "replayed_location":1694501464,
      "replayed_timestamp":null,
      "paused":false
   },
   "replication":[

   ],
   "byte_lag: 0
}
film42 commented 4 years ago

Dude! Awesome work here! Left two comments, but this is really really good!

film42 commented 4 years ago

Looks great! Thanks for your work on this! Enjoy the PNW :)

schinns commented 4 years ago

Thanks @film42 for reviewing and providing feedback!