Skip to content

Commit 3624808

Browse files
feat(tools/postgres): add list_pg_settings, list_database_stats tools for postgres
1 parent a539c71 commit 3624808

File tree

20 files changed

+1191
-11
lines changed

20 files changed

+1191
-11
lines changed

cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,11 @@ import (
181181
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgresexecutesql"
182182
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistactivequeries"
183183
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistavailableextensions"
184+
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistdatabasestats"
184185
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistindexes"
185186
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistinstalledextensions"
186187
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistlocks"
188+
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistpgsettings"
187189
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistschemas"
188190
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslistsequences"
189191
_ "github.com/googleapis/genai-toolbox/internal/tools/postgres/postgreslisttables"

cmd/root_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,7 +1478,7 @@ func TestPrebuiltTools(t *testing.T) {
14781478
wantToolset: server.ToolsetConfigs{
14791479
"alloydb_postgres_database_tools": tools.ToolsetConfig{
14801480
Name: "alloydb_postgres_database_tools",
1481-
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"},
1481+
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_pg_settings", "list_database_stats"},
14821482
},
14831483
},
14841484
},
@@ -1508,7 +1508,7 @@ func TestPrebuiltTools(t *testing.T) {
15081508
wantToolset: server.ToolsetConfigs{
15091509
"cloud_sql_postgres_database_tools": tools.ToolsetConfig{
15101510
Name: "cloud_sql_postgres_database_tools",
1511-
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"},
1511+
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_pg_settings", "list_database_stats"},
15121512
},
15131513
},
15141514
},
@@ -1608,7 +1608,7 @@ func TestPrebuiltTools(t *testing.T) {
16081608
wantToolset: server.ToolsetConfigs{
16091609
"postgres_database_tools": tools.ToolsetConfig{
16101610
Name: "postgres_database_tools",
1611-
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"},
1611+
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_pg_settings", "list_database_stats"},
16121612
},
16131613
},
16141614
},

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

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

228234
## Cloud SQL for PostgreSQL Observability
229235

@@ -525,6 +531,9 @@ details on how to connect your AI tools (IDEs) to databases via Toolbox and MCP.
525531
* `list_triggers`: Lists triggers in the database.
526532
* `list_indexes`: List available user indexes in a PostgreSQL database.
527533
* `list_sequences`: List sequences in a PostgreSQL database.
534+
* `list_pg_settings`: List configuration parameters for the PostgreSQL server.
535+
* `list_database_stats`: Lists the key performance and activity statistics for
536+
each database in the PostgreSQL server.
528537

529538
## Google Cloud Serverless for Apache Spark
530539

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ cluster][alloydb-free-trial].
7171
- [`postgres-replication-stats`](../tools/postgres/postgres-replication-stats.md)
7272
List replication stats in a PostgreSQL database.
7373

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

7683
- [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
@@ -67,6 +67,13 @@ to a database by following these instructions][csql-pg-quickstart].
6767
- [`postgres-replication-stats`](../tools/postgres/postgres-replication-stats.md)
6868
List replication stats in a PostgreSQL database.
6969

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

7279
- [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
@@ -62,6 +62,13 @@ reputation for reliability, feature robustness, and performance.
6262
- [`postgres-replication-stats`](../tools/postgres/postgres-replication-stats.md)
6363
List replication stats in a PostgreSQL database.
6464

65+
- [`postgres-list-pg-settings`](../tools/postgres/postgres-list-pg-settings.md)
66+
List configuration parameters for the PostgreSQL server.
67+
68+
- [`postgres-list-database-stats`](../tools/postgres/postgres-list-database-stats.md)
69+
Lists the key performance and activity statistics for each database in the postgreSQL
70+
server.
71+
6572
### Pre-built Configurations
6673

6774
- [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
@@ -192,6 +192,14 @@ tools:
192192
kind: postgres-list-triggers
193193
source: alloydb-pg-source
194194

195+
list_pg_settings:
196+
kind: postgres-list-pg-settings
197+
source: alloydb-pg-source
198+
199+
list_database_stats:
200+
kind: postgres-list-database-stats
201+
source: alloydb-pg-source
202+
195203
toolsets:
196204
alloydb_postgres_database_tools:
197205
- execute_sql
@@ -214,4 +222,6 @@ toolsets:
214222
- long_running_transactions
215223
- list_locks
216224
- replication_stats
225+
- list_pg_settings
226+
- list_database_stats
217227

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@ tools:
194194
kind: postgres-list-sequences
195195
source: cloudsql-pg-source
196196

197+
list_pg_settings:
198+
kind: postgres-list-pg-settings
199+
source: cloudsql-pg-source
200+
201+
list_database_stats:
202+
kind: postgres-list-database-stats
203+
source: cloudsql-pg-source
204+
197205
toolsets:
198206
cloud_sql_postgres_database_tools:
199207
- execute_sql
@@ -216,3 +224,5 @@ toolsets:
216224
- long_running_transactions
217225
- list_locks
218226
- replication_stats
227+
- list_pg_settings
228+
- list_database_stats

0 commit comments

Comments
 (0)