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

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.

主站蜘蛛池模板: 通城县| 防城港市| 渑池县| 西乌珠穆沁旗| 安丘市| 永修县| 丹阳市| 建平县| 呼伦贝尔市| 内乡县| 霍山县| 浦江县| 合江县| 抚顺市| 涞源县| 佛冈县| 黄龙县| 康保县| 香河县| 开鲁县| 常宁市| 兴国县| 南乐县| 万源市| 法库县| 泰和县| 凌云县| 出国| 华容县| 鄯善县| 太保市| 灵宝市| 聊城市| 拜泉县| 安宁市| 定安县| 松阳县| 郯城县| 宁河县| 五华县| 阳泉市|