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

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.

主站蜘蛛池模板: 藁城市| 海宁市| 宣汉县| 富宁县| 玉屏| 南投县| 炉霍县| 张掖市| 民丰县| 屯门区| 嵩明县| 广安市| 分宜县| 太湖县| 木兰县| 临潭县| 姚安县| 梁山县| 昌黎县| 兴安县| 岱山县| 祥云县| 浑源县| 宜昌市| 搜索| 衡东县| 体育| 哈尔滨市| 莎车县| 连云港市| 金湖县| 新津县| 特克斯县| 江阴市| 逊克县| 淳安县| 呼和浩特市| 五指山市| 墨脱县| 津南区| 五台县|