简体   繁体   English

事务空闲并使用 PostgreSQL 锁定

[英]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 :看着 PgAdmin 我有这个:

活动

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 ?你能帮助我吗 ?

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. “交易中的闲置”是指会话(在本例中为PID = 16686)开始了交易,并在商品goodscontract表上保留了一些锁。

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). 请注意,您看到的PID = 16686的选择很可能不是阻止更新的语句(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). PID = 16686很可能以前运行了获取锁的其他语句(或者select包含for update子句-因为您的屏幕快照未显示完整的语句,这是无法告诉的)。

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 select s. 通常,强烈建议尽快结束事务(使用commitrollback )-包括仅select s的只读事务。

two things need to be updated on postgresql.conf postgresql.conf 上需要更新两件事

idle_transaction_timeout idle_transaction_timeout

shared_memory共享内存

will solve the problem.将解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM