title: measuring replication lag in postgresql
body: <p>im trying to measure the replication time lag in my system. (postgresql 10.1)</p>
  
  <p>I use a combination of <code>pg_last_xact_timestamp()</code>, <code>pg_last_receive_lsn()</code> and <code>pg_last_replay_lsn()</code> functions in a query to check the lag. </p>
  
  <p>(Took an example of how to measure from <a href="https://www.postgresql.org/message-id/flat/CADKbJJWz9M0swPT3oqe8f9%2BtfD4-F54uE6Xtkh4nERpVsQnjnw%40mail.gmail.com" rel="nofollow noreferrer">this</a> link)</p>
  
  <pre><code>postgres=# SELECT now(), pg_last_wal_receive_lsn(), pg_last_wal_replay_lsn(), EXTRACT (EPOCH FROM now() - pg_last_xact_replay_timestamp())::INT;
                 now                | pg_last_wal_receive_lsn | pg_last_wal_replay_lsn | date_part 
  ----------------------------------+-------------------------+------------------------+-----------
   2018-08-06 07:00:36.540959+05:30 | 4/99B84030              | 4/99B84030             |       223
  </code></pre>
  
  <p>As it can be seen from the 2nd and 3 rd columns, the last receive lsn and replay lsn are same, meaning that the systems are in sync. But im unable to understand what is <code>pg_last_xact_replay_timestamp()</code> is. How does it find out replication lag in seconds. Am i using wrong approach to measure the lag in seconds?</p>