【问题标题】:How to commit the transaction that are in idle state in PostgreSQL?如何提交 PostgreSQL 中处于空闲状态的事务?
【发布时间】:2020-08-22 04:16:45
【问题描述】:

有没有办法在 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)

【问题讨论】:

    标签: postgresql postgresql-10 database-tuning


    【解决方案1】:

    那些是“空闲”的会话,而不是事务。

    空闲会话没有可以(或需要)提交的待处理事务。

    你不需要做任何事情

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 这些是应用程序孤儿进程的结果,有什么办法可以处理这种事务,我不想杀死它们,因为它可能会导致数据丢失?
      • 他们已经提交了。连接没有可丢失的数据。也许应用程序有从未发送到数据库的数据,但你不能从数据库中做任何事情。解决问题的方法是修复应用程序。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-20
      • 1970-01-01
      • 2019-01-05
      • 1970-01-01
      • 2015-06-22
      • 1970-01-01
      • 2022-10-01
      相关资源
      最近更新 更多