官术网_书友最值得收藏!

  • Mastering PostgreSQL 9.6
  • Hans Jurgen Schonig
  • 175字
  • 2021-07-09 19:57:09

Killing idle sessions

In PostgreSQL, a session or a transaction can basically live almost forever. In some cases, this has been a problem because transactions were kept open for too long. Usually, this was due to a bug. The trouble is this: insanely long transactions can cause cleanup problems and table bloat can occur. The uncontrolled growth of a table (table bloat) naturally leads to performance problems and unhappy end users.

Starting with PostgreSQL 9.6, it is possible to limit the duration a database connection is allowed to spend inside a transaction without performing real work. Here is how it works:

test=# SET idle_in_transaction_session_timeout TO 2500; 
SET
test=# BEGIN;
BEGIN
test=# SELECT 1;
?column?
----------
1
(1 row)

test=# SELECT 1;
FATAL: terminating connection due to idle-in-transaction timeout

Administrators and developers can set a timeout, which is 2.5 seconds in my example. As soon as a transaction is idle for too long, the connection will be terminated automatically by the server. Nasty side effects of long idle transactions can be prevented easily by adjusting this parameter.

主站蜘蛛池模板: 长沙市| 新和县| 石景山区| 凤台县| 济宁市| 隆昌县| 通江县| 青河县| 富源县| 龙山县| 肥城市| 广平县| 万源市| 桂阳县| 中牟县| 姜堰市| 裕民县| 勃利县| 乌什县| 鹰潭市| 台南市| 乡城县| 桐柏县| 志丹县| 上栗县| 仙桃市| 博白县| 襄樊市| 古田县| 田阳县| 永城市| 三门县| 鄂尔多斯市| 泌阳县| 东至县| 多伦县| 潞城市| 兴宁市| 驻马店市| 栾川县| 静乐县|