Idle-in-Transaction Sessions

Identify the cause of `idle in transaction` sessions. Continuously track transaction age and application ownership.

2026-09-06 · 2 min read

Why this problem matters

A session in idle in transaction retains an open transaction even while no statement is running. It may hold locks and keep the dead-row cleanup horizon from advancing.

How to diagnose it

Order sessions using xact_start, state_change, application, and client information. Time-series evidence distinguishes brief normal think time from a persistent application defect.

The query only lists sessions idle inside an open transaction. The displayed text is the last statement and does not mean it is currently executing.

SELECT pid, usename, application_name, client_addr, xact_start, state_change,
       clock_timestamp() - xact_start AS transaction_age,
       left(query, 200) AS last_query
FROM pg_stat_activity
WHERE state = 'idle in transaction'
ORDER BY xact_start;

A safe solution approach

Fix application transaction boundaries so connections do not retain open transactions while waiting for external work. Evaluate appropriate timeout policies only after testing production behavior.

Why continuous monitoring matters

moon helps continuously track the age and recurrence of these sessions with low overhead. Slack, PagerDuty, or webhook routing can notify the application owner early.

Frequently asked questions

Do idle and idle in transaction carry the same risk?

No, an ordinary idle session may have no open transaction. idle in transaction can retain transaction resources and affect the MVCC horizon.

How does moon help with this problem?

moon continuously observes SQL Server, PostgreSQL, and MongoDB signals, helping teams evaluate the problem as a trend instead of relying on a one-time check.