Files
genai-toolbox/docs/en/resources/tools/postgres/postgres-long-running-transactions.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

4.1 KiB

title, type, weight, description, aliases
title type weight description aliases
postgres-long-running-transactions docs 1 The postgres-long-running-transactions tool Identifies and lists database transactions that exceed a specified time limit. For each of the long running transactions, the output contains the process id, database name, user name, application name, client address, state, connection age, transaction age, query age, last activity age, wait event type, wait event, and query string.
/resources/tools/postgres-long-running-transactions

About

The postgres-long-running-transactions tool reports transactions that exceed a configured duration threshold by scanning pg_stat_activity for sessions where xact_start is set and older than the configured interval.

Compatible sources:

The tool returns a JSON array with one object per matching session (non-idle). Each object contains the process id, database and user, application name, client address, session state, several age intervals (connection, transaction, query, and last activity), wait event info, and the SQL text currently associated with the session.

Parameters:

  • min_duration (optional): Only show transactions running at least this long (Postgres interval format, e.g., '5 minutes'). Default: 5 minutes.
  • limit (optional): Maximum number of results to return. Default: 20.

Query

The SQL used by the tool looks like:

SELECT
  pid,
  datname,
  usename,
  application_name as appname,
  client_addr,
  state,
  now() - backend_start as conn_age,
  now() - xact_start as xact_age,
  now() - query_start as query_age,
  now() - state_change as last_activity_age,
  wait_event_type,
  wait_event,
  query
FROM
  pg_stat_activity
WHERE
  state <> 'idle'
  AND (now() - xact_start) > COALESCE($1::INTERVAL, interval '5 minutes')
  AND xact_start IS NOT NULL
  AND pid <> pg_backend_pid()
ORDER BY
  xact_age DESC
LIMIT 
  COALESCE($2::int, 20);

Example

kind: tools
name: long_running_transactions
type: postgres-long-running-transactions
source: postgres-source
description: "Identifies transactions open longer than a threshold and returns details including query text and durations."

Example response element:

{
  "pid": 12345,
  "datname": "my_database",
  "usename": "dbuser",
  "appname": "my_app",
  "client_addr": "10.0.0.5",
  "state": "idle in transaction",
  "conn_age": "00:12:34",
  "xact_age": "00:06:00",
  "query_age": "00:02:00",
  "last_activity_age": "00:01:30",
  "wait_event_type": null,
  "wait_event": null,
  "query": "UPDATE users SET last_seen = now() WHERE id = 42;"
}

Reference

field type required description
pid integer true Process id (backend pid).
datname string true Database name.
usename string true Database user name.
appname string false Application name (client application).
client_addr string false Client IPv4/IPv6 address (may be null for local connections).
state string true Session state (e.g., active, idle in transaction).
conn_age string true Age of the connection: now() - backend_start (Postgres interval serialized as string).
xact_age string true Age of the transaction: now() - xact_start (Postgres interval serialized as string).
query_age string true Age of the currently running query: now() - query_start (Postgres interval serialized as string).
last_activity_age string true Time since last state change: now() - state_change (Postgres interval serialized as string).
wait_event_type string false Type of event the backend is waiting on (may be null).
wait_event string false Specific wait event name (may be null).
query string true SQL text associated with the session.