postgresのレプリケーションの状態を確認する

pgsqlのレプリケーションの状態を確認する手順と、レプリケーションが正しく行われていないことを示すタイミングを、どなたか教えてください。

pgsql9.0とpgsql9.4でストリーミングレプリケーションを使用しています。

ありがとうございます。

マスター上では、pg_stat_replicationが進行中のレプリケーションに関するデータを提供します。

select client_addr, state, sent_location, write_location,
        flush_location, replay_location from pg_stat_replication;

Postgresql v10 では、以下のようになります。

select client_addr, state, sent_lsn, write_lsn,
    flush_lsn, replay_lsn from pg_stat_replication;
解説 (3)

PostgreSQLでレプリケーションの状態を表示する

サーバー上

postgres=# select usename,application_name,client_addr,backend_start,state,sync_state from pg_stat_replication ;

usename   | application_name |  client_addr   |         backend_start         |   state   | sync_state 
------------+------------------+----------------+-------------------------------+-----------+------------
replicator | walreceiver      | 192.168.10.132 | 2018-07-06 06:12:20.786918+03 | streaming | async
(1 row)

オンクライアント

postgres=# select pg_is_in_recovery();
 pg_is_in_recovery 
-------------------
 t
 (1 row)

postgres=# select pg_last_xlog_receive_location();
 pg_last_xlog_receive_location 
-------------------------------
 0/540C1DB8

postgres=# select pg_last_xlog_replay_location();
 pg_last_xlog_replay_location 
------------------------------
 0/540C1DB8
 (1 row)

postgres=#    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;
 log_delay 
-----------
 0
 (1 row)
解説 (1)

Postgres v11 では、通常、以下の SQL クエリでステータスを確認しています。

**マスターの場合

select * from pg_stat_replication;

レプリカの場合(私の場合はストリーミングレプリケーション)。

select * from pg_stat_wal_receiver;
解説 (0)