Menu

Postgres "idle in transaction" Sessions Are Blocking Your Migrations and Vacuum: Find Them, Fix the Code, Set a Timeout
📰

Postgres "idle in transaction" Sessions Are Blocking Your Migrations and Vacuum: Find Them, Fix the Code, Set a Timeout

DEV Community: postgres·Libme·1 day ago
#ShJdjske
Long article (1401 words) — no AI summary yet.
Reading 0:00
15s threshold

TL;DR: A session in the idle in transaction state has opened a transaction and is doing nothing, usually because application code is waiting on something else (an HTTP call, a user, a forgotten commit ). It keeps its locks and pins the oldest visible transaction, so migrations queue behind it and vacuum cannot clean up dead rows. Find the sessions in pg_stat_activity , fix the code path that holds a transaction open across slow work, and set idle_in_transaction_session_timeout as a backstop.

Behavior described here is accurate for current Postgres releases as of late 2026; the parameters I mention exist in the versions noted below.

How do I know this is my problem?

The symptoms are indirect, which is why this one takes people days. A migration that should take milliseconds hangs on ALTER TABLE . Table bloat grows even though autovacuum is running.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.