Files
genai-toolbox/docs/en/resources/tools/postgres/postgres-replication-stats.md
Siddharth Ravi 5abad5d56c feat(tools/postgres): add long_running_transactions, list_locks and replication_stats tools (#1751)
Adds the following tools for Postgre
(1) long_running_transactions - reports transactions that exceed a
configured duration threshold.
(2) list_locks - lists active locks in the database, including the
associated process, lock type, relation, mode, and the query holding or
waiting on the lock.
(3) replication_stats - reports replication-related metrics for WAL
streaming replicas, including lag sizes presented in human-readable
form.

<img width="3020" height="1420" alt="image"
src="https://github.com/user-attachments/assets/e7d70063-b90c-4464-90ec-1bd810c02cac"
/>

<img width="3036" height="1374" alt="image"
src="https://github.com/user-attachments/assets/f7cf584b-ae01-455c-9c9c-acca3166a549"
/>

<img width="2682" height="868" alt="image"
src="https://github.com/user-attachments/assets/dd10646c-4521-4d8f-a111-760d6eb01249"
/>


## PR Checklist
- [Y] Make sure you reviewed

[CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md)
- [Y] Make sure to open an issue as a

[bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose)
  before writing your code! That way we can discuss the change, evaluate
  designs, and agree on the general idea
- [Y] Ensure the tests and linter pass
- [Y] Code coverage does not decrease (if any source code was changed)
- [Y] Appropriate docs were updated (if necessary)
- [Y] Make sure to add `!` if this involve a breaking change

🛠️ Fixes #1691 #1715

---------

Co-authored-by: Wenxin Du <117315983+duwenxin99@users.noreply.github.com>
2025-11-18 19:23:10 +00:00

2.8 KiB

title, type, weight, description, aliases
title type weight description aliases
postgres-replication-stats docs 1 The "postgres-replication-stats" tool reports replication-related metrics for WAL streaming replicas, including lag sizes presented in human-readable form.
/resources/tools/postgres-replication-stats

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

field type required description
pid integer true Process ID of the replication backend on the primary.
usename string true Name of the user performing the replication connection.
application_name string true Name of the application (replica) connecting to the primary.
backend_xmin string false Standby's xmin horizon reported by hot_standby_feedback (may be null).
client_addr string false Client IP address of the replica (may be null).
state string true Connection state (e.g., streaming).
sync_state string true Sync state (e.g., async, sync, potential).
sent_lag string true Human-readable size difference between current WAL LSN and sent_lsn.
write_lag string true Human-readable write lag between sent_lsn and write_lsn.
flush_lag string true Human-readable flush lag between write_lsn and flush_lsn.
replay_lag string true Human-readable replay lag between flush_lsn and replay_lsn.
total_lag string true Human-readable total lag between current WAL LSN and replay_lsn.