How to check the replication delay in PostgreSQL?

后端 未结 6 1627
眼角桃花
眼角桃花 2020-12-28 13:57

I would like to measure time between insert data into master-table and slave-table using streaming replication in PostgreSQL 9.3. For this I create table test_time

6条回答
  •  暖寄归人
    2020-12-28 14:03

    If your database has frequent writes, then the below query is a close approximation to get the slave lag

    select now() - pg_last_xact_replay_timestamp() AS replication_delay;
    

    Below is a more accurate query for calculating replication lag for databases with very few writes. If the master doesnt sent down any write to the slave, then pg_last_xact_replay_timestamp() can be constant and hence may not accurately determine the slave lag using the above query.

    SELECT CASE WHEN pg_last_xlog_receive_location() =
    pg_last_xlog_replay_location() THEN 0 ELSE EXTRACT (EPOCH FROM now() -
    pg_last_xact_replay_timestamp()) END AS log_delay;
    

提交回复
热议问题