Postgres idle From PostgreSQL 9. The locks remain (and are of course granted, otherwise the session could not be idle) until the transaction ends. Then pg_terminate_backend worked. What we're seeing: 'idle in transaction' queries on the DB that hang out for a long time. I am using Postgres for one of my applications and sometimes (not very frequently) one of the connection goes into <IDLE> in transaction state and it keeps acquired lock that causes other connections to wait on these locks ultimately causing my application to hang. What worked was first setting idle_in_transaction_session_timeout to a value bellow the runtime of the idle query. But meanwhile, we want to set a timeout for these idle connections, maybe max to 5 minute. However, those threads connect to the database with different user. select * from pg_stat_activity; What does it mean when a PostgreSQL process is "idle in transaction"? On a server that I'm looking at, the output of "ps ax | grep postgres" I see 9 PostgreSQL processes that look like the following: postgres: user db 127. 0. In order to see them, I'll run something like this: SELECT query_start, procpid, client_addr, current_query FROM pg_stat_activity WHERE query_start < NOW() - interval '5 minutes'; postgres "idle in transaction" for 13 hours. @Priya:- How about creating a cron job and then execute this query with that cron job: SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'regress' AND pid <> pg_backend_pid() AND state = 'idle' AND state_change < current_timestamp - INTERVAL '10' MINUTE; You can change the time from 10 minutes to whatever time you want. There are additional threads that do the same as above. We are trying to fix our connection leak. 0. How to handle idle in transaction in python for Postgres? 2. Following is the output from pg_stat_activity table for that process: 00:00:00 postgres: postgres my_app ::1(43084) idle I see a lot of them. What does it mean when a PostgreSQL process is "idle in transaction"? On a server that I'm looking at, the output of "ps ax | grep postgres" I see 9 PostgreSQL processes that look like the following: postgres: user db 127. Then SET SESSION idle_in_transaction_session_timeout=<new value>. select * from pg_stat_activity;. Which should be sufficient, by the way max-active: 10 max-idle: 10 min-idle: 5 max-wait: 30000 time-between-eviction-runs-millis: 5000 min-evictable-idle-time-millis: 60000 jmx-enabled: true Now Its creating 5 Idle connection to DB. 1(55658) idle in transaction Does this mean that some of the processes are hung, waiting for a transaction to be committed? A connection is considered inactive if its state is either idle, idle in transaction, idle in transaction (aborted) or disabled. A connection is considered old if its state stayed the same during more than 5 minutes. If you want to set it back to the value it was before, use SHOW idle_in_transaction_session_timeout. I am verifying that by executing below query. 6 on, you can set the parameter idle_in_transaction_session_timeout to terminate such transactions automatically with a ROLLBACK, but that is a band-aid to avoid problems on the database rather than a solution. pwfyatkt etfaao fegx ydxcrn acwdby slgf zcxa ewxoyji bpkq vhpaabu