Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean when a PostgreSQL process is "idle in transaction"?

Tags:

postgresql

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.0.1(55658) idle in transaction

Does this mean that some of the processes are hung, waiting for a transaction to be committed? Any pointers to relevant documentation are appreciated.

like image 774
readonly Avatar asked Sep 09 '08 00:09

readonly


People also ask

Why does PostgreSQL say idle connection?

PostgreSQL connections consume memory and CPU resources even when idle. As queries are run on a connection, memory gets allocated. This memory isn't completely freed up even when the connection goes idle.

How do I stop Postgres automatically idle?

From PostgreSQL v14 on, you can set the idle_session_timeout parameter to automatically disconnect client sessions that are idle.

How do I find idle transactions?

If you want to see how many idle connections you have that have an open transaction, you could use: select * from pg_stat_activity where (state = 'idle in transaction') and xact_start is not null; This will provide a list of open connections that are in the idle state, that also have an open transaction.

Is there a timeout for idle PostgreSQL connections?

No, something akin to the other answers is required for previous versions. SET SESSION is just for the current session (it will go back to the default once you open a new connection).


2 Answers

The PostgreSQL manual indicates that this means the transaction is open (inside BEGIN) and idle. It's most likely a user connected using the monitor who is thinking or typing. I have plenty of those on my system, too.

If you're using Slony for replication, however, the Slony-I FAQ suggests idle in transaction may mean that the network connection was terminated abruptly. Check out the discussion in that FAQ for more details.

like image 56
Anonymoose Avatar answered Oct 26 '22 23:10

Anonymoose


As mentioned here: Re: BUG #4243: Idle in transaction it is probably best to check your pg_locks table to see what is being locked and that might give you a better clue where the problem lies.

like image 33
Arthur Thomas Avatar answered Oct 27 '22 00:10

Arthur Thomas