如何提交PostgreSQL中处于空闲状态的事务?

问题描述

有没有办法提交Postgres中处于空闲状态的事务?

如果我们使用idle_in_transaction_session_timeout会杀死并回滚事务,但是有什么方法可以提交和完成会话,我看不到任何被PID阻止的东西,我使用的是postgre10。 还是有什么办法可以阻止这些会话?所有这些似乎都是应用程序中孤立过程的结果。

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)

解决方法

那些是“空闲”会话,而不是“交易”。

空闲会话没有可以(或需要)提交的未决事务。

您无需执行任何操作

,

'ClientRead'表示它们被阻止,等待客户端发送另一个命令。它没有在做什么。如果它们在交易中,则该状态将被称为“交易中的空闲”,而不仅仅是“空闲”。您无法让他们提交,因为没有什么可以提交。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...