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

  • 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.

主站蜘蛛池模板: 汕头市| 阳西县| 济阳县| 平和县| 巴马| 奉贤区| 盈江县| 林口县| 屯留县| 廊坊市| 开平市| 清涧县| 固安县| 奉新县| 扶绥县| 贡嘎县| 威宁| 张家港市| 长阳| 浑源县| 襄垣县| 柳河县| 湾仔区| 邯郸县| 嘉定区| 富裕县| 临漳县| 通辽市| 岑溪市| 油尖旺区| 垣曲县| 石柱| 翁源县| 娱乐| 广安市| 磐安县| 黄陵县| 台州市| 格尔木市| 宁海县| 麻江县|