I am wondering if there is a way to find replication lag (in time seconds etc.) between primary and standby in case of STREAMING REPLICATION.
I can use the function pg_last_xact_replay_timestamp () as below. Only problem is IF THERE IS NO UPDATE ACTIVITY in primary database the output of the following query keeps increasing but in reality standby is in sync with primary data-wise.
SELECT EXTRACT (EPOCH FROM AGE(current_timestamp, pg_last_xact_replay_timestamp()) )