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

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

主站蜘蛛池模板: 甘南县| 崇明县| 保康县| 观塘区| 清流县| 桂林市| 饶阳县| 宜兰市| 上杭县| 凌源市| 舒城县| 许昌市| 固始县| 墨竹工卡县| 山东| 宝清县| 宽城| 海丰县| 石家庄市| 盐池县| 兴化市| 广东省| 德兴市| 云南省| 乐东| 阿勒泰市| 环江| 连山| 周宁县| 绥化市| 枞阳县| 平乐县| 鄂托克前旗| 赣州市| 黑山县| 苗栗县| 云安县| 正镶白旗| 白水县| 灵丘县| 新巴尔虎左旗|