Skip to content

Commit e371d68

Browse files
feat(tools/postgres): add list_pg_settings, list_database_stats tools for postgres
1 parent 0e7fbf4 commit e371d68

File tree

20 files changed

+1190
-13
lines changed

20 files changed

+1190
-13
lines changed

cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,11 @@ import (
184184
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgresgetcolumncardinality"
185185
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistactivequeries"
186186
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistavailableextensions"
187+
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistdatabasestats"
187188
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistindexes"
188189
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistinstalledextensions"
189190
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistlocks"
191+
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistpgsettings"
190192
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistquerystats"
191193
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistschemas"
192194
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistsequences"

cmd/root_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,7 @@ func TestPrebuiltTools(t *testing.T) {
14881488
wantToolset: server.ToolsetConfigs{
14891489
"alloydb_postgres_database_tools": tools.ToolsetConfig{
14901490
Name: "alloydb_postgres_database_tools",
1491-
ToolNames: []string{"execute_sql", "list_tables", "list_active_queries", "list_available_extensions", "list_installed_extensions", "list_autovacuum_configurations", "list_memory_configurations", "list_top_bloated_tables", "list_replication_slots", "list_invalid_indexes", "get_query_plan", "list_views", "list_schemas", "database_overview", "list_triggers", "list_indexes", "list_sequences", "long_running_transactions", "list_locks", "replication_stats", "list_query_stats", "get_column_cardinality"},
1491+
ToolNames: []string{"execute_sql", "list_tables", "list_active_queries", "list_available_extensions", "list_installed_extensions", "list_autovacuum_configurations", "list_memory_configurations", "list_top_bloated_tables", "list_replication_slots", "list_invalid_indexes", "get_query_plan", "list_views", "list_schemas", "database_overview", "list_triggers", "list_indexes", "list_sequences", "long_running_transactions", "list_locks", "replication_stats", "list_query_stats", "get_column_cardinality", "list_pg_settings", "list_database_stats"},
14921492
},
14931493
},
14941494
},
@@ -1518,7 +1518,7 @@ func TestPrebuiltTools(t *testing.T) {
15181518
wantToolset: server.ToolsetConfigs{
15191519
"cloud_sql_postgres_database_tools": tools.ToolsetConfig{
15201520
Name: "cloud_sql_postgres_database_tools",
1521-
ToolNames: []string{"execute_sql", "list_tables", "list_active_queries", "list_available_extensions", "list_installed_extensions", "list_autovacuum_configurations", "list_memory_configurations", "list_top_bloated_tables", "list_replication_slots", "list_invalid_indexes", "get_query_plan", "list_views", "list_schemas", "database_overview", "list_triggers", "list_indexes", "list_sequences", "long_running_transactions", "list_locks", "replication_stats", "list_query_stats", "get_column_cardinality"},
1521+
ToolNames: []string{"execute_sql", "list_tables", "list_active_queries", "list_available_extensions", "list_installed_extensions", "list_autovacuum_configurations", "list_memory_configurations", "list_top_bloated_tables", "list_replication_slots", "list_invalid_indexes", "get_query_plan", "list_views", "list_schemas", "database_overview", "list_triggers", "list_indexes", "list_sequences", "long_running_transactions", "list_locks", "replication_stats", "list_query_stats", "get_column_cardinality", "list_pg_settings", "list_database_stats"},
15221522
},
15231523
},
15241524
},
@@ -1618,7 +1618,7 @@ func TestPrebuiltTools(t *testing.T) {
16181618
wantToolset: server.ToolsetConfigs{
16191619
"postgres_database_tools": tools.ToolsetConfig{
16201620
Name: "postgres_database_tools",
1621-
ToolNames: []string{"execute_sql", "list_tables", "list_active_queries", "list_available_extensions", "list_installed_extensions", "list_autovacuum_configurations", "list_memory_configurations", "list_top_bloated_tables", "list_replication_slots", "list_invalid_indexes", "get_query_plan", "list_views", "list_schemas", "database_overview", "list_triggers", "list_indexes", "list_sequences", "long_running_transactions", "list_locks", "replication_stats", "list_query_stats", "get_column_cardinality"},
1621+
ToolNames: []string{"execute_sql", "list_tables", "list_active_queries", "list_available_extensions", "list_installed_extensions", "list_autovacuum_configurations", "list_memory_configurations", "list_top_bloated_tables", "list_replication_slots", "list_invalid_indexes", "get_query_plan", "list_views", "list_schemas", "database_overview", "list_triggers", "list_indexes", "list_sequences", "long_running_transactions", "list_locks", "replication_stats", "list_query_stats", "get_column_cardinality", "list_pg_settings", "list_database_stats"},
16221622
},
16231623
},
16241624
},

docs/en/reference/prebuilt-tools.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ details on how to connect your AI tools (IDEs) to databases via Toolbox and MCP.
5050
* `list_triggers`: Lists triggers in the database.
5151
* `list_indexes`: List available user indexes in a PostgreSQL database.
5252
* `list_sequences`: List sequences in a PostgreSQL database.
53+
* `list_pg_settings`: List configuration parameters for the PostgreSQL server.
54+
* `list_database_stats`: Lists the key performance and activity statistics for
55+
each database in the AlloyDB instance.
5356

5457
## AlloyDB Postgres Admin
5558

@@ -227,6 +230,9 @@ details on how to connect your AI tools (IDEs) to databases via Toolbox and MCP.
227230
* `list_triggers`: Lists triggers in the database.
228231
* `list_indexes`: List available user indexes in a PostgreSQL database.
229232
* `list_sequences`: List sequences in a PostgreSQL database.
233+
* `list_pg_settings`: List configuration parameters for the PostgreSQL server.
234+
* `list_database_stats`: Lists the key performance and activity statistics for
235+
each database in the postgreSQL instance.
230236

231237
## Cloud SQL for PostgreSQL Observability
232238

@@ -532,6 +538,9 @@ details on how to connect your AI tools (IDEs) to databases via Toolbox and MCP.
532538
* `list_triggers`: Lists triggers in the database.
533539
* `list_indexes`: List available user indexes in a PostgreSQL database.
534540
* `list_sequences`: List sequences in a PostgreSQL database.
541+
* `list_pg_settings`: List configuration parameters for the PostgreSQL server.
542+
* `list_database_stats`: Lists the key performance and activity statistics for
543+
each database in the PostgreSQL server.
535544

536545
## Google Cloud Serverless for Apache Spark
537546

docs/en/resources/sources/alloydb-pg.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ cluster][alloydb-free-trial].
7777
- [`postgres-get-column-cardinality`](../tools/postgres/postgres-get-column-cardinality.md)
7878
List cardinality of columns in a table in a PostgreSQL database.
7979

