Answer the question
In order to leave comments, you need to log in
How to find the cause of "Exception: idle transaction timeout" in a Flask+psycopg2+postgresql+pgbouncer application?
There was such a problem. Once a month, the web application stopped with a 502 error. The reason was that postgresql stopped processing requests because the limit on the number of connections was exceeded. The list of processes showed a bunch of open pending connections that were being blocked by some request. Moreover, the request was quite ordinary, which was usually performed instantly. The reason that led to such a blocking was not enough to find out the mind. But there were several "idle in transaction" processes, and after killing one of them, everything was restored.
Postgresql 9.5 does not yet have an option to set a timeout for hanging transactions. Therefore, it was decided to install Pgbouncer.
As a result, there is postgresql, in front of it is pgbouncer in pool_mode=transaction.
For a couple of weeks everything worked great. But during the last two days, suddenly, for no apparent reason, a problem arose. The web application returns 500 to the user, the user is surprised, tries again, everything works fine again. A few minutes later, in another place in the application, the situation repeats itself. The user is nervous.
In the application log (Python, Flask, psycopg2):
Exception on /any-url-of-the-application [POST]
...
...
Exception: idle transaction timeout
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
idle_transaction_timeout = 600
Answer the question
In order to leave comments, you need to log in
and after killing one of them, everything was restored.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question