postgres-replication-stats

The “postgres-replication-stats” tool reports replication-related metrics for WAL streaming replicas, including lag sizes presented in human-readable form.

About

The postgres-replication-stats tool queries pg_stat_replication to surface the status of connected replicas. It reports application_name, client address, connection and sync state, and human-readable lag sizes (sent, write, flush, replay, and total) computed using WAL LSN differences.

Compatible sources:

This tool takes no parameters. It returns a JSON array; each element represents a replication connection on the primary and includes lag metrics formatted by pg_size_pretty.

Example

tools:
  replication_stats:
    kind: postgres-replication-stats
    source: postgres-source
    description: "Lists replication connections and readable WAL lag metrics."

Example response element:

{
  "pid": 12345,
  "usename": "replication_user",
  "application_name": "replica-1",
  "backend_xmin": "0/0",
  "client_addr": "10.0.0.7",
  "state": "streaming",
  "sync_state": "sync",
  "sent_lag": "1234 kB",
  "write_lag": "12 kB",
  "flush_lag": "0 bytes",
  "replay_lag": "0 bytes",
  "total_lag": "1234 kB"
}

Reference

fieldtyperequireddescription
pidintegertrueProcess ID of the replication backend on the primary.
usenamestringtrueName of the user performing the replication connection.
application_namestringtrueName of the application (replica) connecting to the primary.
backend_xminstringfalseStandby’s xmin horizon reported by hot_standby_feedback (may be null).
client_addrstringfalseClient IP address of the replica (may be null).
statestringtrueConnection state (e.g., streaming).
sync_statestringtrueSync state (e.g., async, sync, potential).
sent_lagstringtrueHuman-readable size difference between current WAL LSN and sent_lsn.
write_lagstringtrueHuman-readable write lag between sent_lsn and write_lsn.
flush_lagstringtrueHuman-readable flush lag between write_lsn and flush_lsn.
replay_lagstringtrueHuman-readable replay lag between flush_lsn and replay_lsn.
total_lagstringtrueHuman-readable total lag between current WAL LSN and replay_lsn.
Last modified November 19, 2025: chore(main): release 0.21.0 (#1957) (e81dfea)