How to check the replication delay in PostgreSQL?

后端 未结 6 1636
眼角桃花
眼角桃花 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:10

    slightly different version of the correct answer:

    postgres=# SELECT
      pg_last_xlog_receive_location() receive,
      pg_last_xlog_replay_location() replay,
      (
       extract(epoch FROM now()) -
       extract(epoch FROM pg_last_xact_replay_timestamp())
      )::int lag;
    
      receive   |   replay   |  lag  
    ------------+------------+-------
     1/AB861728 | 1/AB861728 | 2027
    

    the lag is only important when "receive" not equal "replay". execute the query on the replica

提交回复
热议问题