Files
genai-toolbox/docs/en/resources/tools/postgres/postgres-list-stored-procedure.md
Yuan Teoh 293c1d6889 feat!: update configuration file v2 (#2369)
This PR introduces a significant update to the Toolbox configuration
file format, which is one of the primary **breaking changes** required
for the implementation of the Advanced Control Plane.

# Summary of Changes
The configuration schema has been updated to enforce resource isolation
and facilitate atomic, incremental updates.
* Resource Isolation: Resource definitions are now separated into
individual blocks, using a distinct structure for each resource type
(Source, Tool, Toolset, etc.). This improves readability, management,
and auditing of configuration files.
* Field Name Modification: Internal field names have been modified to
align with declarative methodologies. Specifically, the configuration
now separates kind (general resource type, e.g., Source) from type
(specific implementation, e.g., Postgres).

# User Impact
Existing tools.yaml configuration files are now in an outdated format.
Users must eventually update their files to the new YAML format.

# Mitigation & Compatibility
Backward compatibility is maintained during this transition to ensure no
immediate user action is required for existing files.
* Immediate Backward Compatibility: The source code includes a
pre-processing layer that automatically detects outdated configuration
files (v1 format) and converts them to the new v2 format under the hood.
* [COMING SOON] Migration Support: The new toolbox migrate subcommand
will be introduced to allow users to automatically convert their old
configuration files to the latest format.

# Example
Example for config file v2:
```
kind: sources
name: my-pg-instance
type: cloud-sql-postgres
project: my-project
region: my-region
instance: my-instance
database: my_db
user: my_user
password: my_pass
---
kind: authServices
name: my-google-auth
type: google
clientId: testing-id
---
kind: tools
name: example_tool
type: postgres-sql
source: my-pg-instance
description: some description
statement: SELECT * FROM SQL_STATEMENT;
parameters:
- name: country
  type: string
  description: some description
---
kind: tools
name: example_tool_2
type: postgres-sql
source: my-pg-instance
description: returning the number one
statement: SELECT 1;
---
kind: toolsets
name: example_toolset
tools:
- example_tool
```

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Averi Kitsch <akitsch@google.com>
2026-01-27 16:58:43 -08:00

5.8 KiB

title, type, weight, description, aliases
title type weight description aliases
postgres-list-stored-procedure docs 1 The "postgres-list-stored-procedure" tool retrieves metadata for stored procedures in PostgreSQL, including procedure definitions, owners, languages, and descriptions.
/resources/tools/postgres-list-stored-procedure

About

The postgres-list-stored-procedure tool queries PostgreSQL system catalogs (pg_proc, pg_namespace, pg_roles, and pg_language) to retrieve comprehensive metadata about stored procedures in the database. It filters for procedures (kind = 'p') and provides the full procedure definition along with ownership and language information.

Compatible sources:

The tool returns a JSON array where each element represents a stored procedure with its schema, name, owner, language, complete definition, and optional description. Results are sorted by schema name and procedure name, with a default limit of 20 procedures.

Parameters

parameter type required default description
role_name string false null Optional: The owner name to filter stored procedures by (supports partial matching)
schema_name string false null Optional: The schema name to filter stored procedures by (supports partial matching)
limit integer false 20 Optional: The maximum number of stored procedures to return

Example

kind: tools
name: list_stored_procedure
type: postgres-list-stored-procedure
source: postgres-source
description: "Retrieves stored procedure metadata including definitions and owners."

Example Requests

List all stored procedures (default limit 20):

{}

Filter by specific owner (role):

{
  "role_name": "app_user"
}

Filter by schema:

{
  "schema_name": "public"
}

Filter by owner and schema with custom limit:

{
  "role_name": "postgres",
  "schema_name": "public",
  "limit": 50
}

Filter by partial schema name:

{
  "schema_name": "audit"
}

Example Response

[
  {
    "schema_name": "public",
    "name": "process_payment",
    "owner": "postgres",
    "language": "plpgsql",
    "definition": "CREATE OR REPLACE PROCEDURE public.process_payment(p_order_id integer, p_amount numeric)\n LANGUAGE plpgsql\nAS $procedure$\nBEGIN\n  UPDATE orders SET status = 'paid', amount = p_amount WHERE id = p_order_id;\n  INSERT INTO payment_log (order_id, amount, timestamp) VALUES (p_order_id, p_amount, now());\n  COMMIT;\nEND\n$procedure$",
    "description": "Processes payment for an order and logs the transaction"
  },
  {
    "schema_name": "public",
    "name": "cleanup_old_records",
    "owner": "postgres",
    "language": "plpgsql",
    "definition": "CREATE OR REPLACE PROCEDURE public.cleanup_old_records(p_days_old integer)\n LANGUAGE plpgsql\nAS $procedure$\nDECLARE\n  v_deleted integer;\nBEGIN\n  DELETE FROM audit_logs WHERE created_at < now() - (p_days_old || ' days')::interval;\n  GET DIAGNOSTICS v_deleted = ROW_COUNT;\n  RAISE NOTICE 'Deleted % records', v_deleted;\nEND\n$procedure$",
    "description": "Removes audit log records older than specified days"
  },
  {
    "schema_name": "audit",
    "name": "audit_table_changes",
    "owner": "app_user",
    "language": "plpgsql",
    "definition": "CREATE OR REPLACE PROCEDURE audit.audit_table_changes()\n LANGUAGE plpgsql\nAS $procedure$\nBEGIN\n  INSERT INTO audit.change_log (table_name, operation, changed_at) VALUES (TG_TABLE_NAME, TG_OP, now());\nEND\n$procedure$",
    "description": null
  }
]

Output Fields Reference

field type description
schema_name string Name of the schema containing the stored procedure.
name string Name of the stored procedure.
owner string PostgreSQL role/user who owns the stored procedure.
language string Programming language in which the procedure is written (e.g., plpgsql, sql, c).
definition string Complete SQL definition of the stored procedure, including the CREATE PROCEDURE statement.
description string Optional description or comment for the procedure (may be null if no comment is set).

Use Cases

  • Code review and auditing: Export procedure definitions for version control or compliance audits.
  • Documentation generation: Automatically extract procedure metadata and descriptions for documentation.
  • Permission auditing: Identify procedures owned by specific users or in specific schemas.
  • Migration planning: Retrieve all procedure definitions when planning database migrations.
  • Dependency analysis: Review procedure definitions to understand dependencies and call chains.
  • Security assessment: Audit which roles own and can modify stored procedures.

Performance Considerations

  • The tool filters at the database level using LIKE pattern matching, so partial matches are supported.
  • Procedure definitions can be large; consider using the limit parameter for large databases with many procedures.
  • Results are ordered by schema name and procedure name for consistent output.
  • The default limit of 20 procedures is suitable for most use cases; increase as needed.

Notes

  • Only stored procedures are returned; functions and other callable objects are excluded via the prokind = 'p' filter.
  • Filtering uses LIKE pattern matching, so filter values support partial matches (e.g., role_name: "app" will match "app_user", "app_admin", etc.).
  • The definition field contains the complete, runnable CREATE PROCEDURE statement.
  • The description field is populated from comments set via PostgreSQL's COMMENT command and may be null.