I know we can connect to primary and SELECT pg_current_xlog_location(); (eg. '0/36A77900') to get primary xlog position then connect to the standby to do the following to get the byte lag:
My question is that is there a way I can connect to the primary on the standby host using replica user which i already have the primary_conninfo in the recovery.conf and get the result of SELECT pg_current_xlog_location(); of the primary so I can simply write a function on the standby to return the lag in bytes in one call.