Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Idle in transaction and lock with PostgreSQL

I have a query that is locked. Thus my web application is locked and I don't really understand why.

Looking at the PgAdmin I have this :

Activities

If I understand correctly, the orange query has been blocked by the query just above (which is in "idle in transaction" state).

Does it mean that the "idle in transaction" transaction is not committed ? And is it because it is not committed that the other transaction is locked ?

If I commit the "idle in transaction" transaction, will it unlock the locked transaction ?

To be honest I don't really understand how I should interpret this. Can you help me ?

like image 441
Fabien Henon Avatar asked Sep 16 '25 10:09

Fabien Henon


1 Answers

Yor assumptions are correct. "idle in transaction" means the session (in this case PID=16686) started a transaction and is holding some locks on the goodscontract table.

Note that the select that you see for PID=16686 is most probably not the statement that is blocking the update (writers are not blocked by readers in Postgres). It is highly likely that PID=16686 ran a different statement previously that acquired the lock (or the select contains a for update clause - as your screenshot doesn't show the full statement this is impossible to tell).

In general it is highly recommended to end a transactions as soon as possible (using commit or rollback) - that includes read-only transactions that only do selects.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!