Files
genai-toolbox/docs/en/resources/tools/postgres/postgres-list-query-stats.md
Siddharth Ravi 9f76026925 feat: add list-query-stats and get-column-cardinality functions (#1976)
Adds the following tools for Postgre
(1) get_column_cardinality - to fetch the estimates of the distinct
column counts in the table for particular column or all columns
(2) list-query-stats - to obtain the query level statistics in a
database. This tool requires pg_stat_statements extension as a
prerequisite.

<img width="2428" height="1368" alt="image"
src="https://github.com/user-attachments/assets/5d9b22f0-6b09-4abe-8411-b1139387e259"
/>

<img width="3774" height="1010" alt="image"
src="https://github.com/user-attachments/assets/b1d9fdf1-8a3b-4afe-ab98-63226a7e3705"
/>


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 https://github.com/googleapis/genai-toolbox/issues/1691

---------

Co-authored-by: Averi Kitsch <akitsch@google.com>
2025-11-26 23:43:03 +00:00

2.8 KiB

title, type, weight, description, aliases
title type weight description aliases
postgres-list-query-stats docs 1 The "postgres-list-query-stats" tool lists query statistics from a Postgres database.
/resources/tools/postgres-list-query-stats

About

The postgres-list-query-stats tool retrieves query statistics from the pg_stat_statements extension in a PostgreSQL database. It provides detailed performance metrics for executed queries. It's compatible with any of the following sources:

postgres-list-query-stats lists detailed query statistics as JSON, ordered by total execution time in descending order. The tool takes the following input parameters:

  • database_name (optional): The database name to filter query stats for. The input is used within a LIKE clause. Default: "" (all databases).
  • limit (optional): The maximum number of results to return. Default: 50.

Example

tools:
  list_query_stats:
    kind: postgres-list-query-stats
    source: postgres-source
    description: List query statistics from pg_stat_statements, showing performance metrics for queries including execution counts, timing information, and resource usage. Results are ordered by total execution time descending.

The response is a json array with the following elements:

[
  {
    "datname": "database name",
    "query": "the SQL query text",
    "calls": "number of times the query was executed",
    "total_exec_time": "total execution time in milliseconds",
    "min_exec_time": "minimum execution time in milliseconds",
    "max_exec_time": "maximum execution time in milliseconds",
    "mean_exec_time": "mean execution time in milliseconds",
    "rows": "total number of rows retrieved or affected",
    "shared_blks_hit": "number of shared block cache hits",
    "shared_blks_read": "number of shared block disk reads"
  }
]

Notes

This tool requires the pg_stat_statements extension to be installed and enabled on the PostgreSQL database. The pg_stat_statements extension tracks execution statistics for all SQL statements executed by the server, which is useful for identifying slow queries and understanding query performance patterns.

Reference

field type required description
kind string true Must be "postgres-list-query-stats".
source string true Name of the source the SQL should execute on.
description string true Description of the tool that is passed to the LLM.