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

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

主站蜘蛛池模板: 灵石县| 乐业县| 平江县| 和平县| 金溪县| 油尖旺区| 龙里县| 泊头市| 商水县| 旬阳县| 都匀市| 乐安县| 长白| 白玉县| 南澳县| 齐河县| 德保县| 甘肃省| 张北县| 来凤县| 弥勒县| 云南省| 岳阳县| 庆元县| 德兴市| 平南县| 巫溪县| 潢川县| 龙南县| 花莲县| 马公市| 潜江市| 遵化市| 蒙自县| 山阴县| 德钦县| 金坛市| 延川县| 阳谷县| 洛隆县| 高平市|