Find the bugs: long-running transactions

iv_sessions contains a snapshot of pg_stat_activity taken on February 1, 2026, at 12:00:00. Find sessions with transactions that have been open for more than 10 minutes. These transactions may hold locks and prevent VACUUM from cleaning up old row versions. List the oldest transactions first. Which lines of the query contain errors?

Find the errorsTransactions and locksMiddleBackendData Engineer
Input data · iv_sessions
pidstatexact_startquery_startquery
101active2026-02-01 11:59:582026-02-01 11:59:58SELECT * FROM iv_orders ORDER BY created_at DESC LIMIT 20
102idle in transaction2026-02-01 11:05:002026-02-01 11:05:02UPDATE iv_orders SET total = total - 10 WHERE customer_id = 2
103active2026-02-01 11:20:002026-02-01 11:59:30DELETE FROM iv_events WHERE user_id IS NULL
104idleNULL2026-02-01 09:00:00COMMIT
105active2026-02-01 11:40:002026-02-01 11:40:00SELECT customer_id, SUM(total) FROM iv_orders GROUP BY customer_id
106idle in transaction (aborted)2026-02-01 11:57:002026-02-01 11:57:10INSERT INTO iv_events (event_type) VALUES (NULL)
SELECT pid, state, xact_start, query
FROM iv_sessions
WHERE state = 'active'
  AND query_start < '2026-02-01 11:50:00'
ORDER BY xact_start