- 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.
- 大數據專業英語
- Google App Inventor
- 嵌入式Linux上的C語言編程實踐
- 統計學習理論與方法:R語言版
- PostgreSQL 10 Administration Cookbook
- Machine Learning with Apache Spark Quick Start Guide
- 貫通Java Web開發三劍客
- 網站入侵與腳本攻防修煉
- Silverlight 2完美征程
- Photoshop CS4數碼攝影處理50例
- Machine Learning with Spark(Second Edition)
- 筆記本電腦使用與維護
- 運動控制系統
- 開放自動化系統應用與實戰:基于標準建模語言IEC 61499
- Mastering Android Game Development with Unity