Skip to content

Idle transactions#

What it does

Shows sessions left idle inside a transaction beyond a specified duration.

$ pgcue run activity.idle_transactions

Use when

  • Vacuum cannot remove old row versions or tables are accumulating dead tuples.
  • Applications may be leaving transactions open between requests.

Inspect

  • Old transaction start times and long idle durations.
  • Repeated application names, users, or query patterns.

Result

Current state at execution time.

Columns#

Column Meaning
application_name Client-supplied application name.
database_name Database to which the session is connected.
duration Time elapsed since the transaction began.
pid PostgreSQL backend process ID.
query Most recently observed statement in the session.
state Current backend state.
transaction_started Time at which the current transaction began.
user_name Connected PostgreSQL role.

Parameters#

Option Type Default Description
--limit integer, minimum 1, accepts NULL 20 Maximum number of rows to show. Use NULL for no limit.
--minimum-duration duration 5m Minimum time a transaction must have remained open.

Privileges#

Without membership of pg_monitor, other sessions' query text and statistics may be hidden, and pgcue warns that results may be incomplete.

Compatibility#

  • PostgreSQL 14+

Used by investigations#