神刀安全网

Hubert 'depesz' Lubaczewski: Waiting for 9.6 – Add idle_in_transaction_session_timeout.

On 16th of March, Robert Haas committed patch:

Add idle_in_transaction_session_timeout.   Vik Fearing, reviewed by Stéphane Schildknecht and me, and revised slightly by me.

This is something amazing.

I hate “idle in transaction" connections. These cause lots of problems, and while are generally easy to solve, in times where we have orms, web frameworks, various “work flows" in companies, and lots of developers – in many cases noone really seems to care about these (aside from dbas), and they don’t get fixed.

Now, with this new patch, the problem is gone.

By default idle_in_transaction_session_timeout is set to 0, which means no timeout – transaction started will just continue forever.

But if I’ll change it to something else, like 15 seconds:

$ set idle_in_transaction_session_timeout = '15s';

Then start transaction, wait for 15 seconds (it’s 15 seconds of idle in transaction, not “process some queries" in transaction), and then will try to run a query:

(depesz@[local]:5960) 20:15:16 [depesz]  $ begin; BEGIN   (depesz@[local]:5960) 20:15:18 [depesz]  *$    (depesz@[local]:5960) 20:15:43 [depesz]  *$ select 1; FATAL:  terminating connection due to idle-in-transaction timeout server closed the connection unexpectedly         This probably means the server terminated abnormally         before or while processing the request. The connection to the server was lost. Attempting reset: Succeeded.

In logs, I can see:

1264 2016-03-21 20:15:33.537 CET depesz@depesz 7649 [local] FATAL:  terminating connection due to idle-in-transaction timeout 1265 2016-03-21 20:15:33.537 CET depesz@depesz 7649 [local] LOG:  disconnection: session time: 0:00:20.308 user=depesz database=depesz host=[local]

Nice. Something I was waiting for for a very long time. Thanks a lot

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Hubert 'depesz' Lubaczewski: Waiting for 9.6 – Add idle_in_transaction_session_timeout.

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
分享按钮