- 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.
- Mastering Spark for Data Science
- 人工智能超越人類
- R Data Mining
- Getting Started with Oracle SOA B2B Integration:A Hands-On Tutorial
- Hands-On Cybersecurity with Blockchain
- CompTIA Network+ Certification Guide
- Windows游戲程序設(shè)計基礎(chǔ)
- 大學(xué)C/C++語言程序設(shè)計基礎(chǔ)
- Excel 2007常見技法與行業(yè)應(yīng)用實(shí)例精講
- 激光選區(qū)熔化3D打印技術(shù)
- 自動化生產(chǎn)線安裝與調(diào)試(三菱FX系列)(第二版)
- 奇點(diǎn)將至
- AMK伺服控制系統(tǒng)原理及應(yīng)用
- 大數(shù)據(jù):引爆新的價值點(diǎn)
- Natural Language Processing and Computational Linguistics