简体   繁体   English

如何在 PostgreSQL 中提交处于空闲 state 的事务?

[英]How to commit the transaction that are in idle state in PostgreSQL?

Is there a way to commit a transaction that is in an idle state in Postgres?有没有办法提交 Postgres 中空闲 state 中的事务?

If we use idle_in_transaction_session_timeout it kills and rollbacks the transaction, but is there any way to commit and complete the session, I can't see any blocked by PID, I am using postgre10.如果我们使用 idle_in_transaction_session_timeout 它会杀死并回滚事务,但是有什么方法可以提交和完成 session,我看不到任何被 PID 阻止,我使用的是 postgre10。 Or is there any way I can find what is blocking these sessions?或者有什么方法可以找到阻止这些会话的原因吗? all these seem to be the result of the orphan processes from the application.所有这些似乎都是应用程序孤儿进程的结果。

APPNEW=# SELECT datname
APPNEW-# ,pid
APPNEW-# , usename
APPNEW-# , wait_event_type
APPNEW-# , wait_event
APPNEW-# ,backend_start
APPNEW-# ,state
APPNEW-# , pg_blocking_pids(pid) AS blocked_by
APPNEW-# ,query
APPNEW-# FROM pg_stat_activity
APPNEW-# WHERE wait_event IS NOT NULL
APPNEW-# order by backend_start;
 datname |  pid  |   usename   | wait_event_type |     wait_event      |         backend_start         |        state        | blocked_by | query
---------+-------+-------------+-----------------+---------------------+-------------------------------+---------------------+------------+--------------------------------------------------
 APPNEW   |  4227 | appnew     | Client          | ClientRead          | 2020-07-26 14:28:26.956884+12 | idle                | {}         | BEGIN;commit
 APPNEW   |  4305 | appnew     | Client          | ClientRead          | 2020-07-26 14:28:35.955987+12 | idle                | {}         | BEGIN;commit
 APPNEW   |  4314 | appnew     | Client          | ClientRead          | 2020-07-26 14:28:36.002783+12 | idle                | {}         | commit
 APPNEW   |  4323 | appnew     | Client          | ClientRead          | 2020-07-26 14:28:36.046023+12 | idle                | {}         | BEGIN;commit
 APPNEW   |  4332 | appnew     | Client          | ClientRead          | 2020-07-26 14:28:36.088676+12 | idle                | {}         | commit
 APPNEW   |  4341 | appnew     | Client          | ClientRead          | 2020-07-26 14:28:36.137323+12 | idle                | {}         | BEGIN;commit
 APPNEW   |  4350 | appnew     | Client          | ClientRead          | 2020-07-26 14:28:36.185843+12 | idle                | {}         | commit
 APPNEW   |  4359 | appnew     | Client          | ClientRead          | 2020-07-26 14:28:36.227245+12 | idle                | {}         | BEGIN;commit
 APPNEW   |  4368 | appnew     | Client          | ClientRead          | 2020-07-26 14:28:36.288329+12 | idle                | {}         | commit
 APPNEW   |  4377 | appnew     | Client          | ClientRead          | 2020-07-26 14:28:36.337534+12 | idle                | {}         | commit
 APPNEW   |  4386 | appnew     | Client          | ClientRead          | 2020-07-26 14:28:36.402352+12 | idle                | {}         | commit
 APPNEW   |  4395 | appnew     | Client          | ClientRead          | 2020-07-26 14:28:36.439634+12 | idle                | {}         | commit
 APPNEW   |  4404 | appnew     | Client          | ClientRead          | 2020-07-26 14:28:36.481263+12 | idle                | {}         | commit
 .
 .
 (240 rows)

Those are sessions that are "idle", not transactions.这些是“空闲”的会话,而不是事务。

An idle session has no pending transaction that can (or needs to) be committed.空闲的 session 没有可以(或需要)提交的待处理事务。

There is nothing you need to do您无需做任何事情

'ClientRead' means they are blocked waiting for the client to send another command. 'ClientRead' 表示它们被阻止等待客户端发送另一个命令。 Which it is not doing.它没有这样做。 If they were inside a transaction, the state would be called 'idle in transaction', not just 'idle'.如果它们在事务中,则 state 将被称为“事务中的空闲”,而不仅仅是“空闲”。 You can't make them commit, as there is nothing to commit.你不能让他们提交,因为没有什么可提交的。

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

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