80+
- [`postgres-list-pg-settings`](../tools/postgres/postgres-list-pg-settings.md)
81+
List configuration parameters for the PostgreSQL server.
82+
83+
- [`postgres-list-database-stats`](../tools/postgres/postgres-list-database-stats.md)
84+
Lists the key performance and activity statistics for each database in the AlloyDB
85+
instance.
86+
8087
### Pre-built Configurations
8188

8289
- [AlloyDB using MCP](https://googleapis.github.io/genai-toolbox/how-to/connect-ide/alloydb_pg_mcp/)

docs/en/resources/sources/cloud-sql-pg.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ to a database by following these instructions][csql-pg-quickstart].
7373
- [`postgres-get-column-cardinality`](../tools/postgres/postgres-get-column-cardinality.md)
7474
List cardinality of columns in a table in a PostgreSQL database.
7575

76+
- [`postgres-list-pg-settings`](../tools/postgres/postgres-list-pg-settings.md)
77+
List configuration parameters for the PostgreSQL server.
78+
79+
- [`postgres-list-database-stats`](../tools/postgres/postgres-list-database-stats.md)
80+
Lists the key performance and activity statistics for each database in the postgreSQL
81+
instance.
82+
7683
### Pre-built Configurations
7784

7885
- [Cloud SQL for Postgres using

docs/en/resources/sources/postgres.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ reputation for reliability, feature robustness, and performance.
6868
- [`postgres-get-column-cardinality`](../tools/postgres/postgres-get-column-cardinality.md)
6969
List cardinality of columns in a table in a PostgreSQL database.
7070

71+
- [`postgres-list-pg-settings`](../tools/postgres/postgres-list-pg-settings.md)
72+
List configuration parameters for the PostgreSQL server.
73+
74+
- [`postgres-list-database-stats`](../tools/postgres/postgres-list-database-stats.md)
75+
Lists the key performance and activity statistics for each database in the postgreSQL
76+
server.
77+
7178
### Pre-built Configurations
7279

7380
- [PostgreSQL using MCP](https://googleapis.github.io/genai-toolbox/how-to/connect-ide/postgres_mcp/)
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
title: "postgres-list-database-stats"
3+
type: docs
4+
weight: 1
5+
description: >
6+
The "postgres-list-database-stats" tool lists lists key performance and activity statistics of PostgreSQL databases.
7+
aliases:
8+
- /resources/tools/postgres-list-database-stats
9+
---
10+
11+
## About
12+
13+
The `postgres-list-database-stats` lists the key performance and activity statistics for each PostgreSQL database in the instance, offering insights into cache efficiency, transaction throughput, row-level activity, temporary file usage, and contention. It's compatible with
14+
any of the following sources:
15+
16+
- [alloydb-postgres](../../sources/alloydb-pg.md)
17+
- [cloud-sql-postgres](../../sources/cloud-sql-pg.md)
18+
- [postgres](../../sources/postgres.md)
19+
20+
`postgres-list-database-stats` lists detailed information as JSON for each database. The tool
21+
takes the following input parameters:
22+
23+
- `database_name` (optional): A text to filter results by database name. Default: `""`
24+
- `include_templates` (optional): Boolean, set to `true` to include template databases in the results. Default: `false`
25+
- `database_owner` (optional): A text to filter results by database owner. Default: `""`
26+
- `default_tablespace` (optional): A text to filter results by the default tablespace name. Default: `""`
27+
- `order_by` (optional): Specifies the sorting order. Valid values are `'size'` (descending) or `'commit'` (descending). Default: `database_name` ascending.
28+
- `limit` (optional): The maximum number of databases to return. Default: `10`
29+
30+
## Example
31+
32+
```yaml
33+
tools:
34+
list_database_stats:
35+
kind: postgres-list-database-stats
36+
source: postgres-source
37+
description: |
38+
Lists the key performance and activity statistics for each PostgreSQL
39+
database in the instance, offering insights into cache efficiency,
40+
transaction throughput row-level activity, temporary file usage, and
41+
contention. It returns: the database name, whether the database is
42+
connectable, database owner, default tablespace name, the percentage of
43+
data blocks found in the buffer cache rather than being read from disk
44+
(a higher value indicates better cache performance), the total number of
45+
disk blocks read from disk, the total number of times disk blocks were
46+
found already in the cache; the total number of committed transactions,
47+
the total number of rolled back transactions, the percentage of rolled
48+
back transactions compared to the total number of completed
49+
transactions, the total number of rows returned by queries, the total
50+
number of live rows fetched by scans, the total number of rows inserted,
51+
the total number of rows updated, the total number of rows deleted, the
52+
number of temporary files created by queries, the total size of
53+
temporary files used by queries in bytes, the number of query
54+
cancellations due to conflicts with recovery, the number of deadlocks
55+
detected, the current number of active backend connections, the
56+
timestamp when the database statistics were last reset, and the total
57+
database size in bytes.
58+
```
59+
60+
The response is a json array with the following elements:
61+
62+
```json
63+
{
64+
"database_name": "Name of the database",
65+
"is_connectable": "Boolean indicating Whether the database allows connections",
66+
"database_owner": "Username of the database owner",
67+
"default_tablespace": "Name of the default tablespace for the database",
68+
"cache_hit_ratio_percent": "The percentage of data blocks found in the buffer cache rather than being read from disk",
69+
"blocks_read_from_disk": "The total number of disk blocks read for this database",
70+
"blocks_hit_in_cache": "The total number of times disk blocks were found already in the cache.",
71+
"xact_commit": "The total number of committed transactions",
72+
"xact_rollback": "The total number of rolled back transactions",
73+
"rollback_ratio_percent": "The percentage of rolled back transactions compared to the total number of completed transactions",
74+
"rows_returned_by_queries": "The total number of rows returned by queries",
75+
"rows_fetched_by_scans": "The total number of live rows fetched by scans",
76+
"tup_inserted": "The total number of rows inserted",
77+
"tup_updated": "The total number of rows updated",
78+
"tup_deleted": "The total number of rows deleted",
79+
"temp_files": "The number of temporary files created by queries",
80+
"temp_size_bytes": "The total size of temporary files used by queries in bytes",
81+
"conflicts": "Number of query cancellations due to conflicts",
82+
"deadlocks": "Number of deadlocks detected",
83+
"active_connections": "The current number of active backend connections",
84+
"statistics_last_reset": "The timestamp when the database statistics were last reset",
85+
"database_size_bytes": "The total disk size of the database in bytes"
86+
}
87+
```
88+
89+
## Reference
90+
91+
| **field** | **type** | **required** | **description** |
92+
|-------------|:--------:|:------------:|------------------------------------------------------|
93+
| kind | string | true | Must be "postgres-list-database-stats". |
94+
| source | string | true | Name of the source the SQL should execute on. |
95+
| description | string | false | Description of the tool that is passed to the agent. |
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: "postgres-list-pg-settings"
3+
type: docs
4+
weight: 1
5+
description: >
6+
The "postgres-list-pg-settings" tool lists PostgreSQL run-time configuration settings.
7+
aliases:
8+
- /resources/tools/postgres-list-pg-settings
9+
---
10+
11+
## About
12+
13+
The `postgres-list-pg-settings` tool lists the configuration parameters for the postgres server, their current values, and related information. It's compatible with any of the following sources:
14+
15+
- [alloydb-postgres](../../sources/alloydb-pg.md)
16+
- [cloud-sql-postgres](../../sources/cloud-sql-pg.md)
17+
- [postgres](../../sources/postgres.md)
18+
19+
`postgres-list-pg-settings` lists detailed information as JSON for each setting. The tool
20+
takes the following input parameters:
21+
22+
- `name` (optional): A text to filter results by setting name. Default: `""`
23+
- `limit` (optional): The maximum number of rows to return. Default: `50`.
24+
25+
## Example
26+
27+
```yaml
28+
tools:
29+
list_indexes:
30+
kind: postgres-list-pg-settings
31+
source: postgres-source
32+
description: |
33+
Lists configuration parameters for the postgres server ordered lexicographically,
34+
with a default limit of 50 rows. It returns the parameter name, its current setting,
35+
unit of measurement, a short description, the source of the current setting (e.g.,
36+
default, configuration file, session), and whether a restart is required when the
37+
parameter value is changed."
38+
```
39+
40+
The response is a json array with the following elements:
41+
42+
```json
43+
{
44+
"name": "Setting name",
45+
"current_value": "Current value of the setting",
46+
"unit": "Unit of the setting",
47+
"short_desc": "Short description of the setting",
48+
"source": "Source of the current value (e.g., default, configuration file, session)",
49+
"requires_restart": "Indicates if a server restart is required to apply a change ('Yes', 'No', or 'No (Reload sufficient)')"
50+
}
51+
```
52+
53+
## Reference
54+
55+
| **field** | **type** | **required** | **description** |
56+
|-------------|:--------:|:------------:|------------------------------------------------------|
57+
| kind | string | true | Must be "postgres-list-pg-settings". |
58+
| source | string | true | Name of the source the SQL should execute on. |
59+
| description | string | false | Description of the tool that is passed to the agent. |

internal/prebuiltconfigs/tools/alloydb-postgres.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,14 @@ tools:
200200
kind: postgres-get-column-cardinality
201201
source: alloydb-pg-source
202202

203+
list_pg_settings:
204+
kind: postgres-list-pg-settings
205+
source: alloydb-pg-source
206+
207+
list_database_stats:
208+
kind: postgres-list-database-stats
209+
source: alloydb-pg-source
210+
203211
toolsets:
204212
alloydb_postgres_database_tools:
205213
- execute_sql
@@ -222,5 +230,7 @@ toolsets:
222230
- long_running_transactions
223231
- list_locks
224232
- replication_stats
233+
- list_pg_settings
234+
- list_database_stats
225235
- list_query_stats
226236
- get_column_cardinality

internal/prebuiltconfigs/tools/cloud-sql-postgres.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,14 @@ tools:
202202
kind: postgres-get-column-cardinality
203203
source: cloudsql-pg-source
204204

205+
list_pg_settings:
206+
kind: postgres-list-pg-settings
207+
source: cloudsql-pg-source
208+
209+
list_database_stats:
210+
kind: postgres-list-database-stats
211+
source: cloudsql-pg-source
212+
205213
toolsets:
206214
cloud_sql_postgres_database_tools:
207215
- execute_sql
@@ -226,3 +234,5 @@ toolsets:
226234
- replication_stats
227235
- list_query_stats
228236
- get_column_cardinality
237+
- list_pg_settings
238+
- list_database_stats

0 commit comments

Comments
 (0)